Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions reposerver/repository/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,7 @@ func TestListApps(t *testing.T) {
"kustomization_yml": "Kustomize",
"my-chart": "Helm",
"my-chart-2": "Helm",
"values-files": "Helm",
}
assert.Equal(t, expectedApps, res.Apps)
}
Expand Down Expand Up @@ -1995,3 +1996,32 @@ func runGit(t *testing.T, workDir string, args ...string) string {
require.NoError(t, err, stringOut)
return stringOut
}

func Test_findHelmValueFilesInPath(t *testing.T) {
t.Run("does not exist", func(t *testing.T) {
files, err := findHelmValueFilesInPath("/obviously/does/not/exist")
assert.Error(t, err)
assert.Empty(t, files)
})
t.Run("values files", func(t *testing.T) {
files, err := findHelmValueFilesInPath("./testdata/values-files")
assert.NoError(t, err)
assert.Len(t, files, 4)
})
}

func Test_populateHelmAppDetails(t *testing.T) {
res := apiclient.RepoAppDetailsResponse{}
q := apiclient.RepoServerAppDetailsQuery{
Repo: &argoappv1.Repository{},
Source: &argoappv1.ApplicationSource{
Helm: &argoappv1.ApplicationSourceHelm{ValueFiles: []string{"exclude.yaml", "has-the-word-values.yaml"}},
},
}
appPath, err := filepath.Abs("./testdata/values-files/")
require.NoError(t, err)
err = populateHelmAppDetails(&res, appPath, appPath, &q)
require.NoError(t, err)
assert.Len(t, res.Helm.Parameters, 3)
assert.Len(t, res.Helm.ValueFiles, 4)
}
2 changes: 2 additions & 0 deletions reposerver/repository/testdata/values-files/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name: my-chart
version: 1.1.0
Empty file.
1 change: 1 addition & 0 deletions reposerver/repository/testdata/values-files/exclude.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exclude: yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
has:
the:
word:
values: yaml
1 change: 1 addition & 0 deletions reposerver/repository/testdata/values-files/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
values: yaml
Empty file.
5 changes: 3 additions & 2 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -799,14 +799,15 @@ func TestAuthenticate_bad_request_metadata(t *testing.T) {
},
}

ctx := context.Background()

