Skip to content

Commit

Permalink
util: adding test cases
Browse files Browse the repository at this point in the history
Signed-off-by: Annaraya Narasagond <[email protected]>
  • Loading branch information
asn1809 committed Dec 16, 2024
1 parent 240c77e commit 717f791
Showing 1 changed file with 50 additions and 2 deletions.
52 changes: 50 additions & 2 deletions internal/controller/util/json_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import (
type testCases struct {
jsonPathExprs string
result bool
jsonText []byte
}

var jsonText1 = []byte(`{
var jsonDeployment = []byte(`{
"kind": "Deployment",
"spec": {
"progressDeadlineSeconds": 600,
Expand All @@ -38,18 +39,65 @@ var jsonText1 = []byte(`{
}
}`)

var jsonPod = []byte(`{
"kind": "Pod",
"spec": {
"progressDeadlineSeconds": 600,
"replicas": 1,
"revisionHistoryLimit": 10
},
"status": {
"replicas": 1,
"conditions": [
{
"status": "True",
"type": "Progressing"
},
{
"status": "True",
"type": "Available"
}
]
}
}`)

var jsonStatefulset = []byte(`{
"kind": "Statefulset",
"spec": {
"progressDeadlineSeconds": 600,
"replicas": 1,
"revisionHistoryLimit": 10
},
"status": {
"replicas": 1,
"conditions": [
{
"status": "True",
"type": "Progressing"
},
{
"status": "True",
"type": "Available"
}
]
}
}`)

var testCasesData = []testCases{
{
jsonPathExprs: "{$.status.conditions[0].status} == True",
result: true,
jsonText: jsonDeployment,
},
{
jsonPathExprs: "{$.spec.replicas} == 1",
result: true,
jsonText: jsonPod,
},
{
jsonPathExprs: "{$.status.conditions[0].status} == {True}",
result: false,
jsonText: jsonStatefulset,
},
}

Expand All @@ -60,7 +108,7 @@ func TestEvaluateCheckHookExp(t *testing.T) {
t.Run(strconv.Itoa(i), func(t *testing.T) {
var jsonData map[string]interface{}

err := json.Unmarshal(jsonText1, &jsonData)
err := json.Unmarshal(tt.jsonText, &jsonData)
if err != nil {
t.Error(err)
}
Expand Down

0 comments on commit 717f791

Please sign in to comment.