1
0
mirror of https://github.com/regclient/regclient.git synced 2025-04-18 22:44:00 +03:00
regclient/cmd/regctl/manifest_test.go
Brandon Mitchell eea06e2a5c
Refactoring the type package
I feel like I need to explain, this is all to move the descriptor package.
The platform package could not use the predefined errors in types because of a circular dependency from descriptor.
The most appropriate way to reorg this is to move descriptor out of the type package since it was more complex than a self contained type.
When doing that, type aliases were needed to avoid breaking changes to existing users.
Those aliases themselves caused circular dependency loops because of the media types and errors, so those were also pulled out to separate packages.
All of the old values were aliased and deprecated, and to fix the linter, those deprecations were fixed by updating the imports... everywhere.

Signed-off-by: Brandon Mitchell <git@bmitch.net>
2024-03-04 15:43:18 -05:00

74 lines
1.9 KiB
Go

package main
import (
"errors"
"fmt"
"strings"
"testing"
"github.com/regclient/regclient/types/errs"
)
func TestManifestHead(t *testing.T) {
tt := []struct {
name string
args []string
expectErr error
expectOut string
outContains bool
}{
{
name: "Missing arg",
args: []string{"manifest", "head"},
expectErr: fmt.Errorf("accepts 1 arg(s), received 0"),
},
{
name: "Invalid ref",
args: []string{"manifest", "head", "invalid*ref"},
expectErr: errs.ErrInvalidReference,
},
{
name: "Missing manifest",
args: []string{"manifest", "head", "ocidir://../../testdata/testrepo:missing"},
expectErr: errs.ErrNotFound,
},
{
name: "Digest",
args: []string{"manifest", "head", "ocidir://../../testdata/testrepo:v1"},
expectOut: "sha256:",
outContains: true,
},
{
name: "Platform amd64",
args: []string{"manifest", "head", "ocidir://../../testdata/testrepo:v1", "--platform", "linux/amd64"},
expectOut: "sha256:",
outContains: true,
},
{
name: "Platform unknown",
args: []string{"manifest", "head", "ocidir://../../testdata/testrepo:v1", "--platform", "linux/unknown"},
expectErr: ErrNotFound,
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
out, err := cobraTest(t, nil, tc.args...)
if tc.expectErr != nil {
if err == nil {
t.Errorf("did not receive expected error: %v", tc.expectErr)
} else if !errors.Is(err, tc.expectErr) && err.Error() != tc.expectErr.Error() {
t.Errorf("unexpected error, received %v, expected %v", err, tc.expectErr)
}
return
}
if err != nil {
t.Fatalf("returned unexpected error: %v", err)
}
if (!tc.outContains && out != tc.expectOut) || (tc.outContains && !strings.Contains(out, tc.expectOut)) {
t.Errorf("unexpected output, expected %s, received %s", tc.expectOut, out)
}
})
}
}