// *********************** Mock transcation Server ********************* //
func mockServerFor_getAccessToken(rcase int, ep string) *httptest.Server {
	handler := func(rsp http.ResponseWriter, req *http.Request) {
		if req.Method != "POST" {
			log.Fatalf("Expecting Request.Method POST, but got %v", req.Method)
		}
		switch rcase {
		case 1:
			fmt.Fprintf(rsp, `{ "code":1,
							"msg":"OK",
							"data":{"accesstoken":"a1a2a3a4a5a6a7a8",
							 		"remainingtime":"72h3m0.5s",
									"entrypoint":"%s"}
						 }`, ep)
		case 2:
			fmt.Fprintf(rsp, `{ "code":1,
							"msg":"OK",
							"data":{" ",
							 		"remainingtime":"72h3m0.5s",
									"entrypoint":"http://www.exaple.com:5678"}
						 }`)
		default:
		}

	}

	return httptest.NewServer(http.HandlerFunc(handler))
}
// *********************** Mock download Server ********************* //
func mockServerFor_download() *httptest.Server {
	handler := func(rsp http.ResponseWriter, req *http.Request) {
		if req.Method != "GET" {
			log.Fatalf("Expecting Request.Method GET, but got %v", req.Method)
		}
		rsp.WriteHeader(http.StatusBadGateway)
	}

	return httptest.NewServer(http.HandlerFunc(handler))
}
Exemple #3
0
// *********************** Mock ngix login ********************* //
func mockServerFor_loginNgix() *httptest.Server {
	handler := func(rsp http.ResponseWriter, req *http.Request) {
		if req.Method != "GET" {
			log.Fatalf("Expecting Request.Method GET, but got %v", req.Method)
		}

		fmt.Fprintf(rsp, `{"token":"3281f6af065790adc9e79eec4588d905="}`)
	}

	return httptest.NewServer(http.HandlerFunc(handler))
}
Exemple #4
0
// *********************** Mock commToServer ********************* //
func mockServerFor_commToServer() *httptest.Server {
	handler := func(rsp http.ResponseWriter, req *http.Request) {
		if req.Method != "GET" {
			log.Fatalf("Expecting Request.Method GET, but got %v", req.Method)
		}

		fmt.Fprintf(rsp, `Test_commToServer response test`)
	}

	return httptest.NewServer(http.HandlerFunc(handler))
}
func mockServerFor_DelItem() *httptest.Server {
	handler := func(rsp http.ResponseWriter, req *http.Request) {
		if req.Method != "GET" {
			log.Fatalf("Expecting Request.Method GET, but got %v", req.Method)
		}

		fmt.Fprintln(rsp, `{ 	"code":0,
					"msg":"OK"
				   }`)
	}

	return httptest.NewServer(http.HandlerFunc(handler))
}