Files
helmfile/pkg/state/envvals_loader_test.go
T
Kevin J. Qiu 0f86cc9b87 Add the ability to load a remote environment values file (#1296)
Enables the user to specify a remote path for an environment values file, e.g.,

```yaml
environments:
  cluster-azure-us-west:
    values:
      - git::https://git.company.org/helmfiles/global/azure.yaml?ref=master
      - git::https://git.company.org/helmfiles/global/us-west.yaml?ref=master
  cluster-gcp-europe-west:
    values:
      - git::https://git.company.org/helmfiles/global/gcp.yaml?ref=master
      - git::https://git.company.org/helmfiles/global/europe-west.yaml?ref=master

releases:
  - ...
```

This is particularly useful when you co-locate helmfiles within your project repo but want to reuse the definitions in a global repo.
2020-06-11 10:04:01 +09:00

121 lines
2.8 KiB
Go

package state
import (
"github.com/google/go-cmp/cmp"
"github.com/roboll/helmfile/pkg/remote"
"go.uber.org/zap"
"io/ioutil"
"path/filepath"
"testing"
)
func newLoader() *EnvironmentValuesLoader {
log, err := zap.NewDevelopment(zap.AddStacktrace(zap.DebugLevel))
if err != nil {
panic(err)
}
sugar := log.Sugar()
storage := &Storage{
FilePath: "./helmfile.yaml",
basePath: ".",
glob: filepath.Glob,
logger: sugar,
}
readFile := func(s string) ([]byte, error) { return []byte{}, nil }
dirExists := func(d string) bool { return false }
fileExists := func(f string) bool { return false }
return NewEnvironmentValuesLoader(storage, ioutil.ReadFile, sugar, remote.NewRemote(sugar, "/tmp", readFile, dirExists, fileExists))
}
// See https://github.com/roboll/helmfile/pull/1169
func TestEnvValsLoad_SingleValuesFile(t *testing.T) {
l := newLoader()
actual, err := l.LoadEnvironmentValues(nil, []interface{}{"testdata/values.5.yaml"})
if err != nil {
t.Fatal(err)
}
expected := map[string]interface{}{
"affinity": map[string]interface{}{},
}
if diff := cmp.Diff(expected, actual); diff != "" {
t.Errorf(diff)
}
}
// See https://github.com/roboll/helmfile/issues/1150
func TestEnvValsLoad_OverwriteNilValue_Issue1150(t *testing.T) {
l := newLoader()
actual, err := l.LoadEnvironmentValues(nil, []interface{}{"testdata/values.1.yaml", "testdata/values.2.yaml"})
if err != nil {
t.Fatal(err)
}
expected := map[string]interface{}{
"components": map[string]interface{}{
"etcd-operator": map[string]interface{}{
"version": "0.10.3",
},
},
}
if diff := cmp.Diff(expected, actual); diff != "" {
t.Errorf(diff)
}
}
// See https://github.com/roboll/helmfile/issues/1154
func TestEnvValsLoad_OverwriteWithNilValue_Issue1154(t *testing.T) {
l := newLoader()
actual, err := l.LoadEnvironmentValues(nil, []interface{}{"testdata/values.3.yaml", "testdata/values.4.yaml"})
if err != nil {
t.Fatal(err)
}
expected := map[string]interface{}{
"components": map[string]interface{}{
"etcd-operator": map[string]interface{}{
"version": "0.10.3",
},
"prometheus": nil,
},
}
if diff := cmp.Diff(expected, actual); diff != "" {
t.Errorf(diff)
}
}
// See https://github.com/roboll/helmfile/issues/1168
func TestEnvValsLoad_OverwriteEmptyValue_Issue1168(t *testing.T) {
l := newLoader()
actual, err := l.LoadEnvironmentValues(nil, []interface{}{"testdata/issues/1168/addons.yaml", "testdata/issues/1168/addons2.yaml"})
if err != nil {
t.Fatal(err)
}
expected := map[string]interface{}{
"addons": map[string]interface{}{
"mychart": map[string]interface{}{
"skip": false,
"name": "mychart",
"namespace": "kube-system",
"chart": "stable/mychart",
"version": "1.0.0",
},
},
}
if diff := cmp.Diff(expected, actual); diff != "" {
t.Errorf(diff)
}
}