Skip to content

Commit

Permalink
add no flag test case
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
  • Loading branch information
Xiaoxuan Wang committed Aug 13, 2024
1 parent c75e088 commit 60a2dfa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cmd/oras/root/manifest/index/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ Example - add one manifest from an index:
}

func updateIndex(cmd *cobra.Command, opts updateOptions) error {
// if --add is not used, then there's nothing to update
if !cmd.Flags().Changed("add") {
opts.Println("--add is not used. There's nothing to update.")
return nil
}
ctx, logger := command.GetLogger(cmd, &opts.Common)
target, err := opts.NewTarget(opts.Common, logger)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion test/e2e/suite/command/manifest_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ var _ = Describe("1.1 registry users:", func() {
ORAS("manifest", "fetch", RegistryRef(ZOTHost, ImageRepo, "update-add")).
MatchKeyWords("amd64", "arm64", "v7").Exec()
})
It("should update by specifying index digest", func() {
It("should update by specifying the index digest", func() {
// create an index for testing purpose
ORAS("manifest", "index", "create", RegistryRef(ZOTHost, ImageRepo, ""),
string(multi_arch.LinuxAMD64.Digest), string(multi_arch.LinuxARM64.Digest)).Exec()
Expand All @@ -131,6 +131,10 @@ var _ = Describe("1.1 registry users:", func() {
ORAS("manifest", "fetch", RegistryRef(ZOTHost, ImageRepo, "sha256:84887718c9e61daa0f1996aad3ae2eb10db15dcbdab394e4b2dfee7967c55f2c")).
MatchKeyWords("amd64", "arm64", "v7").Exec()
})
It("should tell user nothing to update if no update flags are used", func() {
ORAS("manifest", "index", "update", RegistryRef(ZOTHost, ImageRepo, "nothing-to-update")).
MatchKeyWords("nothing to update").Exec()
})
It("should fail if empty reference is given", func() {
ORAS("manifest", "index", "update", RegistryRef(ZOTHost, ImageRepo, ""),
"--add", string(multi_arch.LinuxARMV7.Digest)).ExpectFailure().
Expand Down

0 comments on commit 60a2dfa

Please sign in to comment.