Skip to content

Commit

Permalink
added tests
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 87817c8 commit 168a011
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
56 changes: 56 additions & 0 deletions cmd/oras/root/manifest/index/create_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
Copyright The ORAS Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package index

import (
"reflect"
"testing"
)

func Test_parseAnnotations(t *testing.T) {
tests := []struct {
name string
input []string
annotations map[string]string
wantErr bool
wantAnnotations map[string]string
}{
{
name: "valid input",
input: []string{"a=b", "c=d", "e=f"},
annotations: make(map[string]string),
wantErr: false,
wantAnnotations: map[string]string{"a": "b", "c": "d", "e": "f"},
},
{
name: "invalid input",
input: []string{"c:d", "e=f"},
annotations: make(map[string]string),
wantErr: true,
wantAnnotations: map[string]string{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := parseAnnotations(tt.input, tt.annotations); (err != nil) != tt.wantErr {
t.Errorf("parseAnnotations() error = %v, wantErr %v", err, tt.wantErr)
}
if !reflect.DeepEqual(tt.annotations, tt.wantAnnotations) {
t.Errorf("parseAnnotations() annotations = %v, want %v", tt.annotations, tt.wantAnnotations)
}
})
}
}
8 changes: 8 additions & 0 deletions test/e2e/suite/command/manifest_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ var _ = Describe("1.1 registry users:", func() {
"does-not-exist").ExpectFailure().
MatchErrKeyWords("Error", "could not find", "does-not-exist").Exec()
})

It("should fail if given annotation input of wrong format", func() {
testRepo := indexTestRepo("create", "bad-annotations")
CopyZOTRepo(ImageRepo, testRepo)
ORAS("manifest", "index", "create", RegistryRef(ZOTHost, testRepo, ""),
string(multi_arch.LinuxAMD64.Digest), "-a", "foo:bar").ExpectFailure().
MatchErrKeyWords("Error", "annotation value doesn't match the required format").Exec()
})
})

When("running `manifest index update`", func() {
Expand Down

0 comments on commit 168a011

Please sign in to comment.