update test to table driven with assertions & test GetMergedValues (#1721)
This commit is contained in:
parent
04b5151285
commit
5963dd364d
2
go.mod
2
go.mod
|
|
@ -184,6 +184,7 @@ require (
|
||||||
github.com/docker/go-metrics v0.0.1 // indirect
|
github.com/docker/go-metrics v0.0.1 // indirect
|
||||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||||
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
|
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
|
||||||
|
github.com/evanphx/json-patch v5.9.0+incompatible // indirect
|
||||||
github.com/extism/go-sdk v1.3.1 // indirect
|
github.com/extism/go-sdk v1.3.1 // indirect
|
||||||
github.com/felixge/httpsnoop v1.0.4 // indirect
|
github.com/felixge/httpsnoop v1.0.4 // indirect
|
||||||
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
|
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
|
||||||
|
|
@ -232,6 +233,7 @@ require (
|
||||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||||
github.com/mailru/easyjson v0.7.7 // indirect
|
github.com/mailru/easyjson v0.7.7 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
|
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
|
||||||
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
|
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
|
||||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
|
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
|
||||||
github.com/moby/locker v1.0.1 // indirect
|
github.com/moby/locker v1.0.1 // indirect
|
||||||
|
|
|
||||||
4
go.sum
4
go.sum
|
|
@ -443,6 +443,8 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.m
|
||||||
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
|
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
|
||||||
github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE=
|
github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE=
|
||||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||||
|
github.com/evanphx/json-patch v5.9.0+incompatible h1:fBXyNpNMuTTDdquAq/uisOr2lShz4oaXpDTX2bLe7ls=
|
||||||
|
github.com/evanphx/json-patch v5.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
||||||
github.com/extism/go-sdk v1.3.1 h1:eVpuv36b67Km/tAb7Cq6msHEW8kkdFgpZO/7fCwjuoE=
|
github.com/extism/go-sdk v1.3.1 h1:eVpuv36b67Km/tAb7Cq6msHEW8kkdFgpZO/7fCwjuoE=
|
||||||
github.com/extism/go-sdk v1.3.1/go.mod h1:tPMWfCSOThie3LSTSZKbrQjRm2oAXxUUjSE4HJWjYQM=
|
github.com/extism/go-sdk v1.3.1/go.mod h1:tPMWfCSOThie3LSTSZKbrQjRm2oAXxUUjSE4HJWjYQM=
|
||||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||||
|
|
@ -774,6 +776,8 @@ github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRC
|
||||||
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
|
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
|
||||||
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||||
|
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
|
||||||
|
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
|
||||||
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
|
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
|
||||||
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
|
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
|
||||||
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
|
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
|
||||||
|
|
|
||||||
|
|
@ -4,98 +4,91 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
// See https://github.com/roboll/helmfile/issues/1150
|
func TestMerge_Issues(t *testing.T) {
|
||||||
func TestMerge_OverwriteNilValue_Issue1150(t *testing.T) {
|
tests := []struct {
|
||||||
dst := &Environment{
|
name string
|
||||||
Name: "dst",
|
dst *Environment
|
||||||
Values: map[string]any{
|
src *Environment
|
||||||
"components": map[string]any{
|
expected map[string]any
|
||||||
"etcd-operator": nil,
|
}{
|
||||||
|
{
|
||||||
|
name: "OverwriteNilValue_Issue1150",
|
||||||
|
dst: &Environment{
|
||||||
|
Name: "dst",
|
||||||
|
Values: map[string]any{
|
||||||
|
"components": map[string]any{
|
||||||
|
"etcd-operator": nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Defaults: nil,
|
||||||
},
|
},
|
||||||
},
|
src: &Environment{
|
||||||
Defaults: nil,
|
Name: "src",
|
||||||
}
|
Values: map[string]any{
|
||||||
|
"components": map[string]any{
|
||||||
src := &Environment{
|
"etcd-operator": map[string]any{
|
||||||
Name: "src",
|
"version": "0.10.3",
|
||||||
Values: map[string]any{
|
},
|
||||||
"components": map[string]any{
|
},
|
||||||
"etcd-operator": map[string]any{
|
},
|
||||||
"version": "0.10.3",
|
Defaults: nil,
|
||||||
|
},
|
||||||
|
expected: map[string]any{
|
||||||
|
"components": map[string]any{
|
||||||
|
"etcd-operator": map[string]any{
|
||||||
|
"version": "0.10.3",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Defaults: nil,
|
{
|
||||||
}
|
name: "OverwriteWithNilValue_Issue1154",
|
||||||
|
dst: &Environment{
|
||||||
merged, err := dst.Merge(src)
|
Name: "dst",
|
||||||
if err != nil {
|
Values: map[string]any{
|
||||||
t.Fatal(err)
|
"components": map[string]any{
|
||||||
}
|
"etcd-operator": map[string]any{
|
||||||
|
"version": "0.10.0",
|
||||||
actual := merged.Values
|
},
|
||||||
|
},
|
||||||
expected := map[string]any{
|
},
|
||||||
"components": map[string]any{
|
Defaults: nil,
|
||||||
"etcd-operator": map[string]any{
|
|
||||||
"version": "0.10.3",
|
|
||||||
},
|
},
|
||||||
},
|
src: &Environment{
|
||||||
}
|
Name: "src",
|
||||||
|
Values: map[string]any{
|
||||||
if diff := cmp.Diff(expected, actual); diff != "" {
|
"components": map[string]any{
|
||||||
t.Errorf(diff)
|
"etcd-operator": map[string]any{
|
||||||
}
|
"version": "0.10.3",
|
||||||
}
|
},
|
||||||
|
"prometheus": nil,
|
||||||
// See https://github.com/roboll/helmfile/issues/1154
|
},
|
||||||
func TestMerge_OverwriteWithNilValue_Issue1154(t *testing.T) {
|
},
|
||||||
dst := &Environment{
|
Defaults: nil,
|
||||||
Name: "dst",
|
},
|
||||||
Values: map[string]any{
|
expected: map[string]any{
|
||||||
"components": map[string]any{
|
"components": map[string]any{
|
||||||
"etcd-operator": map[string]any{
|
"etcd-operator": map[string]any{
|
||||||
"version": "0.10.0",
|
"version": "0.10.3",
|
||||||
|
},
|
||||||
|
"prometheus": nil,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Defaults: nil,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
src := &Environment{
|
for _, tt := range tests {
|
||||||
Name: "src",
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
Values: map[string]any{
|
merged, err := tt.dst.Merge(tt.src)
|
||||||
"components": map[string]any{
|
require.NoError(t, err)
|
||||||
"etcd-operator": map[string]any{
|
|
||||||
"version": "0.10.3",
|
|
||||||
},
|
|
||||||
"prometheus": nil,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Defaults: nil,
|
|
||||||
}
|
|
||||||
|
|
||||||
merged, err := dst.Merge(src)
|
actual := merged.Values
|
||||||
if err != nil {
|
assert.Empty(t, cmp.Diff(tt.expected, actual), "unexpected diff")
|
||||||
t.Fatal(err)
|
})
|
||||||
}
|
|
||||||
|
|
||||||
actual := merged.Values
|
|
||||||
|
|
||||||
expected := map[string]any{
|
|
||||||
"components": map[string]any{
|
|
||||||
"etcd-operator": map[string]any{
|
|
||||||
"version": "0.10.3",
|
|
||||||
},
|
|
||||||
"prometheus": nil,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
if diff := cmp.Diff(expected, actual); diff != "" {
|
|
||||||
t.Errorf(diff)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -105,3 +98,46 @@ func TestNew(t *testing.T) {
|
||||||
|
|
||||||
require.Equal(t, envName, env.Name, "environment name should be %s, but got %s", envName, env.Name)
|
require.Equal(t, envName, env.Name, "environment name should be %s, but got %s", envName, env.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEnvironment_DeepCopy(t *testing.T) {
|
||||||
|
env := &Environment{
|
||||||
|
Name: "test",
|
||||||
|
Values: map[string]any{
|
||||||
|
"foo": "bar",
|
||||||
|
},
|
||||||
|
Defaults: map[string]any{
|
||||||
|
"baz": "qux",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
copy := env.DeepCopy()
|
||||||
|
|
||||||
|
assert.Equal(t, env.Name, copy.Name)
|
||||||
|
assert.Equal(t, env.Values, copy.Values)
|
||||||
|
assert.Equal(t, env.Defaults, copy.Defaults)
|
||||||
|
|
||||||
|
copy.Values["foo"] = "modified"
|
||||||
|
assert.NotEqual(t, env.Values["foo"], copy.Values["foo"])
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEnvironment_GetMergedValues(t *testing.T) {
|
||||||
|
env := &Environment{
|
||||||
|
Name: "test",
|
||||||
|
Values: map[string]any{
|
||||||
|
"foo": "bar",
|
||||||
|
},
|
||||||
|
Defaults: map[string]any{
|
||||||
|
"baz": "qux",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
mergedValues, err := env.GetMergedValues()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
expected := map[string]any{
|
||||||
|
"foo": "bar",
|
||||||
|
"baz": "qux",
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, expected, mergedValues)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue