mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-18 04:25:31 +00:00
[doc]: https://github.com/golang/go/wiki/Modules#releasing-modules-v2-or-higher Per this Go modules [doc] a repo or branch that's already tagged v2 or higher should increment the major version (e.g. go to v3) when releasing their first Go module-based packages. At the moment, the kustomize repo has these top level packages in the sigs.k8s.io/kustomize module: - `cmd` - holds main program for kustomize Conceivably someone can depend on this package for integration tests. - `internal` - intentionally unreleased subpackages - `k8sdeps` - an adapter wrapping k8s dependencies This exists only for use in pre-Go-modules kustomize-into-kubectl integration and won't live much longer (as everything involved is switching to Go modules). - `pkg` - kustomize packages for export This should shrink in later versions, since the surface area is too large, containing sub-packages that should be in 'internal'. - `plugin` - holds main programs for plugins This PR changes the top level go.mod file from ``` module sigs.k8s.io/kustomize ``` to ``` module sigs.k8s.io/kustomize/v3 ``` and adjusts all import statements to reflect the change.
92 lines
2.0 KiB
Go
92 lines
2.0 KiB
Go
// Copyright 2019 The Kubernetes Authors.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package loader
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
|
"sigs.k8s.io/kustomize/v3/pkg/types"
|
|
"sigs.k8s.io/kustomize/v3/pkg/validators"
|
|
)
|
|
|
|
func TestKeyValuesFromLines(t *testing.T) {
|
|
tests := []struct {
|
|
desc string
|
|
content string
|
|
expectedPairs []types.Pair
|
|
expectedErr bool
|
|
}{
|
|
{
|
|
desc: "valid kv content parse",
|
|
content: `
|
|
k1=v1
|
|
k2=v2
|
|
`,
|
|
expectedPairs: []types.Pair{
|
|
{Key: "k1", Value: "v1"},
|
|
{Key: "k2", Value: "v2"},
|
|
},
|
|
expectedErr: false,
|
|
},
|
|
{
|
|
desc: "content with comments",
|
|
content: `
|
|
k1=v1
|
|
#k2=v2
|
|
`,
|
|
expectedPairs: []types.Pair{
|
|
{Key: "k1", Value: "v1"},
|
|
},
|
|
expectedErr: false,
|
|
},
|
|
// TODO: add negative testcases
|
|
}
|
|
|
|
l := NewFileLoaderAtRoot(
|
|
validators.MakeFakeValidator(), fs.MakeFakeFS())
|
|
for _, test := range tests {
|
|
pairs, err := l.keyValuesFromLines([]byte(test.content))
|
|
if test.expectedErr && err == nil {
|
|
t.Fatalf("%s should not return error", test.desc)
|
|
}
|
|
if !reflect.DeepEqual(pairs, test.expectedPairs) {
|
|
t.Errorf("%s should succeed, got:%v exptected:%v", test.desc, pairs, test.expectedPairs)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestKeyValuesFromFileSources(t *testing.T) {
|
|
tests := []struct {
|
|
description string
|
|
sources []string
|
|
expected []types.Pair
|
|
}{
|
|
{
|
|
description: "create kvs from file sources",
|
|
sources: []string{"files/app-init.ini"},
|
|
expected: []types.Pair{
|
|
{
|
|
Key: "app-init.ini",
|
|
Value: "FOO=bar",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
fSys := fs.MakeFakeFS()
|
|
fSys.WriteFile("/files/app-init.ini", []byte("FOO=bar"))
|
|
l := NewFileLoaderAtRoot(validators.MakeFakeValidator(), fSys)
|
|
for _, tc := range tests {
|
|
kvs, err := l.keyValuesFromFileSources(tc.sources)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if !reflect.DeepEqual(kvs, tc.expected) {
|
|
t.Fatalf("in testcase: %q updated:\n%#v\ndoesn't match expected:\n%#v\n", tc.description, kvs, tc.expected)
|
|
}
|
|
}
|
|
}
|