diff --git a/cmd/helm/repo_add_test.go b/cmd/helm/repo_add_test.go index 3c768fcd0..7eb8e7b78 100644 --- a/cmd/helm/repo_add_test.go +++ b/cmd/helm/repo_add_test.go @@ -17,6 +17,7 @@ limitations under the License. package main import ( + "bytes" "fmt" "io/ioutil" "net/http" @@ -28,10 +29,30 @@ import ( "k8s.io/helm/pkg/repo" ) -var ( - testName = "test-name" - testURL = "test-url" -) +var testName string = "test-name" + +func TestRepoAddCmd(t *testing.T) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/plain") + fmt.Fprintln(w, "OK") + })) + + tests := []releaseCase{ + { + name: "add a repository", + args: []string{testName, ts.URL}, + expected: testName + " has been added to your repositories", + }, + } + + for _, tt := range tests { + buf := bytes.NewBuffer(nil) + c := newRepoAddCmd(buf) + if err := c.RunE(c, tt.args); err != nil { + t.Errorf("%q: expected '%q', got '%q'", tt.name, tt.expected, err) + } + } +} func TestRepoAdd(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { diff --git a/cmd/helm/repo_index_test.go b/cmd/helm/repo_index_test.go new file mode 100644 index 000000000..fbf22daca --- /dev/null +++ b/cmd/helm/repo_index_test.go @@ -0,0 +1,51 @@ +/* +Copyright 2016 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "bytes" + "io/ioutil" + "os" + "path/filepath" + "testing" + + "k8s.io/helm/pkg/repo" +) + +func TestRepoIndexCmd(t *testing.T) { + + dir, _ := ioutil.TempDir("", "charts") + defer os.RemoveAll(dir) + os.Link("testdata/testcharts/compressedChart-0.1.0.tgz", filepath.Join(dir, "compressedChart-0.1.0.tgz")) + + buf := bytes.NewBuffer(nil) + c := newRepoIndexCmd(buf) + + if err := c.RunE(c, []string{dir}); err != nil { + t.Errorf("%q", err) + } + + index, err := repo.LoadIndexFile(filepath.Join(dir, "index.yaml")) + if err != nil { + t.Fatal(err) + } + + if len(index.Entries) != 1 { + t.Errorf("expected 1 entires, got %v", len(index.Entries)) + } + +} diff --git a/cmd/helm/repo_remove_test.go b/cmd/helm/repo_remove_test.go index 007c02f0a..ea4fa6b55 100644 --- a/cmd/helm/repo_remove_test.go +++ b/cmd/helm/repo_remove_test.go @@ -24,6 +24,7 @@ import ( ) func TestRepoRemove(t *testing.T) { + testURL := "https://test-url.com" home := createTmpHome() helmHome = home if err := ensureHome(); err != nil {