Add regression tests for environment values merge (#1170)

This is a follow-up for #1169 and it also relates to #1168
This commit is contained in:
KUOKA Yusuke 2020-04-04 14:27:29 +09:00 committed by GitHub
parent 25aae679b1
commit 1654ce4c18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 139 additions and 0 deletions

View File

@ -0,0 +1,116 @@
package state
import (
"github.com/google/go-cmp/cmp"
"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,
}
return NewEnvironmentValuesLoader(storage, ioutil.ReadFile, sugar)
}
// 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)
}
}

View File

@ -0,0 +1,7 @@
addons:
mychart:
skip: true
name: mychart
namespace: kube-system
chart: stable/mychart
version: 1.0.0

View File

@ -0,0 +1,3 @@
addons:
mychart:
skip: false

2
pkg/state/testdata/values.1.yaml vendored Normal file
View File

@ -0,0 +1,2 @@
components:
etcd-operator:

3
pkg/state/testdata/values.2.yaml vendored Normal file
View File

@ -0,0 +1,3 @@
components:
etcd-operator:
version: 0.10.3

3
pkg/state/testdata/values.3.yaml vendored Normal file
View File

@ -0,0 +1,3 @@
components:
etcd-operator:
version: 0.10.0

4
pkg/state/testdata/values.4.yaml vendored Normal file
View File

@ -0,0 +1,4 @@
components:
etcd-operator:
version: 0.10.3
prometheus:

1
pkg/state/testdata/values.5.yaml vendored Normal file
View File

@ -0,0 +1 @@
affinity: {}