當前位置: 首頁>>代碼示例>>Golang>>正文


Golang test.Expect函數代碼示例

本文整理匯總了Golang中github.com/Esri/geotrigger-go/geotrigger/test.Expect函數的典型用法代碼示例。如果您正苦於以下問題:Golang Expect函數的具體用法?Golang Expect怎麽用?Golang Expect使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Expect函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestSimpleTokenRequest

func TestSimpleTokenRequest(t *testing.T) {
	tm := newTokenManager("acc", "rfr", 1800)

	// access token req
	tr := &tokenRequest{
		purpose:        accessNeeded,
		tokenResponses: make(chan *tokenResponse),
	}
	go tm.tokenRequest(tr)

	tokenResp := <-tr.tokenResponses
	test.Refute(t, tokenResp, nil)
	test.Expect(t, tokenResp.isAccessToken, true)
	test.Expect(t, tokenResp.token, "acc")

	// refresh token req
	tr = &tokenRequest{
		purpose:        refreshNeeded,
		tokenResponses: make(chan *tokenResponse),
	}
	go tm.tokenRequest(tr)

	tokenResp = <-tr.tokenResponses
	test.Refute(t, tokenResp, nil)
	test.Expect(t, tokenResp.isAccessToken, false)
	test.Expect(t, tokenResp.token, "rfr")
}
開發者ID:Esri,項目名稱:geotrigger-go,代碼行數:27,代碼來源:token_manager_test.go

示例2: TestApplicationRegisterSuccess

func TestApplicationRegisterSuccess(t *testing.T) {
	client := getValidApplicationClient(t)
	sessionInfo := client.Info()
	test.Expect(t, sessionInfo["access_token"], "good_access_token")
	test.Expect(t, sessionInfo["client_id"], "good_client_id")
	test.Expect(t, sessionInfo["client_secret"], "good_client_secret")
}
開發者ID:Esri,項目名稱:geotrigger-go,代碼行數:7,代碼來源:application_test.go

示例3: TestDeviceRegisterSuccess

func TestDeviceRegisterSuccess(t *testing.T) {
	client := getValidDeviceClient(t)
	sessionInfo := client.Info()
	test.Expect(t, sessionInfo["access_token"], "good_access_token")
	test.Expect(t, sessionInfo["refresh_token"], "good_refresh_token")
	test.Expect(t, sessionInfo["device_id"], "device_id")
	test.Expect(t, sessionInfo["client_id"], "good_client_id")
}
開發者ID:Esri,項目名稱:geotrigger-go,代碼行數:8,代碼來源:device_test.go

示例4: TestDeviceConcurrentTokenExpirationWaitingAtRefreshStep

func TestDeviceConcurrentTokenExpirationWaitingAtRefreshStep(t *testing.T) {
	dc := getValidDeviceClient(t)
	dc.setExpiresAt(-100)

	bt, gt := testConcurrentRefresh(t, dc, "refresh_token", "", "good_refresh_token", false, false)
	test.Expect(t, bt, 0)
	test.Expect(t, gt, 4)
}
開發者ID:Esri,項目名稱:geotrigger-go,代碼行數:8,代碼來源:device_test.go

示例5: TestApplicationRecoveryFromErrorDuringTokenExpirationWaitingForRefresh

func TestApplicationRecoveryFromErrorDuringTokenExpirationWaitingForRefresh(t *testing.T) {
	ac := getValidApplicationClient(t)
	ac.setExpiresAt(-100)

	bt, gt := testConcurrentRefresh(t, ac, "client_credentials", "good_client_secret", "", false, true)
	test.Expect(t, bt, 0)
	test.Expect(t, gt, 3)
}
開發者ID:Esri,項目名稱:geotrigger-go,代碼行數:8,代碼來源:application_test.go

示例6: TestApplicationConcurrentTokenExpirationWaitingAtRefreshStep

func TestApplicationConcurrentTokenExpirationWaitingAtRefreshStep(t *testing.T) {
	ac := getValidApplicationClient(t)
	ac.setExpiresAt(-100)

	bt, gt := testConcurrentRefresh(t, ac, "client_credentials", "good_client_secret", "", false, false)
	test.Expect(t, bt, 0)
	test.Expect(t, gt, 4)
}
開發者ID:Esri,項目名稱:geotrigger-go,代碼行數:8,代碼來源:application_test.go

示例7: TestDeviceRecoveryFromErrorDuringTokenExpirationWaitingForRefresh

func TestDeviceRecoveryFromErrorDuringTokenExpirationWaitingForRefresh(t *testing.T) {
	dc := getValidDeviceClient(t)
	dc.setExpiresAt(-100)

	bt, gt := testConcurrentRefresh(t, dc, "refresh_token", "", "good_refresh_token", false, true)
	test.Expect(t, bt, 0)
	test.Expect(t, gt, 3)
}
開發者ID:Esri,項目名稱:geotrigger-go,代碼行數:8,代碼來源:device_test.go

示例8: TestNewTokenManager

