Skip to content

Commit

Permalink
Add and update tests around diamond import of folders.
Browse files Browse the repository at this point in the history
1. Test simple import of common resources.
2. Test simple import of common variables.
3. Test simple import of variables without their target
   resources in the parent folders.
4. Test that the algorithm is reporting proper errors
   in case of not supported diamond import of resources.
5. Test that the algorithm is reporting proper errors
   in case of not supported diamond import of variables.
6. Update errors messages in existing tests.
  • Loading branch information
jbrette committed Jul 9, 2019
1 parent b43b841 commit 502eae5
Show file tree
Hide file tree
Showing 4 changed files with 509 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pkg/target/complexcomposition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ resources:
t.Fatalf("Expected resource accumulation error")
}
if !strings.Contains(
err.Error(), "already registered id: apps_v1_StatefulSet|~X|my-sts") {
err.Error(), "conflict between") {
t.Fatalf("Unexpected err: %v", err)
}

Expand Down Expand Up @@ -283,7 +283,7 @@ resources:
t.Fatalf("Expected resource accumulation error")
}
if !strings.Contains(
err.Error(), "already registered id: apps_v1_StatefulSet|~X|my-sts") {
err.Error(), "conflict between") {
t.Fatalf("Unexpected err: %v", err)
}

Expand Down
133 changes: 131 additions & 2 deletions pkg/target/diamondcomposition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,49 @@ func writeDeploymentBase(th *kusttest_test.KustTestHarness) {
th.WriteK("/app/base", `
resources:
- deployment.yaml
patchesStrategicMerge:
- dep-patch.yaml
`)

th.WriteF("/app/base/deployment.yaml", `
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
template:
spec:
containers:
- name: my-deployment
image: my-image
`)

th.WriteF("/app/base/dep-patch.yaml", `
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
template:
spec:
dnsPolicy: "None"
`)
}

func writeDeploymentBaseNoPatch(th *kusttest_test.KustTestHarness) {
th.WriteK("/app/base", `
resources:
- deployment.yaml
`)

th.WriteF("/app/base/deployment.yaml", `
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
template:
spec:
containers:
- name: my-deployment
image: my-image
Expand Down Expand Up @@ -122,7 +154,11 @@ patchesStrategicMerge:
// \ | /
// base
//
func TestIssue1251_CompositeDiamond_Failure(t *testing.T) {

// In the case, the DeploymentBase is setting the DnsPolicy to None.
// Kustomize detects a merge conflict when merging probe, dns and restart
// into composite.
func TestIssue1251_CompositeDiamond_ProbeDnsRestart_MergeConflict(t *testing.T) {
th := kusttest_test.NewKustTestHarness(t, "/app/composite")
writeDeploymentBase(th)
writeProbeOverlay(th)
Expand All @@ -141,7 +177,55 @@ resources:
t.Fatalf("Expected resource accumulation error")
}
if !strings.Contains(
err.Error(), "already registered id: apps_v1_Deployment|~X|my-deployment") {
err.Error(), "conflict between") {
t.Fatalf("Unexpected err: %v", err)
}
}

func TestIssue1251_CompositeDiamond_ProbeRestartDns_MergeConflict(t *testing.T) {
th := kusttest_test.NewKustTestHarness(t, "/app/composite")
writeDeploymentBase(th)
writeProbeOverlay(th)
writeDNSOverlay(th)
writeRestartOverlay(th)

th.WriteK("/app/composite", `
resources:
- ../probe
- ../restart
- ../dns
`)

_, err := th.MakeKustTarget().MakeCustomizedResMap()
if err == nil {
t.Fatalf("Expected resource accumulation error")
}
if !strings.Contains(
err.Error(), "conflict between") {
t.Fatalf("Unexpected err: %v", err)
}
}

func TestIssue1251_CompositeDiamond_DnsProbeRestart_MergeConflict(t *testing.T) {
th := kusttest_test.NewKustTestHarness(t, "/app/composite")
writeDeploymentBase(th)
writeProbeOverlay(th)
writeDNSOverlay(th)
writeRestartOverlay(th)

th.WriteK("/app/composite", `
resources:
- ../dns
- ../probe
- ../restart
`)

_, err := th.MakeKustTarget().MakeCustomizedResMap()
if err == nil {
t.Fatalf("Expected resource accumulation error")
}
if !strings.Contains(
err.Error(), "conflict between") {
t.Fatalf("Unexpected err: %v", err)
}
}
Expand All @@ -165,6 +249,51 @@ spec:
restartPolicy: Always
`

// Same test except that there no conflict to be detected in during
// the merge
func TestIssue1251_CompositeDiamond_ProbeRestartDns(t *testing.T) {
th := kusttest_test.NewKustTestHarness(t, "/app/composite")
writeDeploymentBaseNoPatch(th)
writeProbeOverlay(th)
writeDNSOverlay(th)
writeRestartOverlay(th)

th.WriteK("/app/composite", `
resources:
- ../probe
- ../dns
- ../restart
`)

m, err := th.MakeKustTarget().MakeCustomizedResMap()
if err != nil {
t.Fatalf("Err: %v", err)
}
th.AssertActualEqualsExpected(m, expectedPatchedDeployment)
}

// Identical test. Validate that ordering of resources as no effect.
func TestIssue1251_CompositeDiamond_ProbeDnsRestart(t *testing.T) {
th := kusttest_test.NewKustTestHarness(t, "/app/composite")
writeDeploymentBaseNoPatch(th)
writeProbeOverlay(th)
writeDNSOverlay(th)
writeRestartOverlay(th)

th.WriteK("/app/composite", `
resources:
- ../probe
- ../restart
- ../dns
`)

m, err := th.MakeKustTarget().MakeCustomizedResMap()
if err != nil {
t.Fatalf("Err: %v", err)
}
th.AssertActualEqualsExpected(m, expectedPatchedDeployment)
}

// This test reuses some methods from TestIssue1251_CompositeDiamond,
// but overwrites the kustomization files in the overlays.
func TestIssue1251_Patches_Overlayed(t *testing.T) {
Expand Down
Loading

0 comments on commit 502eae5

Please sign in to comment.