Commit 4df486e3 authored by Michelle Noorali's avatar Michelle Noorali

feat(repo): add GetRepoURLByName test

* + fix old repo tests for Name addition
parent 6e96c333
......@@ -33,6 +33,7 @@ var (
TestChartFile = "testdata/frobnitz/Chart.yaml"
TestShouldFindRegex = regexp.MustCompile(TestArchiveName)
TestShouldNotFindRegex = regexp.MustCompile("foobar")
TestName = "bucket-name"
)
func TestValidGSURL(t *testing.T) {
......@@ -51,7 +52,7 @@ func TestValidGSURL(t *testing.T) {
func TestInvalidGSURL(t *testing.T) {
var invalidGSURL = "https://valid.url/wrong/scheme"
_, err := NewGCSRepo(invalidGSURL, TestRepoCredentialName, nil)
_, err := NewGCSRepo(invalidGSURL, TestRepoCredentialName, TestName, nil)
if err == nil {
t.Fatalf("expected error did not occur for invalid GS URL")
}
......@@ -126,7 +127,7 @@ func TestGetChartWithInvalidName(t *testing.T) {
}
func getTestRepo(t *testing.T) IStorageRepo {
tr, err := NewGCSRepo(TestRepoURL, TestRepoCredentialName, nil)
tr, err := NewGCSRepo(TestRepoURL, TestRepoCredentialName, TestName, nil)
if err != nil {
t.Fatal(err)
}
......
......@@ -32,7 +32,11 @@ func TestService(t *testing.T) {
t.Fatalf("unexpected repo count; want: %d, have %d.", 1, len(repos))
}
tr, err := rs.GetRepoByURL(repos[0])
u := ""
for _, url := range repos {
u = url
}
tr, err := rs.GetRepoByURL(u)
if err != nil {
t.Fatal(err)
}
......@@ -71,7 +75,7 @@ func TestService(t *testing.T) {
func TestCreateRepoWithDuplicateURL(t *testing.T) {
rs := NewInmemRepoService()
r, err := newRepo(GCSPublicRepoURL, "", GCSRepoFormat, GCSRepoType)
r, err := newRepo(GCSPublicRepoURL, "", TestName, GCSRepoFormat, GCSRepoType)
if err != nil {
t.Fatalf("cannot create test repo: %s", err)
}
......@@ -90,6 +94,25 @@ func TestGetRepoWithInvalidURL(t *testing.T) {
}
}
func TestGetRepoURLByName(t *testing.T) {
rs := NewInmemRepoService()
testURL := "gcs://helm-test-charts"
r, err := newRepo(testURL, "", TestName, GCSRepoFormat, GCSRepoType)
err = rs.CreateRepo(r)
if err != nil {
t.Fatalf("Error creating repo: %s", err)
}
expectedURL := testURL
actualURL, err := rs.GetRepoURLByName(TestName)
if err != nil {
t.Fatalf("%v", err)
}
if expectedURL != actualURL {
t.Fatalf("Incorrect resulting URL. Expected %s. Got %s", expectedURL, actualURL)
}
}
func TestGetRepoWithInvalidChartURL(t *testing.T) {
invalidURL := "https://not.a.valid/url"
rs := NewInmemRepoService()
......
......@@ -29,7 +29,7 @@ var (
)
func TestValidRepoURL(t *testing.T) {
tr, err := NewRepo(TestRepoURL, TestRepoCredentialName, string(TestRepoFormat), string(TestRepoType))
tr, err := NewRepo(TestRepoURL, TestRepoCredentialName, TestRepoBucket, string(TestRepoFormat), string(TestRepoType))
if err != nil {
t.Fatal(err)
}
......@@ -40,14 +40,14 @@ func TestValidRepoURL(t *testing.T) {
}
func TestInvalidRepoURL(t *testing.T) {
_, err := newRepo("%:invalid&url:%", TestRepoCredentialName, TestRepoFormat, TestRepoType)
_, err := newRepo("%:invalid&url:%", TestRepoCredentialName, TestRepoBucket, TestRepoFormat, TestRepoType)
if err == nil {
t.Fatalf("expected error did not occur for invalid URL")
}
}
func TestDefaultCredentialName(t *testing.T) {
tr, err := newRepo(TestRepoURL, "", TestRepoFormat, TestRepoType)
tr, err := newRepo(TestRepoURL, "", TestRepoBucket, TestRepoFormat, TestRepoType)
if err != nil {
t.Fatalf("cannot create repo using default credential name")
}
......@@ -60,7 +60,7 @@ func TestDefaultCredentialName(t *testing.T) {
}
func TestInvalidRepoFormat(t *testing.T) {
_, err := newRepo(TestRepoURL, TestRepoCredentialName, "", TestRepoType)
_, err := newRepo(TestRepoURL, TestRepoCredentialName, TestRepoBucket, "", TestRepoType)
if err == nil {
t.Fatalf("expected error did not occur for invalid format")
}
......
......@@ -116,7 +116,7 @@ func TestGetChartByReferenceWithValidReferences(t *testing.T) {
func getTestRepoProvider(t *testing.T) IRepoProvider {
rp := newRepoProvider(nil, nil, nil)
rs := rp.GetRepoService()
tr, err := newRepo(TestRepoURL, TestRepoCredentialName, TestRepoFormat, TestRepoType)
tr, err := newRepo(TestRepoURL, TestRepoCredentialName, TestName, TestRepoFormat, TestRepoType)
if err != nil {
t.Fatalf("cannot create test repository: %s", err)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment