diff --git a/cmd/oras/internal/display/metadata/text/attach_test.go b/cmd/oras/internal/display/metadata/text/attach_test.go new file mode 100644 index 000000000..066a47cad --- /dev/null +++ b/cmd/oras/internal/display/metadata/text/attach_test.go @@ -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) + }) + } +} diff --git a/test/e2e/suite/command/attach.go b/test/e2e/suite/command/attach.go index 509615919..ee19f0ba1 100644 --- a/test/e2e/suite/command/attach.go +++ b/test/e2e/suite/command/attach.go @@ -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