Merge pull request #1476 from poopoothegorilla/fix/testdata-bug

fix(helm): fix tests if tmp directory is on another block device
pull/1485/head
Matt Butcher 8 years ago committed by GitHub
commit 91005b8f78

@ -18,6 +18,7 @@ package main
import ( import (
"bytes" "bytes"
"io"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -35,11 +36,11 @@ func TestRepoIndexCmd(t *testing.T) {
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
comp := filepath.Join(dir, "compressedchart-0.1.0.tgz") 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) t.Fatal(err)
} }
comp2 := filepath.Join(dir, "compressedchart-0.2.0.tgz") 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) t.Fatal(err)
} }
@ -81,10 +82,10 @@ func TestRepoIndexCmd(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
// Add a new chart and a new version of an existing chart // 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) 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) t.Fatal(err)
} }
@ -112,3 +113,29 @@ func TestRepoIndexCmd(t *testing.T) {
t.Errorf("expected %q, got %q", expectedVersion, vs[0].Version) 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
}

Loading…
Cancel
Save