for _, testData := range tests {
testDataCopy := testData

t.Run(testDataCopy.test, func(t *testing.T) {
t.Parallel()

// Must be declared here to avoid race.
ctx := context.Background() //nolint:ineffassign,staticcheck

argocd, _ := getTestServer(t, testDataCopy.anonymousEnabled, true)
ctx = metadata.NewIncomingContext(context.Background(), testDataCopy.metadata)

Expand Down
6 changes: 2 additions & 4 deletions util/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"net/url"
"os"
"os/exec"
"path"
"strings"

"github.com/ghodss/yaml"
Expand Down Expand Up @@ -143,11 +142,10 @@ func (h *helm) GetParameters(valuesFiles []pathutil.ResolvedFilePath) (map[strin
if err == nil && (parsedURL.Scheme == "http" || parsedURL.Scheme == "https") {
fileValues, err = config.ReadRemoteFile(file)
} else {
filePath := path.Join(h.cmd.WorkDir, file)
if _, err := os.Stat(filePath); os.IsNotExist(err) {
if _, err := os.Stat(file); os.IsNotExist(err) {
continue
}
fileValues, err = ioutil.ReadFile(filePath)
fileValues, err = ioutil.ReadFile(file)
}
if err != nil {
return nil, fmt.Errorf("failed to read value file %s: %s", file, err)
Expand Down
43 changes: 33 additions & 10 deletions util/helm/helm_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package helm

import (
"path/filepath"
"testing"

"github.com/stretchr/testify/require"

"github.com/argoproj/argo-cd/v2/util/io/path"

"github.com/argoproj/gitops-engine/pkg/utils/kube"
Expand Down Expand Up @@ -51,11 +54,16 @@ func TestHelmTemplateParams(t *testing.T) {
}

func TestHelmTemplateValues(t *testing.T) {
h, err := NewHelmApp("./testdata/redis", []HelmRepository{}, false, "", "", false)
repoRoot := "./testdata/redis"
repoRootAbs, err := filepath.Abs(repoRoot)
require.NoError(t, err)
h, err := NewHelmApp(repoRootAbs, []HelmRepository{}, false, "", "", false)
assert.NoError(t, err)
valuesPath, _, err := path.ResolveFilePath(repoRootAbs, repoRootAbs, "values-production.yaml", nil)
require.NoError(t, err)
opts := TemplateOpts{
Name: "test",
Values: []path.ResolvedFilePath{"values-production.yaml"},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests were passing relative paths. That worked when we were incorrectly using filepath.Join. Since the code now expects (and should always receive) absolute paths, we have to calculate absolute paths in the tests.

Values: []path.ResolvedFilePath{valuesPath},
}
objs, err := template(h, &opts)
assert.Nil(t, err)
Expand All @@ -72,33 +80,48 @@ func TestHelmTemplateValues(t *testing.T) {
}

func TestHelmGetParams(t *testing.T) {
h, err := NewHelmApp("./testdata/redis", nil, false, "", "", false)
repoRoot := "./testdata/redis"
repoRootAbs, err := filepath.Abs(repoRoot)
require.NoError(t, err)
h, err := NewHelmApp(repoRootAbs, nil, false, "", "", false)
assert.NoError(t, err)
params, err := h.GetParameters(nil)
assert.Nil(t, err)

slaveCountParam := params["cluster.slaveCount"]
assert.Equal(t, slaveCountParam, "1")
assert.Equal(t, "1", slaveCountParam)
}

func TestHelmGetParamsValueFiles(t *testing.T) {
h, err := NewHelmApp("./testdata/redis", nil, false, "", "", false)
repoRoot := "./testdata/redis"
repoRootAbs, err := filepath.Abs(repoRoot)
require.NoError(t, err)
h, err := NewHelmApp(repoRootAbs, nil, false, "", "", false)
assert.NoError(t, err)
params, err := h.GetParameters([]path.ResolvedFilePath{"values-production.yaml"})
valuesPath, _, err := path.ResolveFilePath(repoRootAbs, repoRootAbs, "values-production.yaml", nil)
require.NoError(t, err)
params, err := h.GetParameters([]path.ResolvedFilePath{valuesPath})
assert.Nil(t, err)

slaveCountParam := params["cluster.slaveCount"]
assert.Equal(t, slaveCountParam, "3")
assert.Equal(t, "3", slaveCountParam)
}

func TestHelmGetParamsValueFilesThatExist(t *testing.T) {
h, err := NewHelmApp("./testdata/redis", nil, false, "", "", false)
repoRoot := "./testdata/redis"
repoRootAbs, err := filepath.Abs(repoRoot)
require.NoError(t, err)
h, err := NewHelmApp(repoRootAbs, nil, false, "", "", false)
assert.NoError(t, err)
params, err := h.GetParameters([]path.ResolvedFilePath{"values-missing.yaml", "values-production.yaml"})
valuesMissingPath, _, err := path.ResolveFilePath(repoRootAbs, repoRootAbs, "values-missing.yaml", nil)
require.NoError(t, err)
valuesProductionPath, _, err := path.ResolveFilePath(repoRootAbs, repoRootAbs, "values-production.yaml", nil)
require.NoError(t, err)
params, err := h.GetParameters([]path.ResolvedFilePath{valuesMissingPath, valuesProductionPath})
assert.Nil(t, err)

slaveCountParam := params["cluster.slaveCount"]
assert.Equal(t, slaveCountParam, "3")
assert.Equal(t, "3", slaveCountParam)
}

func TestHelmTemplateReleaseNameOverwrite(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions util/io/path/resolved.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

// ResolvedFilePath represents a resolved file path and intended to prevent unintentional use of not verified file path.
// It is always either a URL or an absolute path.
type ResolvedFilePath string

// resolveSymbolicLinkRecursive resolves the symlink path recursively to its
Expand Down