Files
troubleshoot/pkg/oci/pull_test.go
Evans Mungai 15a4802cd2 feat: Add dry run flag to print support bundle specs to std out (#1337)
* Add dry-run flag

* No traces on dry run

* More refactoring

* More updates to support bundle binary

* More refactoring changes

* Different approach of loading specs from URIs

* Self review

* More changes after review and testing

* fix how we parse oci image uri

* Remove unnecessary comment

* Add missing file

* Fix failing tests

* Better error check for no collectors

* Add default collectors when parsing support bundle specs

* Add missed test fixture

* Download specs with correct headers

* Fix typo
2023-10-10 18:43:32 +01:00

67 lines
1.7 KiB
Go

package oci
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_parseURI(t *testing.T) {
tests := []struct {
name string
uri string
imageName string
wantUri string
wantErr bool
}{
{
name: "happy path",
uri: "oci://registry.replicated.com/app-slug/unstable",
imageName: "replicated-preflight",
wantUri: "registry.replicated.com/app-slug/unstable/replicated-preflight:latest",
},
{
name: "no path in uri",
uri: "oci://registry.replicated.com",
imageName: "replicated-preflight",
wantUri: "registry.replicated.com/replicated-preflight:latest",
},
{
name: "hostname with port",
uri: "oci://localhost:5000/some/path",
imageName: "replicated-preflight",
wantUri: "localhost:5000/some/path/replicated-preflight:latest",
},
{
name: "uri with tags",
uri: "oci://localhost:5000/some/path:tag",
imageName: "replicated-preflight",
wantUri: "localhost:5000/some/path/replicated-preflight:tag",
},
{
name: "empty uri",
wantErr: true,
},
{
name: "invalid uri",
uri: "registry.replicated.com/app-slug/unstable",
imageName: "replicated-preflight",
wantErr: true,
},
{
name: "invalid uri",
uri: "https://registry.replicated.com/app-slug/unstable",
imageName: "replicated-preflight",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := parseURI(tt.uri, tt.imageName)
require.Equalf(t, tt.wantErr, err != nil, "parseURI() error = %v, wantErr %v", err, tt.wantErr)
assert.Equalf(t, tt.wantUri, got, "parseURI() = %v, want %v", got, tt.wantUri)
})
}
}