func TestNewTokenManager(t *testing.T) {
	tm := newTokenManager("acc", "rfr", 1800)
	test.Refute(t, tm, nil)
	test.Expect(t, tm.getAccessToken(), "acc")
	test.Expect(t, tm.getRefreshToken(), "rfr")

	tm.setAccessToken("merp")
	test.Expect(t, tm.getAccessToken(), "merp")
}
開發者ID:Esri,項目名稱:geotrigger-go,代碼行數:9,代碼來源:token_manager_test.go

示例9: TestClientWithExistingDevice

func TestClientWithExistingDevice(t *testing.T) {
	// a test server to represent the geotrigger server
	gtServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, r *http.Request) {
		test.Refute(t, r, nil)
		test.Expect(t, r.URL.Path, "/some/route")
		test.Expect(t, r.Header.Get("Content-Type"), "application/json")
		test.Expect(t, r.Header.Get("X-GT-Client-Name"), "geotrigger-go")
		test.Expect(t, r.Header.Get("X-GT-Client-Version"), version)
		accessToken := r.Header.Get("Authorization")
		test.Expect(t, strings.Index(accessToken, "Bearer "), 0)
		accessToken = strings.Split(accessToken, " ")[1]
		test.Expect(t, accessToken, "good_access_token")
		contents, _ := ioutil.ReadAll(r.Body)
		test.Refute(t, len(contents), 0)
		var params map[string]interface{}
		_ = json.Unmarshal(contents, &params)
		test.Expect(t, len(params), 1)
		test.Expect(t, params["tags"], "derp")
		fmt.Fprintln(res, `{}`)
	}))
	defer gtServer.Close()

	client := ExistingDevice("good_client_id", "device_id", "good_access_token", 1800, "good_refresh_token")
	client.session.setEnv(testEnv(gtServer.URL, ""))

	params := map[string]interface{}{
		"tags": "derp",
	}
	var responseJSON map[string]interface{}

	err := client.Request("/some/route", params, &responseJSON)
	test.Expect(t, err, nil)
}
開發者ID:Esri,項目名稱:geotrigger-go,代碼行數:33,代碼來源:client_test.go

示例10: TestDeviceConcurrentRefreshWaitingAtAccessStep

func TestDeviceConcurrentRefreshWaitingAtAccessStep(t *testing.T) {
	// This will spawn 4 go routines making requests with bad tokens.
	// The first routine will fire away immediately, get the invalid token response
	// from the geotrigger server, ask for permission to refresh, and start refreshing the token.
	// After a delay, the other 3 routines will ask to use the access token,
	// and end up waiting because a refresh is in progress.
	// After the first routine successfully refreshes the token, the waiting
	// routines will be give the message to continue by using the new access token.
	bt, gt := testConcurrentRefresh(t, getValidDeviceClient(t), "refresh_token", "", "good_refresh_token", true, false)
	test.Expect(t, bt, 1)
	test.Expect(t, gt, 4)
}
開發者ID:Esri,項目名稱:geotrigger-go,代碼行數:12,代碼來源:device_test.go

示例11: TestErrorCheck

func TestErrorCheck(t *testing.T) {
	resp := []byte(`["array", "root", "element"]`)
	errResponse := errorCheck(resp)
	test.Expect(t, errResponse, nil)

	resp = []byte(`{"object":"doesnt match", "derp":["dorp", "morp"]}`)
	errResponse = errorCheck(resp)
	test.Expect(t, errResponse, nil)

	resp = []byte(`{"error":{"code":400,"message":"Invalid token."}}`)
	errResponse = errorCheck(resp)
	test.Refute(t, errResponse, nil)
}
開發者ID:Esri,項目名稱:geotrigger-go,代碼行數:13,代碼來源:session_test.go

示例12: TestClientWithNewApplication

func TestClientWithNewApplication(t *testing.T) {
	// a test server to represent AGO
	agoServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, r *http.Request) {
		test.Refute(t, r, nil)
		test.Expect(t, r.URL.Path, "/sharing/oauth2/token")
		test.Expect(t, r.Header.Get("Content-Type"), "application/x-www-form-urlencoded")
		contents, _ := ioutil.ReadAll(r.Body)
		test.Refute(t, len(contents), 0)
		vals, _ := url.ParseQuery(string(contents))
		test.Expect(t, len(vals), 4)
		test.Expect(t, vals.Get("client_id"), "good_client_id")
		test.Expect(t, vals.Get("f"), "json")
		test.Expect(t, vals.Get("grant_type"), "client_credentials")
		test.Expect(t, vals.Get("client_secret"), "good_client_secret")
		fmt.Fprintln(res, `{"access_token":"good_access_token","expires_in":7200}`)
	}))
	defer agoServer.Close()

	// set the ago url to the url of our test server so we aren't hitting prod
	agoURLRestorer, err := test.Patch(defEnv, *testEnv("", agoServer.URL))
	if err != nil {
		t.Error("Error during test setup: %s", err)
	}
	defer agoURLRestorer.Restore()

	client, err := NewApplication("good_client_id", "good_client_secret")
	test.Expect(t, err, nil)
	test.Refute(t, client, nil)
}
開發者ID:Esri,項目名稱:geotrigger-go,代碼行數:29,代碼來源:client_test.go

