Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for adding repository #175

Merged
merged 1 commit into from
Jan 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions pkg/dashboard/objects/repos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"helm.sh/helm/v3/pkg/repo"
)

var filePath = "./testdata/repositories.yaml"

func initRepository(t *testing.T, filePath string) *Repositories {
t.Helper()

Expand All @@ -30,8 +32,6 @@ func initRepository(t *testing.T, filePath string) *Repositories {

func TestLoadRepo(t *testing.T) {

filePath := "./testdata/repositories.yaml"

res, err := repo.LoadFile(filePath)
if err != nil {
t.Fatal(err)
Expand All @@ -48,8 +48,6 @@ func TestLoadRepo(t *testing.T) {
}

func TestList(t *testing.T) {
filePath := "./testdata/repositories.yaml"

res, err := repo.LoadFile(filePath)
if err != nil {
t.Fatal(err)
Expand All @@ -65,3 +63,32 @@ func TestList(t *testing.T) {

assert.Equal(t, len(repos), len(res.Repositories))
}

func TestAdd(t *testing.T) {
testRepoName := "TEST"
testRepoUrl := "https://helm.github.io/examples"

res, err := repo.LoadFile(filePath)
if err != nil {
t.Fatal(err)
}

// Delete the repository if already exist
res.Remove(testRepoName)

testRepository := initRepository(t, filePath)

err = testRepository.Add(testRepoName, testRepoUrl)

if err != nil {
t.Fatal(err, "Failed to add repo")
}

// Reload the file
res, err = repo.LoadFile(filePath)
if err != nil {
t.Fatal(err)
}

assert.Equal(t, res.Has(testRepoName), true)
}
33 changes: 27 additions & 6 deletions pkg/dashboard/objects/testdata/repositories.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
apiVersion: ""
generated: "0001-01-01T00:00:00Z"
repositories:
- name: charts
url: "https://charts.helm.sh/stable"
- name: firstexample
url: "http://firstexample.com"
- name: secondexample
url: "http://secondexample.com"
- caFile: ""
certFile: ""
insecure_skip_tls_verify: false
keyFile: ""
name: charts
pass_credentials_all: false
password: ""
url: https://charts.helm.sh/stable
username: ""
- caFile: ""
certFile: ""
insecure_skip_tls_verify: false
keyFile: ""
name: firstexample
pass_credentials_all: false
password: ""
url: http://firstexample.com
username: ""
- caFile: ""
certFile: ""
insecure_skip_tls_verify: false
keyFile: ""
name: secondexample
pass_credentials_all: false
password: ""
url: http://secondexample.com
username: ""