package repository_test import ( "fmt" "testing" "git.badhouseplants.net/allanger/giops/internal/config/repository" "github.com/stretchr/testify/assert" ) func TestValidateURLHttps(t *testing.T) { repo := &repository.Repository{ Name: "test", URL: "https://test.test", } err := repo.ValidateURL() assert.NoError(t, err, fmt.Sprintf("unexpected err occured: %s", err)) } func TestValidateURLOci(t *testing.T) { repo := &repository.Repository{ Name: "test", URL: "oci://test.test", } err := repo.ValidateURL() assert.NoError(t, err, fmt.Sprintf("unexpected err occured: %s", err)) } func TestValidateURLInvalid(t *testing.T) { repo := &repository.Repository{ Name: "test", URL: "invalid://test.test", } err := repo.ValidateURL() assert.ErrorContains(t, err, "it's not a valid repo URL: invalid://test.test", fmt.Sprintf("got unexpected err: %s", err), ) } func TestValidateURLNonURL(t *testing.T) { repo := &repository.Repository{ Name: "test", URL: "test", } err := repo.ValidateURL() assert.ErrorContains(t, err, "it's not a valid repo URL: test", fmt.Sprintf("got unexpected err: %s", err), ) } func TestKindFromUrlDefaultHttps(t *testing.T) { repo := &repository.Repository{ Name: "test", URL: "https://test.test", } if err := repo.KindFromUrl(); err != nil { t.Error(err) } assert.Equal(t, repo.Kind, repository.HELM_REPO_DEFAULT, fmt.Sprintf("got unexpected repo type: %s", repo.Kind), ) } func TestKindFromUrlDefaultHttp(t *testing.T) { repo := &repository.Repository{ Name: "test", URL: "http://test.test", } if err := repo.KindFromUrl(); err != nil { t.Error(err) } assert.Equal(t, repo.Kind, repository.HELM_REPO_DEFAULT, fmt.Sprintf("got unexpected repo type: %s", repo.Kind), ) } func TestKindFromUrlDefaultOci(t *testing.T) { repo := &repository.Repository{ Name: "test", URL: "oci://test.test", } if err := repo.KindFromUrl(); err != nil { t.Error(err) } assert.Equal(t, repo.Kind, repository.HELM_REPO_OCI, fmt.Sprintf("got unexpected repo type: %s", repo.Kind), ) } func TestKindFromUrlDefaultInvalid(t *testing.T) { repo := &repository.Repository{ Name: "test", URL: "invalid:url", } err := repo.KindFromUrl() assert.ErrorContains(t, err, "unknown repo kind: invalid", fmt.Sprintf("got unexpected err: %s", err)) }