Skip to content

Commit

Permalink
refinement
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 Sep 18, 2024
1 parent 9ea1f26 commit 70fc421
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/oras/root/manifest/index/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ func parseAnnotations(input []string) (map[string]string, error) {
if !success {
return nil, fmt.Errorf("annotation value doesn't match the required format of \"key=value\"")
}
if _, ok := annotations[key]; ok {
return nil, fmt.Errorf("duplicate annotation key: %v", key)
}
annotations[key] = val
}
return annotations, nil
Expand Down
6 changes: 6 additions & 0 deletions cmd/oras/root/manifest/index/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ func Test_parseAnnotations(t *testing.T) {
wantErr: true,
wantAnnotations: nil,
},
{
name: "duplicate key",
input: []string{"a=b", "c=d", "a=e"},
wantErr: true,
wantAnnotations: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 70fc421

Please sign in to comment.