Skip to content

Commit

Permalink
increase test coverage
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 Oct 29, 2024
1 parent 3a9bb0a commit 394f907
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
28 changes: 28 additions & 0 deletions cmd/oras/internal/display/content/manifest_index_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
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 content

import (
"os"
"testing"
)

func Test_manifestIndexCreate_OnContentCreated(t *testing.T) {
testHandler := NewManifestIndexCreateHandler(os.Stdout, false, "invalid/path")
if err := testHandler.OnContentCreated([]byte("test content")); err == nil {
t.Errorf("manifestIndexCreate.OnContentCreated() error = %v, wantErr non-nil error", err)
}
}
70 changes: 70 additions & 0 deletions cmd/oras/internal/display/status/text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,73 @@ func TestTextPushHandler_PreCopy(t *testing.T) {
}
validatePrinted(t, "Uploading 0b442c23c1dd oci-image")
}

func TestTextManifestIndexUpdateHandler_OnManifestAdded(t *testing.T) {
tests := []struct {
name string
printer *output.Printer
ref string
desc ocispec.Descriptor
wantErr bool
}{
{
name: "ref is a digest",
printer: output.NewPrinter(os.Stdout, os.Stderr, false),
ref: "sha256:fd6ed2f36b5465244d5dc86cb4e7df0ab8a9d24adc57825099f522fe009a22bb",
desc: ocispec.Descriptor{MediaType: "test", Digest: "sha256:fd6ed2f36b5465244d5dc86cb4e7df0ab8a9d24adc57825099f522fe009a22bb", Size: 25},
wantErr: false,
},
{
name: "ref is not a digest",
printer: output.NewPrinter(os.Stdout, os.Stderr, false),
ref: "v1",
desc: ocispec.Descriptor{MediaType: "test", Digest: "sha256:fd6ed2f36b5465244d5dc86cb4e7df0ab8a9d24adc57825099f522fe009a22bb", Size: 25},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
miuh := &TextManifestIndexUpdateHandler{
printer: tt.printer,
}
if err := miuh.OnManifestAdded(tt.ref, tt.desc); (err != nil) != tt.wantErr {
t.Errorf("TextManifestIndexUpdateHandler.OnManifestAdded() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}

func TestTextManifestIndexUpdateHandler_OnIndexMerged(t *testing.T) {
tests := []struct {
name string
printer *output.Printer
ref string
desc ocispec.Descriptor
wantErr bool
}{
{
name: "ref is a digest",
printer: output.NewPrinter(os.Stdout, os.Stderr, false),
ref: "sha256:fd6ed2f36b5465244d5dc86cb4e7df0ab8a9d24adc57825099f522fe009a22bb",
desc: ocispec.Descriptor{MediaType: "test", Digest: "sha256:fd6ed2f36b5465244d5dc86cb4e7df0ab8a9d24adc57825099f522fe009a22bb", Size: 25},
wantErr: false,
},
{
name: "ref is not a digest",
printer: output.NewPrinter(os.Stdout, os.Stderr, false),
ref: "v1",
desc: ocispec.Descriptor{MediaType: "test", Digest: "sha256:fd6ed2f36b5465244d5dc86cb4e7df0ab8a9d24adc57825099f522fe009a22bb", Size: 25},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
miuh := &TextManifestIndexUpdateHandler{
printer: tt.printer,
}
if err := miuh.OnIndexMerged(tt.ref, tt.desc); (err != nil) != tt.wantErr {
t.Errorf("TextManifestIndexUpdateHandler.OnIndexMerged() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}

0 comments on commit 394f907

Please sign in to comment.