tweak output formatting
This commit is contained in:
@@ -102,7 +102,7 @@ func BodyContains(testCase *TestCase) (bool, error) {
|
|||||||
// search through all the results to see if the expected value is there
|
// search through all the results to see if the expected value is there
|
||||||
for i := range results {
|
for i := range results {
|
||||||
if strings.Contains(results[i].(string), v) {
|
if strings.Contains(results[i].(string), v) {
|
||||||
fmt.Printf("Expected value of '%s' matches, success\n", v)
|
fmt.Printf("Expected value of '%s' matches\n", v)
|
||||||
checkFound = true
|
checkFound = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -123,13 +123,25 @@ func BodyContains(testCase *TestCase) (bool, error) {
|
|||||||
|
|
||||||
func BodyHasKeys(testCase *TestCase) (bool, error) {
|
func BodyHasKeys(testCase *TestCase) (bool, error) {
|
||||||
for _, key := range testCase.Expect.Body.HasKeys {
|
for _, key := range testCase.Expect.Body.HasKeys {
|
||||||
// If the body response was json then we stored it already when running the test
|
|
||||||
if _, ok := testCase.ResultBodyMap[key]; ok {
|
results := findKey(key, testCase.ResultBodyMap)
|
||||||
//fmt.Printf("Confirmed body has key '%s'\n", key)
|
|
||||||
|
if len(results) > 0 {
|
||||||
|
fmt.Printf("Found key '%s' with values %v\n", key, results)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Body HasKeys test failed, expected key '%s' not found\n", key)
|
fmt.Printf("Body HasKeys test failed, expected key '%s' not found\n", key)
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
// If the body response was json then we stored it already when running the test
|
||||||
|
if _, ok := testCase.ResultBodyMap[key]; ok {
|
||||||
|
//fmt.Printf("Confirmed body has key '%s'\n", key)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("Body HasKeys test failed, expected key '%s' not found\n", key)
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
return true, nil
|
return true, nil
|
||||||
|
57
group-test.json
Normal file
57
group-test.json
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
{
|
||||||
|
"name": "CBS group testing",
|
||||||
|
"testCases": {
|
||||||
|
"test1": {
|
||||||
|
"path": "/api/login",
|
||||||
|
"method": "POST",
|
||||||
|
"description": "Perform login",
|
||||||
|
"body": {
|
||||||
|
"username": "Administrator",
|
||||||
|
"password": "Password123"
|
||||||
|
},
|
||||||
|
"expect": {
|
||||||
|
"header": {
|
||||||
|
"contains": {
|
||||||
|
"http_status": "200",
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"body": {
|
||||||
|
"hasKeys": ["access_token"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"test2": {
|
||||||
|
"path": "/api/admin/groups",
|
||||||
|
"method": "GET",
|
||||||
|
"description": "get group listing",
|
||||||
|
"expect": {
|
||||||
|
"header": {
|
||||||
|
"contains": {
|
||||||
|
"http_status": "200"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"body": {
|
||||||
|
"hasKeys": ["groupName"],
|
||||||
|
"contains": {
|
||||||
|
"message": "success"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"url": "https://10.63.39.130:8443",
|
||||||
|
"insecure": true,
|
||||||
|
"header": {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": "Bearer %ACCESS_TOKEN%"
|
||||||
|
},
|
||||||
|
"capture": {
|
||||||
|
"test1": {
|
||||||
|
"body": {
|
||||||
|
"access_token": "%ACCESS_TOKEN%"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
6
main.go
6
main.go
@@ -27,6 +27,7 @@ func main() {
|
|||||||
|
|
||||||
// Process command line arguments
|
// Process command line arguments
|
||||||
flag.StringVar(&inputJson, "input", "./tests.json", "Full path to input json test definition file")
|
flag.StringVar(&inputJson, "input", "./tests.json", "Full path to input json test definition file")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
// Read the json input file
|
// Read the json input file
|
||||||
if fileExists(inputJson) {
|
if fileExists(inputJson) {
|
||||||
@@ -51,6 +52,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RunTest(&testDefinitions.TestCases[i])
|
RunTest(&testDefinitions.TestCases[i])
|
||||||
|
fmt.Printf("\nRunning checks on output\n")
|
||||||
success, err := CheckResults(&testDefinitions.TestCases[i])
|
success, err := CheckResults(&testDefinitions.TestCases[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error running test case : %s\n", err)
|
fmt.Printf("Error running test case : %s\n", err)
|
||||||
@@ -60,11 +62,13 @@ func main() {
|
|||||||
fmt.Printf("Test result failed\n")
|
fmt.Printf("Test result failed\n")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Tests successful\n")
|
fmt.Printf("\nTest '%s' successful\n", testDefinitions.TestCases[i].Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Printf("\nCongratulations, all tests passed!\n\n")
|
||||||
|
|
||||||
// For debugging, just dump the output
|
// For debugging, just dump the output
|
||||||
//fmt.Printf("%+v\n", testDefinitions)
|
//fmt.Printf("%+v\n", testDefinitions)
|
||||||
}
|
}
|
||||||
|
@@ -25,7 +25,7 @@ func RunTest(testCase *TestCase) error {
|
|||||||
}
|
}
|
||||||
client := &http.Client{Transport: tr}
|
client := &http.Client{Transport: tr}
|
||||||
|
|
||||||
fmt.Printf("\nRunning %s : %s\n", testCase.Name, testCase.Description)
|
fmt.Printf("\nRunning %s : %s\n\n", testCase.Name, testCase.Description)
|
||||||
|
|
||||||
// Determine URL
|
// Determine URL
|
||||||
if len(testDefinitions.BaseUrl) > 0 {
|
if len(testDefinitions.BaseUrl) > 0 {
|
||||||
|
52
tests.json
52
tests.json
@@ -99,7 +99,7 @@
|
|||||||
},
|
},
|
||||||
"test10": {
|
"test10": {
|
||||||
"path": "/api/admin/unlock",
|
"path": "/api/admin/unlock",
|
||||||
"disabled": true,
|
"disabled": false,
|
||||||
"method": "POST",
|
"method": "POST",
|
||||||
"description": "provide unlock key",
|
"description": "provide unlock key",
|
||||||
"body": {
|
"body": {
|
||||||
@@ -115,7 +115,7 @@
|
|||||||
},
|
},
|
||||||
"test11": {
|
"test11": {
|
||||||
"path": "/api/admin/unlock",
|
"path": "/api/admin/unlock",
|
||||||
"disabled": true,
|
"disabled": false,
|
||||||
"method": "POST",
|
"method": "POST",
|
||||||
"description": "repeat provide unlock key",
|
"description": "repeat provide unlock key",
|
||||||
"body": {
|
"body": {
|
||||||
@@ -129,6 +129,26 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"test12": {
|
||||||
|
"path": "/api/secret/store",
|
||||||
|
"disabled": true,
|
||||||
|
"method": "POST",
|
||||||
|
"description": "store first new secret",
|
||||||
|
"body": {
|
||||||
|
"safeId": 1,
|
||||||
|
"deviceName": "avcp01.cdc.home",
|
||||||
|
"deviceCategory": "appliance",
|
||||||
|
"userName": "service@cdc.home",
|
||||||
|
"secretValue": "TheWiggles"
|
||||||
|
},
|
||||||
|
"expect": {
|
||||||
|
"header": {
|
||||||
|
"contains": {
|
||||||
|
"http_status": "200"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"test20": {
|
"test20": {
|
||||||
"path": "/api/secret/list",
|
"path": "/api/secret/list",
|
||||||
"disabled": false,
|
"disabled": false,
|
||||||
@@ -179,8 +199,30 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"test23": {
|
"test23": {
|
||||||
|
"path": "/api/secret/retrieve",
|
||||||
|
"method": "POST",
|
||||||
|
"description": "get updated secret",
|
||||||
|
"body": {
|
||||||
|
"deviceName": "adcp01.cdc.home",
|
||||||
|
"deviceCategory": "windows-server",
|
||||||
|
"userName": "dummy@cdc.home"
|
||||||
|
},
|
||||||
|
"expect": {
|
||||||
|
"header": {
|
||||||
|
"contains": {
|
||||||
|
"http_status": "200"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"body": {
|
||||||
|
"contains": {
|
||||||
|
"deviceName": "adcp01.cdc.home"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"test24": {
|
||||||
"path": "/api/secret/delete",
|
"path": "/api/secret/delete",
|
||||||
"method": "POST",
|
"method": "POST",
|
||||||
"description": "delete existing secret",
|
"description": "delete existing secret",
|
||||||
@@ -197,7 +239,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"test24": {
|
"test25": {
|
||||||
"path": "/api/secret/store",
|
"path": "/api/secret/store",
|
||||||
"method": "POST",
|
"method": "POST",
|
||||||
"description": "store new secret",
|
"description": "store new secret",
|
||||||
@@ -216,7 +258,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"test25": {
|
"test26": {
|
||||||
"path": "/api/secret/retrieve",
|
"path": "/api/secret/retrieve",
|
||||||
"method": "POST",
|
"method": "POST",
|
||||||
"description": "test retrieving the new secret",
|
"description": "test retrieving the new secret",
|
||||||
|
Reference in New Issue
Block a user