Skip to content

Commit

Permalink
removing more unrelated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shanalily committed Jan 25, 2022
1 parent 4899c16 commit 8ef9cfa
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 180 deletions.
1 change: 1 addition & 0 deletions api/internal/builtins/PrefixTransformer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/internal/builtins/SuffixTransformer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 0 additions & 29 deletions api/krusty/namespaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,32 +800,3 @@ metadata:
namespace: iter8-monitoring
`)
}

func TestNamespacedNumeric(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteF("secrets.yaml", `
apiVersion: v1
kind: Secret
metadata:
name: dummy
type: Opaque
data:
dummy: ""
`)
th.WriteK(".", `
resources:
- secrets.yaml
namespace: "01234"
`)
m := th.Run(".", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: v1
data:
dummy: ""
kind: Secret
metadata:
name: dummy
namespace: "01234"
type: Opaque
`)
}
76 changes: 0 additions & 76 deletions api/resmap/reswrangler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,82 +363,6 @@ func TestGetMatchingResourcesByCurrentId(t *testing.T) {
}
}

func TestGetMatchingResourcesByCurrentIdNumeric(t *testing.T) {
cmap := resid.NewGvk("", "v1", "ConfigMap")

r1 := rf.FromMap(
map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": map[string]interface{}{
"name": "alice",
"namespace": "01234",
},
})

m := resmaptest_test.NewRmBuilder(t, rf).
AddR(r1).ResMap()

result := m.GetMatchingResourcesByCurrentId(
resid.NewResIdWithNamespace(cmap, "alice", "01234").GvknEquals)
if len(result) != 1 {
t.Fatalf("Expected single map entry but got %v", result)
}

// nolint:goconst
tests := []struct {
name string
matcher IdMatcher
count int
}{
{
"match everything",
func(resid.ResId) bool { return true },
1,
},
{
"match nothing",
func(resid.ResId) bool { return false },
0,
},
{
"name is alice",
func(x resid.ResId) bool { return x.Name == "alice" },
1,
},
{
"01234 namespace",
func(x resid.ResId) bool {
return x.Namespace == "01234"
},
1,
},
{
"01234 deployment",
func(x resid.ResId) bool {
return x.Namespace == "01234" &&
x.Gvk.Kind == "Deployment"
},
0,
},
{
"01234 ConfigMap",
func(x resid.ResId) bool {
return x.Namespace == "01234" &&
x.Gvk.Kind == "ConfigMap"
},
1,
},
}
for _, tst := range tests {
result := m.GetMatchingResourcesByCurrentId(tst.matcher)
if len(result) != tst.count {
t.Fatalf("test '%s'; actual: %d, expected: %d",
tst.name, len(result), tst.count)
}
}
}

func TestGetMatchingResourcesByAnyId(t *testing.T) {
r1 := rf.FromMap(
map[string]interface{}{
Expand Down
28 changes: 0 additions & 28 deletions api/resource/origin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,6 @@ func TestTransformationsString(t *testing.T) {
},
},
}
origin3 := &Origin{
Repo: "github.com/myrepo",
Ref: "master",
ConfiguredIn: "config.yaml",
ConfiguredBy: kyaml.ResourceIdentifier{
TypeMeta: kyaml.TypeMeta{
APIVersion: "builtin",
Kind: "Generator",
},
NameMeta: kyaml.NameMeta{
Name: "my-name",
Namespace: "01234",
},
},
}

tests := []struct {
in Transformations
expected string
Expand Down Expand Up @@ -160,18 +144,6 @@ func TestTransformationsString(t *testing.T) {
kind: Generator
name: my-name
namespace: my-namespace
`,
},
{
in: Transformations{origin3},
expected: `- repo: github.com/myrepo
ref: master
configuredIn: config.yaml
configuredBy:
apiVersion: builtin
kind: Generator
name: my-name
namespace: "01234"
`,
},
{
Expand Down
3 changes: 1 addition & 2 deletions kyaml/yaml/rnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,7 @@ func (rn *RNode) SetNamespace(ns string) error {
return meta.PipeE(Clear(NamespaceField))
}
return rn.SetMapField(
// NewScalarRNode(ns), MetadataField, NamespaceField)
NewStringRNode(ns), MetadataField, NamespaceField)
NewScalarRNode(ns), MetadataField, NamespaceField)
}

// GetAnnotations gets the metadata annotations field.
Expand Down
62 changes: 17 additions & 45 deletions kyaml/yaml/rnode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1081,29 +1081,15 @@ const deploymentJSON = `
`

func TestRNodeSetNamespace(t *testing.T) {
testCases := map[string]struct {
ns string
}{
"simple": {
ns: "flanders",
},
"numeric": {
ns: "01234",
},
}
for n, tc := range testCases {
t.Run(n, func(t *testing.T) {
n := NewRNode(nil)
assert.Equal(t, "", n.GetNamespace())
assert.NoError(t, n.SetNamespace(""))
assert.Equal(t, "", n.GetNamespace())
if err := n.UnmarshalJSON([]byte(deploymentJSON)); err != nil {
t.Fatalf("unexpected unmarshaljson err: %v", err)
}
assert.NoError(t, n.SetNamespace(tc.ns))
assert.Equal(t, tc.ns, n.GetNamespace())
})
n := NewRNode(nil)
assert.Equal(t, "", n.GetNamespace())
assert.NoError(t, n.SetNamespace(""))
assert.Equal(t, "", n.GetNamespace())
if err := n.UnmarshalJSON([]byte(deploymentJSON)); err != nil {
t.Fatalf("unexpected unmarshaljson err: %v", err)
}
assert.NoError(t, n.SetNamespace("flanders"))
assert.Equal(t, "flanders", n.GetNamespace())
}

func TestRNodeSetLabels(t *testing.T) {
Expand Down Expand Up @@ -1819,30 +1805,16 @@ func TestSetName(t *testing.T) {
}

func TestSetNamespace(t *testing.T) {
testCases := map[string]struct {
ns string
}{
"simple": {
ns: "flanders",
},
"numeric": {
ns: "01234",
},
rn := NewRNode(nil)
if err := rn.UnmarshalJSON([]byte(deploymentBiggerJson)); err != nil {
t.Fatalf("unexpected unmarshaljson err: %v", err)
}
for n, tc := range testCases {
t.Run(n, func(t *testing.T) {
rn := NewRNode(nil)
if err := rn.UnmarshalJSON([]byte(deploymentBiggerJson)); err != nil {
t.Fatalf("unexpected unmarshaljson err: %v", err)
}
err := rn.SetNamespace(tc.ns)
require.NoError(t, err)
meta, err := rn.GetMeta()
require.NoError(t, err)
if expected, actual := tc.ns, meta.Namespace; expected != actual {
t.Fatalf("expected '%s', got '%s'", expected, actual)
}
})
err := rn.SetNamespace("flanders")
require.NoError(t, err)
meta, err := rn.GetMeta()
require.NoError(t, err)
if expected, actual := "flanders", meta.Namespace; expected != actual {
t.Fatalf("expected '%s', got '%s'", expected, actual)
}
}

Expand Down

0 comments on commit 8ef9cfa

Please sign in to comment.