本文整理汇总了Golang中github.com/Esri/geotrigger-go/geotrigger/test.Expect函数的典型用法代码示例。如果您正苦于以下问题:Golang Expect函数的具体用法?Golang Expect怎么用?Golang Expect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Expect函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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, ¶ms)
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
示例16: TestDeviceRecoveryFromErrorDuringRefreshWithRoutinesWaitingForAccess
func TestDeviceRecoveryFromErrorDuringRefreshWithRoutinesWaitingForAccess(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.
// The first routine will get an error while refreshing, which it will report.
// The token manager routine will then promote the next routine in line to continue
// with its actions, prompting another refresh which this time will succeed.
// That refresh will be communicated to the remaining routines waiting for a token,
// and they will go ahead and finish.
bt, gt := testConcurrentRefresh(t, getValidDeviceClient(t), "refresh_token", "", "good_refresh_token", true, true)
test.Expect(t, bt, 1)
test.Expect(t, gt, 3)
}
开发者ID:Esri,项目名称:geotrigger-go,代码行数:15,代码来源:device_test.go
示例17: TestDeviceConcurrentRefreshWaitingAtRefreshStep
func TestDeviceConcurrentRefreshWaitingAtRefreshStep(t *testing.T) {
// This will spawn 4 go routines making requests with bad tokens.
// Each routine will get permissions to present the access token to
// the geotrigger server.
// Whichever routine arrives first will receive the invalid token response will then ask for
// permission to refresh the token, and be granted that permission.
// The other 3 routines will also ask for permission to refresh, and instead
// end up waiting for a reply to that request.
// After the first routine successfully refreshes the token, the waiting
// routines will be give the message to continue, but not refresh, and
// instead use the new access token.
bt, gt := testConcurrentRefresh(t, getValidDeviceClient(t), "refresh_token", "", "good_refresh_token", false, false)
test.Expect(t, bt, 4)
test.Expect(t, gt, 4)
}
开发者ID:Esri,项目名称:geotrigger-go,代码行数:15,代码来源:device_test.go
示例18: TestDeviceRecoveryFromErrorDuringRefreshWithRoutinesWaitingForRefresh
func TestDeviceRecoveryFromErrorDuringRefreshWithRoutinesWaitingForRefresh(t *testing.T) {
// This will spawn 4 go routines making requests with bad tokens.
// Each routine will get permissions to present the access token to
// the geotrigger server.
// Whichever routine arrive first will receive the invalid token response will then ask for
// permission to refresh the token, and be granted that permission.
// The other 3 routines will also ask for permission to refresh, and instead
// end up waiting for a reply to that request.
// The first routine will get an error while refreshing, which it will report.
// The token manager routine will then promote the next routine in line to continue
// with its actions, prompting another refresh which this time will succeed.
// That refresh will be communicated to the remaining routines waiting for a token,
// and they will go ahead and finish.
bt, gt := testConcurrentRefresh(t, getValidDeviceClient(t), "refresh_token", "", "good_refresh_token", false, true)
test.Expect(t, bt, 4)
test.Expect(t, gt, 3)
}
开发者ID:Esri,项目名称:geotrigger-go,代码行数:17,代码来源:device_test.go
示例19: TestUnknownPurposeInt
func TestUnknownPurposeInt(t *testing.T) {
tm := newTokenManager("acc", "rfr", 1800)
tr := &tokenRequest{
purpose: 39846,
tokenResponses: make(chan *tokenResponse),
}
go tm.tokenRequest(tr)
tokenResp := <-tr.tokenResponses
test.Expect(t, tokenResp, nil)
}
开发者ID:Esri,项目名称:geotrigger-go,代码行数:12,代码来源:token_manager_test.go
示例20: TestDeviceRegisterFail
func TestDeviceRegisterFail(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/registerDevice")
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), 2)
test.Expect(t, vals.Get("client_id"), "bad_client_id")
test.Expect(t, vals.Get("f"), "json")
fmt.Fprintln(res, `{"error":{"code":999,"message":"Unable to register device.","details":["'client_id' invalid"]}}`)
}))
defer agoServer.Close()
device := &device{
clientID: "bad_client_id",
env: testEnv("", agoServer.URL),
}
expectedErrorMessage := "Error from /sharing/oauth2/registerDevice, code: 999. Message: Unable to register device."
err := device.register()
test.Refute(t, err, nil)
test.Expect(t, err.Error(), expectedErrorMessage)
}
开发者ID:Esri,项目名称:geotrigger-go,代码行数:26,代码来源:device_test.go
注:本文中的github.com/Esri/geotrigger-go/geotrigger/test.Expect函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论