use filepath join in unitests

This commit is contained in:
David Wertenteil
2022-07-05 11:44:07 +03:00
parent 034dbca30c
commit fc78d9143b
3 changed files with 16 additions and 17 deletions

View File

@@ -12,12 +12,12 @@ import (
func onlineBoutiquePath() string {
o, _ := os.Getwd()
return filepath.Join(filepath.Dir(o), "../examples/online-boutique/*")
return filepath.Join(filepath.Dir(o), "..", "examples", "online-boutique")
}
func helmChartPath() string {
o, _ := os.Getwd()
return filepath.Join(filepath.Dir(o), "../examples/helm_chart/*")
return filepath.Join(filepath.Dir(o), "..", "examples", "helm_chart")
}
func TestListFiles(t *testing.T) {
@@ -79,10 +79,10 @@ func TestLoadFiles(t *testing.T) {
}
func TestListDirs(t *testing.T) {
dirs, _ := listDirs(strings.Replace(onlineBoutiquePath(), "*", "adservice.yaml", 1))
dirs, _ := listDirs(filepath.Join(onlineBoutiquePath(), "adservice.yaml"))
assert.Equal(t, 0, len(dirs))
expectedDirs := []string{"examples/helm_chart", "examples/helm_chart/templates"}
expectedDirs := []string{filepath.Join("examples", "helm_chart"), filepath.Join("examples", "helm_chart", "templates")}
dirs, _ = listDirs(helmChartPath())
assert.Equal(t, len(expectedDirs), len(dirs))
for i := range expectedDirs {
@@ -91,7 +91,7 @@ func TestListDirs(t *testing.T) {
}
func TestLoadFile(t *testing.T) {
files, _ := listFiles(strings.Replace(onlineBoutiquePath(), "*", "adservice.yaml", 1))
files, _ := listFiles(filepath.Join(onlineBoutiquePath(), "adservice.yaml"))
assert.Equal(t, 1, len(files))
_, err := loadFile(files[0])

View File

@@ -27,19 +27,19 @@ func TestHelmChartTestSuite(t *testing.T) {
func (s *HelmChartTestSuite) SetupSuite() {
o, _ := os.Getwd()
s.helmChartPath = filepath.Join(filepath.Dir(o), "../examples/helm_chart")
s.helmChartPath = filepath.Join(filepath.Dir(o), "..", "examples", "helm_chart")
s.expectedFiles = []string{
filepath.Join(s.helmChartPath, "templates/clusterrolebinding.yaml"),
filepath.Join(s.helmChartPath, "templates/clusterrole.yaml"),
filepath.Join(s.helmChartPath, "templates/serviceaccount.yaml"),
filepath.Join(s.helmChartPath, "templates/rolebinding.yaml"),
filepath.Join(s.helmChartPath, "templates/role.yaml"),
filepath.Join(s.helmChartPath, "templates/cronjob.yaml"),
filepath.Join(s.helmChartPath, "templates", "clusterrolebinding.yaml"),
filepath.Join(s.helmChartPath, "templates", "clusterrole.yaml"),
filepath.Join(s.helmChartPath, "templates", "serviceaccount.yaml"),
filepath.Join(s.helmChartPath, "templates", "rolebinding.yaml"),
filepath.Join(s.helmChartPath, "templates", "role.yaml"),
filepath.Join(s.helmChartPath, "templates", "cronjob.yaml"),
}
var obj interface{}
file, _ := ioutil.ReadFile("testdata/helm_expected_default_values.json")
file, _ := ioutil.ReadFile(filepath.Join("testdata", "helm_expected_default_values.json"))
_ = json.Unmarshal([]byte(file), &obj)
s.expectedDefaultValues = obj.(map[string]interface{})
}

View File

@@ -5,7 +5,6 @@ import (
"fmt"
"io"
"os"
"path"
"path/filepath"
"strings"
"testing"
@@ -62,9 +61,9 @@ func unzipFile(zipPath, destinationFolder string) (*zip.ReadCloser, error) {
}
func (s *LocalGitRepositoryTestSuite) SetupSuite() {
zippedFixturePath := path.Join(".", "testdata", "localrepo.git")
destinationPath := path.Join(".", "testdata", "temp")
gitRepositoryPath := path.Join(destinationPath, "localrepo")
zippedFixturePath := filepath.Join(".", "testdata", "localrepo.git")
destinationPath := filepath.Join(".", "testdata", "temp")
gitRepositoryPath := filepath.Join(destinationPath, "localrepo")
os.RemoveAll(destinationPath)
archive, err := unzipFile(zippedFixturePath, destinationPath)