helm(repo): add repo add and index cmd test

pull/1204/head
Michelle Noorali 8 years ago
parent a86f304d37
commit ec4442373e

@ -17,6 +17,7 @@ limitations under the License.
package main package main
import ( import (
"bytes"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
@ -28,10 +29,30 @@ import (
"k8s.io/helm/pkg/repo" "k8s.io/helm/pkg/repo"
) )
var ( var testName string = "test-name"
testName = "test-name"
testURL = "test-url" 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) { func TestRepoAdd(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

@ -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))
}
}

@ -24,6 +24,7 @@ import (
) )
func TestRepoRemove(t *testing.T) { func TestRepoRemove(t *testing.T) {
testURL := "https://test-url.com"
home := createTmpHome() home := createTmpHome()
helmHome = home helmHome = home
if err := ensureHome(); err != nil { if err := ensureHome(); err != nil {

Loading…
Cancel
Save