func generateJSON(path string, distPath string) { var obj map[string]interface{} baseURL := fmt.Sprintf("%v://%v%v", *protocol, *host, path) fileFmt := "%v/%v" time.Sleep(100 * time.Millisecond) _, jsonD, _ := cr.HTTPDataMethod(cr.HTTPGetStr, baseURL, "") err := json.Unmarshal([]byte(jsonD), &obj) if err != nil { log.Fatal(err) } var prefix, p1, file string for i, v := range obj["apis"].([]interface{}) { casted := v.(map[string]interface{}) url1 := fmt.Sprintf("%v%v", baseURL, casted["path"]) _, u, _ := cr.HTTPDataMethod(cr.HTTPGetStr, url1, "") p1, file = filepath.Split(fmt.Sprintf("%v", casted["path"])) if i == 0 { prefix = strings.Replace(p1, "/", distPath, 1) err := os.MkdirAll(prefix, 0777) if err != nil { log.Fatalf("Fatal error while generating static JSON path: %v", err) } } ioutil.WriteFile(fmt.Sprintf(fileFmt, prefix, file), []byte(u), 0777) } _, file = filepath.Split(path) prefix1 := strings.Replace(p1, "/", "/../", 1) obj["apiVersion"] = "2.02" a := obj["info"].(map[string]interface{}) a["title"] = "Libsecurity API" j, _ := json.Marshal(obj) newS := strings.Replace(string(j), p1, prefix1, -1) ioutil.WriteFile(fmt.Sprintf(fileFmt, distPath, file), []byte(newS), 0777) }
func exeCommandCheckRes(t *testing.T, method string, url string, expCode int, data string, okJ interface{}) { code, sData, _ := cr.HTTPDataMethod(method, url, data) exp, res, e, err := getExpectedData(sData, okJ) if code != expCode || res != exp || err != nil { t.Errorf("Test fail: run %v '%v' Expected status: %v, received %v, expected data: '%v' received: '%v', error: %v %v", method, url, expCode, code, exp, res, e, err) t.FailNow() } }
func exeCommandCheckRes(t *testing.T, method string, url string, expCode int, data string, okJ interface{}) string { code, sData, err := cr.HTTPDataMethod(method, url, data) logger.Trace.Println("Method:", method, "Url:", url, "data:", data, "response code:", code, "response data:", sData, "error:", err) exp, res, e, err := getExpectedData(sData, okJ) if code != expCode || res != exp || err != nil { t.Errorf("Test fail: run %v '%v' Expected status: %v, received %v, expected data: '%v' received: '%v', error: %v %v", method, url, expCode, code, exp, res, e, err) t.FailNow() } return res }