示例13: getValidApplicationClient

func getValidApplicationClient(t *testing.T) *Client {
	// a test server to represent AGO
	agoServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, r *http.Request) {
		test.Refute(t, r, nil)
		test.Expect(t, r.URL.Path, "/sharing/oauth2/token")
		test.Expect(t, r.Header.Get("Content-Type"), "application/x-www-form-urlencoded")
		contents, _ := ioutil.ReadAll(r.Body)
		test.Refute(t, len(contents), 0)
		vals, _ := url.ParseQuery(string(contents))
		test.Expect(t, len(vals), 4)
		test.Expect(t, vals.Get("client_id"), "good_client_id")
		test.Expect(t, vals.Get("f"), "json")
		test.Expect(t, vals.Get("grant_type"), "client_credentials")
		test.Expect(t, vals.Get("client_secret"), "good_client_secret")
		fmt.Fprintln(res, `{"access_token":"good_access_token","expires_in":7200}`)
	}))
	defer agoServer.Close()

	application := &application{
		clientID:     "good_client_id",
		clientSecret: "good_client_secret",
		env:          testEnv("", agoServer.URL),
	}
	err := application.requestAccess()
	test.Expect(t, err, nil)

	return &Client{application}
}
開發者ID:Esri,項目名稱:geotrigger-go,代碼行數:28,代碼來源:application_test.go

示例14: TestConcurrentTokenAccess

func TestConcurrentTokenAccess(t *testing.T) {
	tm := newTokenManager("acc", "rfr", 1800)

	tr1 := &tokenRequest{
		purpose:        accessNeeded,
		tokenResponses: make(chan *tokenResponse),
	}

	tr2 := &tokenRequest{
		purpose:        accessNeeded,
		tokenResponses: make(chan *tokenResponse),
	}

	tr3 := &tokenRequest{
		purpose:        accessNeeded,
		tokenResponses: make(chan *tokenResponse),
	}

	tr4 := &tokenRequest{
		purpose:        accessNeeded,
		tokenResponses: make(chan *tokenResponse),
	}

	go tm.tokenRequest(tr1)
	go tm.tokenRequest(tr2)
	go tm.tokenRequest(tr3)
	go tm.tokenRequest(tr4)

	var w sync.WaitGroup
	w.Add(4)
	go func() {
		tokenResp := <-tr1.tokenResponses
		test.Refute(t, tokenResp, nil)
		test.Expect(t, tokenResp.isAccessToken, true)
		test.Expect(t, tokenResp.token, "acc")
		w.Done()
	}()
	go func() {
		tokenResp := <-tr2.tokenResponses
		test.Refute(t, tokenResp, nil)
		test.Expect(t, tokenResp.isAccessToken, true)
		test.Expect(t, tokenResp.token, "acc")
		w.Done()
	}()
	go func() {
		tokenResp := <-tr3.tokenResponses
		test.Refute(t, tokenResp, nil)
		test.Expect(t, tokenResp.isAccessToken, true)
		test.Expect(t, tokenResp.token, "acc")
		w.Done()
	}()
	go func() {
		tokenResp := <-tr4.tokenResponses
		test.Refute(t, tokenResp, nil)
		test.Expect(t, tokenResp.isAccessToken, true)
		test.Expect(t, tokenResp.token, "acc")
		w.Done()
	}()
	w.Wait()
}
開發者ID:Esri,項目名稱:geotrigger-go,代碼行數:60,代碼來源:token_manager_test.go

示例15: TestApplicationAccessRequestFail

func TestApplicationAccessRequestFail(t *testing.T) {
	// a test server to represent AGO
	agoServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, r *http.Request) {
		test.Refute(t, r, nil)
		test.Expect(t, r.URL.Path, "/sharing/oauth2/token")
		test.Expect(t, r.Header.Get("Content-Type"), "application/x-www-form-urlencoded")
		contents, _ := ioutil.ReadAll(r.Body)
		test.Refute(t, len(contents), 0)
		vals, _ := url.ParseQuery(string(contents))
		test.Expect(t, len(vals), 4)
		test.Expect(t, vals.Get("client_id"), "bad_client_id")
		test.Expect(t, vals.Get("f"), "json")
		test.Expect(t, vals.Get("grant_type"), "client_credentials")
		test.Expect(t, vals.Get("client_secret"), "bad_client_secret")
		fmt.Fprintln(res, `{"error":{"code":999,"error":"invalid_request","error_description":"Invalid client_id","message":"invalid_request","details":[]}}`)
	}))
	defer agoServer.Close()

	application := &application{
		clientID:     "bad_client_id",
		clientSecret: "bad_client_secret",
		env:          testEnv("", agoServer.URL),
	}

	expectedErrorMessage := "Error from /sharing/oauth2/token, code: 999. Message: invalid_request"
	err := application.requestAccess()
	test.Refute(t, err, nil)
	test.Expect(t, err.Error(), expectedErrorMessage)
}
開發者ID:Esri,項目名稱:geotrigger-go,代碼行數:29,代碼來源:application_test.go


注:本文中的github.com/Esri/geotrigger-go/geotrigger/test.Expect函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。