Skip to content

Commit

Permalink
test(e2e): validate attach status output
Browse files Browse the repository at this point in the history
Signed-off-by: Billy Zha <[email protected]>
  • Loading branch information
qweeah committed Dec 11, 2024
1 parent 83a8be4 commit d9590f0
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 5 deletions.
54 changes: 54 additions & 0 deletions cmd/oras/internal/display/metadata/text/attach_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
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 text

import (
"testing"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras/cmd/oras/internal/option"
"oras.land/oras/cmd/oras/internal/output"
)

func TestAttachHandler_OnAttached(t *testing.T) {
type fields struct {
printer *output.Printer
subjectRefByDigest string
root ocispec.Descriptor
}
type args struct {
target *option.Target
root ocispec.Descriptor
subject ocispec.Descriptor
}
tests := []struct {
name string
fields fields
args args
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ah := &AttachHandler{
printer: tt.fields.printer,
subjectRefByDigest: tt.fields.subjectRefByDigest,
root: tt.fields.root,
}
ah.OnAttached(tt.args.target, tt.args.root, tt.args.subject)
})
}
}
9 changes: 4 additions & 5 deletions test/e2e/suite/command/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,17 @@ var _ = Describe("1.1 registry users:", func() {
subjectRef := RegistryRef(ZOTHost, testRepo, foobar.Tag)
ORAS("attach", "--artifact-type", "test/attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia)).
WithWorkDir(PrepareTempFiles()).
MatchKeyWords(fmt.Sprintf("Attached to [registry] %s", RegistryRef(ZOTHost, testRepo, foobar.Digest))).
MatchStatus([]match.StateKey{foobar.AttachFileStateKey}, false, 1).Exec()
})

It("should attach a file to an arch-specific subject", func() {
// prepare
testRepo := attachTestRepo("arch-specific")
// Below line will cause unexpected 500
// pending for https://github.com/project-zot/zot/pull/2351 to be released
// CopyZOTRepo(ImageRepo, testRepo)
CopyZOTRepo(ImageRepo, testRepo)
// test
subjectRef := RegistryRef(ZOTHost, testRepo, multi_arch.Tag)
ORAS("cp", RegistryRef(ZOTHost, ImageRepo, multi_arch.Tag), subjectRef).Exec()
artifactType := "test/attach"
// test
out := ORAS("attach", "--artifact-type", artifactType, subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--format", "go-template={{.digest}}", "--platform", "linux/amd64").
WithWorkDir(PrepareTempFiles()).Exec().Out.Contents()
// validate
Expand Down

0 comments on commit d9590f0

Please sign in to comment.