Ejemplo n.º 1
0
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.GET_STR, 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.GET_STR, 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)
}
Ejemplo n.º 2
0
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()
	}
}
Ejemplo n.º 3
0
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
}
Ejemplo n.º 4
0
func verifyLen(t *testing.T, url string, lenType string, length int) {
	code, _, _ := cr.HttpDataMethod(cr.GET_STR, url, "")

	curentLen := len(stRestful.UsersList.Users)
	if lenType == ResourcesPath {
		curentLen = len(stRestful.UsersList.Resources)
	}
	if code != http.StatusOK || curentLen != length {
		t.Errorf("Test fail: run GET '%v' Expected status: %v recived %v, expected length: %v, received: %v",
			url, http.StatusOK, code, length, curentLen)
	}
}
Ejemplo n.º 5
0
func addDataVerifyResults(t *testing.T, userName string, url string, okJ cr.Url) {
	exeCommandCheckRes(t, cr.PUT_STR, url, http.StatusCreated, url, okJ)

	code, sData, _ := cr.HttpDataMethod(cr.GET_STR, enPath, "")
	var resData en.EntityManager
	json.Unmarshal([]byte(sData), &resData)
	if code != http.StatusOK || reflect.DeepEqual(stRestful.UsersList, &resData) == false {
		t.Errorf("Test fail: run GET '%v' Expected status: %v received %v, expected data: '%v' received '%v'",
			enPath, http.StatusOK, code, stRestful.UsersList, resData)
		t.FailNow()
	}
}