Merge pull request #1275 from technosophos/fix/srv-in-tmp

fix(helm): fix tests so that they do not write data into testdata
reviewable/pr1278/r1
Matt Butcher 8 years ago committed by GitHub
commit 96cdbbe6b1

@ -29,19 +29,21 @@ import (
var testName = "test-name"
func TestRepoAddCmd(t *testing.T) {
srv := repotest.NewServer("testdata/testserver")
defer srv.Stop()
thome, err := tempHelmHome(t)
srv, thome, err := repotest.NewTempServer("testdata/testserver/*.*")
if err != nil {
t.Fatal(err)
}
oldhome := homePath()
helmHome = thome
defer func() {
srv.Stop()
helmHome = oldhome
os.Remove(thome)
}()
if err := ensureTestHome(helmpath.Home(thome), t); err != nil {
t.Fatal(err)
}
tests := []releaseCase{
{
@ -61,15 +63,22 @@ func TestRepoAddCmd(t *testing.T) {
}
func TestRepoAdd(t *testing.T) {
ts := repotest.NewServer("testdata/testserver")
defer ts.Stop()
thome, err := tempHelmHome(t)
ts, thome, err := repotest.NewTempServer("testdata/testserver/*.*")
if err != nil {
t.Fatal(err)
}
defer os.Remove(thome)
oldhome := homePath()
helmHome = thome
hh := helmpath.Home(thome)
defer func() {
ts.Stop()
helmHome = oldhome
os.Remove(thome)
}()
if err := ensureTestHome(hh, t); err != nil {
t.Fatal(err)
}
if err := addRepository(testName, ts.URL(), hh); err != nil {
t.Error(err)

@ -62,19 +62,21 @@ func TestUpdateCmd(t *testing.T) {
}
func TestUpdateCharts(t *testing.T) {
srv := repotest.NewServer("testdata/testserver")
defer srv.Stop()
thome, err := tempHelmHome(t)
srv, thome, err := repotest.NewTempServer("testdata/testserver/*.*")
if err != nil {
t.Fatal(err)
}
oldhome := homePath()
helmHome = thome
defer func() {
srv.Stop()
helmHome = oldhome
os.Remove(thome)
}()
if err := ensureTestHome(helmpath.Home(thome), t); err != nil {
t.Fatal(err)
}
buf := bytes.NewBuffer(nil)
repos := []*repo.Entry{

@ -27,6 +27,30 @@ import (
"k8s.io/helm/pkg/repo"
)
// NewTempServer creates a server inside of a temp dir.
//
// If the passed in string is not "", it will be treated as a shell glob, and files
// will be copied from that path to the server's docroot.
//
// The caller is responsible for destroying the temp directory as well as stopping
// the server.
func NewTempServer(glob string) (*Server, string, error) {
tdir, err := ioutil.TempDir("", "helm-repotest-")
if err != nil {
return nil, tdir, err
}
srv := NewServer(tdir)
if glob != "" {
if _, err := srv.CopyCharts(glob); err != nil {
srv.Stop()
return srv, tdir, err
}
}
return srv, tdir, nil
}
// NewServer creates a repository server for testing.
//
// docroot should be a temp dir managed by the caller.

@ -102,3 +102,26 @@ func TestServer(t *testing.T) {
t.Errorf("Expected 404, got %d", res.StatusCode)
}
}
func TestNewTempServer(t *testing.T) {
srv, tdir, err := NewTempServer("testdata/examplechart-0.1.0.tgz")
if err != nil {
t.Fatal(err)
}
defer func() {
srv.Stop()
os.RemoveAll(tdir)
}()
if _, err := os.Stat(tdir); err != nil {
t.Fatal(err)
}
res, err := http.Head(srv.URL() + "/examplechart-0.1.0.tgz")
if err != nil {
t.Error(err)
}
if res.StatusCode != 200 {
t.Errorf("Expected 200, got %d", res.StatusCode)
}
}

Loading…
Cancel
Save