Skip to content

Commit

Permalink
fix(helm): fix tests if tmp directory is on another block device
Browse files Browse the repository at this point in the history
Two non-exported helper functions were added to the repo index test
file. They first try to link the file, since this is optimal. If the
link fails a copy occurs.

Fixes #1472
  • Loading branch information
poopoothegorilla committed Oct 29, 2016
1 parent 1a397dd commit 057e4ef
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions cmd/helm/repo_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main

import (
"bytes"
"io"
"io/ioutil"
"os"
"path/filepath"
Expand All @@ -35,11 +36,11 @@ func TestRepoIndexCmd(t *testing.T) {
defer os.RemoveAll(dir)

comp := filepath.Join(dir, "compressedchart-0.1.0.tgz")
if err := os.Link("testdata/testcharts/compressedchart-0.1.0.tgz", comp); err != nil {
if err := linkOrCopy("testdata/testcharts/compressedchart-0.1.0.tgz", comp); err != nil {
t.Fatal(err)
}
comp2 := filepath.Join(dir, "compressedchart-0.2.0.tgz")
if err := os.Link("testdata/testcharts/compressedchart-0.2.0.tgz", comp2); err != nil {
if err := linkOrCopy("testdata/testcharts/compressedchart-0.2.0.tgz", comp2); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -81,10 +82,10 @@ func TestRepoIndexCmd(t *testing.T) {
t.Fatal(err)
}
// Add a new chart and a new version of an existing chart
if err := os.Link("testdata/testcharts/reqtest-0.1.0.tgz", filepath.Join(dir, "reqtest-0.1.0.tgz")); err != nil {
if err := linkOrCopy("testdata/testcharts/reqtest-0.1.0.tgz", filepath.Join(dir, "reqtest-0.1.0.tgz")); err != nil {
t.Fatal(err)
}
if err := os.Link("testdata/testcharts/compressedchart-0.3.0.tgz", filepath.Join(dir, "compressedchart-0.3.0.tgz")); err != nil {
if err := linkOrCopy("testdata/testcharts/compressedchart-0.3.0.tgz", filepath.Join(dir, "compressedchart-0.3.0.tgz")); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -112,3 +113,29 @@ func TestRepoIndexCmd(t *testing.T) {
t.Errorf("expected %q, got %q", expectedVersion, vs[0].Version)
}
}

func linkOrCopy(old, new string) error {
if err := os.Link(old, new); err != nil {
return copyFile(old, new)
}

return nil
}

func copyFile(dst, src string) error {
i, err := os.Open(dst)
if err != nil {
return err
}
defer i.Close()

o, err := os.Create(src)
if err != nil {
return err
}
defer o.Close()

_, err = io.Copy(o, i)

return err
}

0 comments on commit 057e4ef

Please sign in to comment.