コード例 #1
0
// *********************** 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))
}
コード例 #2
0
// *********************** 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))
}
コード例 #3
0
ファイル: handler_test.go プロジェクト: asiainfoLDP/datahub
// *********************** 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))
}
コード例 #4
0
ファイル: handler_test.go プロジェクト: asiainfoLDP/datahub
// *********************** 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))
}
コード例 #5
0
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))
}