Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
omrishiv committed May 14, 2023
1 parent 931eeb0 commit 86fb6e1
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions pkg/kube/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,110 @@ func TestGenericReplacement_multiString(t *testing.T) {
assertSuccessfulReplacement(&dummyResource, &expected, t)
}

func TestGenericReplacement_keyReplacement(t *testing.T) {
dummyResource := Resource{
TemplateData: map[string]interface{}{
"<name>": "default",
"namespace": "test",
},
Data: map[string]interface{}{
"namespace": "default",
"name": "app",
"tag": "latest",
},
Annotations: map[string]string{
(types.AVPPathAnnotation): "",
},
}

replaceInner(&dummyResource, &dummyResource.TemplateData, genericReplacement)

expected := Resource{
TemplateData: map[string]interface{}{
"app": "default",
"namespace": "test",
},
Data: map[string]interface{}{
"namespace": "default",
"name": "app",
"tag": "latest",
},

replacementErrors: []error{},
}

assertSuccessfulReplacement(&dummyResource, &expected, t)
}

func TestGenericReplacement_keyAndValueReplacement(t *testing.T) {
dummyResource := Resource{
TemplateData: map[string]interface{}{
"<name>": "default",
"tag": "<tag>",
},
Data: map[string]interface{}{
"namespace": "default",
"name": "app",
"tag": "latest",
},
Annotations: map[string]string{
(types.AVPPathAnnotation): "",
},
}

replaceInner(&dummyResource, &dummyResource.TemplateData, genericReplacement)

expected := Resource{
TemplateData: map[string]interface{}{
"app": "default",
"tag": "latest",
},
Data: map[string]interface{}{
"namespace": "default",
"name": "app",
"tag": "latest",
},
replacementErrors: []error{},
}

assertSuccessfulReplacement(&dummyResource, &expected, t)
}
func TestGenericReplacement_keyAndValueReplacementNoPathAnnotation(t *testing.T) {
mv := helpers.MockVault{}
mv.LoadData(map[string]interface{}{
"version": "one",
})
dummyResource := Resource{
TemplateData: map[string]interface{}{
"<path:blah/blah#version>": "default",
"version": "<path:blah/blah#version>",
},
Data: map[string]interface{}{
"namespace": "default",
"name": "app",
"tag": "latest",
},
Backend: &mv,
Annotations: map[string]string{},
}

replaceInner(&dummyResource, &dummyResource.TemplateData, genericReplacement)

expected := Resource{
TemplateData: map[string]interface{}{
"one": "default",
"version": "one",
},
Data: map[string]interface{}{
"namespace": "default",
"name": "app",
"tag": "latest",
},
replacementErrors: []error{},
}

assertSuccessfulReplacement(&dummyResource, &expected, t)
}
func TestGenericReplacement_Base64(t *testing.T) {
dummyResource := Resource{
TemplateData: map[string]interface{}{
Expand Down

0 comments on commit 86fb6e1

Please sign in to comment.