• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang assert.Equal函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/chikin14niwa/testify/assert.Equal函数的典型用法代码示例。如果您正苦于以下问题:Golang Equal函数的具体用法?Golang Equal怎么用?Golang Equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Equal函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestNewUser

func TestNewUser(t *testing.T) {

	testProvider := new(test.TestProvider)
	testProvider.On("Name").Return("providerName")

	data := objx.MSI(
		herokuKeyID, "123435467890",
		herokuKeyEmail, "[email protected]")
	creds := &common.Credentials{Map: objx.MSI(oauth2.OAuth2KeyAccessToken, "ABC123")}

	user := NewUser(data, creds, testProvider)

	if assert.NotNil(t, user) {

		assert.Equal(t, data, user.Data())

		assert.Equal(t, "[email protected]", user.Email())

		// check provider credentials
		creds := user.ProviderCredentials()[testProvider.Name()]
		if assert.NotNil(t, creds) {
			assert.Equal(t, "ABC123", creds.Get(oauth2.OAuth2KeyAccessToken).Str())
			assert.Equal(t, "123435467890", creds.Get(common.CredentialsKeyID).Str())
		}

	}

	mock.AssertExpectationsForObjects(t, testProvider.Mock)

}
开发者ID:chikin14niwa,项目名称:gomniauth,代码行数:30,代码来源:user_test.go


示例2: TestNewOAuth2Tripper

func TestNewOAuth2Tripper(t *testing.T) {

	testProvider := new(test.TestProvider)
	creds := &common.Credentials{Map: objx.MSI()}
	var tripper common.Tripper = NewOAuth2Tripper(creds, testProvider)

	if assert.NotNil(t, tripper) {
		assert.Equal(t, creds, tripper.Credentials())
		assert.Equal(t, http.DefaultTransport, tripper.(*OAuth2Tripper).underlyingTransport)
		assert.Equal(t, testProvider, tripper.Provider())
	}

}
开发者ID:chikin14niwa,项目名称:gomniauth,代码行数:13,代码来源:oauth2_tripper_test.go


示例3: TestIDForProvider

func TestIDForProvider(t *testing.T) {

	user := new(User)
	user.data = objx.MSI(
		common.UserKeyProviderCredentials,
		map[string]*common.Credentials{
			"github": &common.Credentials{Map: objx.MSI(common.CredentialsKeyID, "githubid")},
			"google": &common.Credentials{Map: objx.MSI(common.CredentialsKeyID, "googleid")}})

	assert.Equal(t, "githubid", user.IDForProvider("github"))
	assert.Equal(t, "googleid", user.IDForProvider("google"))

}
开发者ID:chikin14niwa,项目名称:gomniauth,代码行数:13,代码来源:user_test.go


示例4: TestProviders

func TestProviders(t *testing.T) {

	prov1 := new(test.TestProvider)
	prov2 := new(test.TestProvider)

	list := WithProviders(prov1, prov2)

	if assert.Equal(t, 2, len(list.Providers())) {
		assert.Equal(t, prov1, list.Providers()[0])
		assert.Equal(t, prov2, list.Providers()[1])
	}

}
开发者ID:chikin14niwa,项目名称:gomniauth,代码行数:13,代码来源:provider_list_test.go


示例5: TestProviderPublicData

func TestProviderPublicData(t *testing.T) {

	provider := new(test.TestProvider)

	provider.On("Name").Return("TestName")
	provider.On("DisplayName").Return("TestDisplayName")

	publicData, _ := ProviderPublicData(provider, objx.MSI("loginpathFormat", "~auth/%s/login"))
	publicDataMap := publicData.(map[string]interface{})

	assert.Equal(t, publicDataMap["name"], "TestName")
	assert.Equal(t, publicDataMap["display"], "TestDisplayName")
	assert.Equal(t, publicDataMap["loginpath"], "~auth/TestName/login")

}
开发者ID:chikin14niwa,项目名称:gomniauth,代码行数:15,代码来源:facade_test.go


示例6: TestProviderListProvider

func TestProviderListProvider(t *testing.T) {

	prov1 := new(test.TestProvider)
	prov2 := new(test.TestProvider)

	prov1.On("Name").Return("prov1")
	prov2.On("Name").Return("prov2")

	// build a list
	list := WithProviders(prov1, prov2)

	returnedProv, err := list.Provider("prov1")

	if assert.NoError(t, err) {
		assert.Equal(t, returnedProv, prov1)
	}

	// check nonsense name
	returnedProv, err = list.Provider("no such provider")

	if assert.Nil(t, returnedProv) {
		assert.IsType(t, &common.MissingProviderError{}, err, "MissingProviderError expected")
	}

	mock.AssertExpectationsForObjects(t, prov1.Mock, prov2.Mock)

}
开发者ID:chikin14niwa,项目名称:gomniauth,代码行数:27,代码来源:provider_list_test.go


示例7: TestRoundTrip

func TestRoundTrip(t *testing.T) {

	underlyingTripper := new(testifyhttp.TestRoundTripper)
	testProvider := new(test.TestProvider)
	creds := &common.Credentials{Map: objx.MSI()}
	creds.Set(OAuth2KeyAccessToken, "This is a real access token :)")

	tripper := new(OAuth2Tripper)
	tripper.underlyingTransport = underlyingTripper
	tripper.credentials = creds
	tripper.provider = testProvider

	request, _ := http.NewRequest("GET", "something", nil)

	underlyingTripper.On("RoundTrip", mock.Anything).Return(new(http.Response), nil)

	response, err := tripper.RoundTrip(request)

	if assert.NoError(t, err) {
		if assert.NotNil(t, response) {

			actualRequest := underlyingTripper.Calls[0].Arguments[0].(*http.Request)

			if assert.NotEqual(t, &actualRequest, &request, "Actual request should be different") {
				headerK, headerV := AuthorizationHeader(creds)
				assert.Equal(t, actualRequest.Header.Get(headerK), headerV)
			}

		}
	}

	mock.AssertExpectationsForObjects(t, testProvider.Mock, underlyingTripper.Mock)

}
开发者ID:chikin14niwa,项目名称:gomniauth,代码行数:34,代码来源:oauth2_tripper_test.go


示例8: TestAdd

func TestAdd(t *testing.T) {

	prov1 := new(test.TestProvider)
	prov2 := new(test.TestProvider)
	prov3 := new(test.TestProvider)

	// build a list
	list := WithProviders(prov1, prov2)

	if assert.Equal(t, 2, len(list.providers)) {

		// add prov3
		assert.Equal(t, list, list.Add(prov3), "Add should chain")
		assert.Equal(t, 3, len(list.providers), "Add should add the provider")
		assert.Equal(t, prov3, list.providers[2])

	}

}
开发者ID:chikin14niwa,项目名称:gomniauth,代码行数:19,代码来源:provider_list_test.go


示例9: TestOAuth2Provider_CompleteAuth_JSON

func TestOAuth2Provider_CompleteAuth_JSON(t *testing.T) {

	config := &common.Config{
		Map: objx.MSI(
			OAuth2KeyRedirectUrl, OAuth2KeyRedirectUrl,
			OAuth2KeyScope, OAuth2KeyScope,
			OAuth2KeyClientID, OAuth2KeyClientID,
			OAuth2KeySecret, OAuth2KeySecret,
			OAuth2KeyAuthURL, OAuth2KeyAuthURL,
			OAuth2KeyTokenURL, OAuth2KeyTokenURL)}

	testTripperFactory := new(test.TestTripperFactory)
	testTripper := new(test.TestTripper)
	testProvider := new(test.TestProvider)

	creds := new(common.Credentials)

	testResponse := new(http.Response)
	testResponse.Header = make(http.Header)
	testResponse.Header.Set("Content-Type", "application/json")
	testResponse.StatusCode = 200
	testResponse.Body = ioutil.NopCloser(strings.NewReader(`{"expires_in":20,"access_token":"ACCESSTOKEN","refresh_token":"REFRESHTOKEN"}`))

	testTripperFactory.On("NewTripper", common.EmptyCredentials, mock.Anything).Return(testTripper, nil)
	testTripper.On("RoundTrip", mock.Anything).Return(testResponse, nil)

	data := objx.MSI(OAuth2KeyCode, []string{"123"})
	creds, err := CompleteAuth(testTripperFactory, data, config, testProvider)

	if assert.NoError(t, err) {
		if assert.NotNil(t, creds, "Creds should be returned") {

			assert.Equal(t, creds.Get(OAuth2KeyAccessToken).Str(), "ACCESSTOKEN")
			assert.Equal(t, creds.Get(OAuth2KeyRefreshToken).Str(), "REFRESHTOKEN")
			assert.Equal(t, creds.Get(OAuth2KeyExpiresIn).Data().(time.Duration), time.Duration(20)*time.Second)

		}
	}

	mock.AssertExpectationsForObjects(t, testTripperFactory.Mock, testTripper.Mock, testProvider.Mock)

}
开发者ID:chikin14niwa,项目名称:gomniauth,代码行数:42,代码来源:complete_auth_test.go


示例10: TestspotifyTripperFactory

func TestspotifyTripperFactory(t *testing.T) {

	g := New("clientID", "secret", "http://myapp.com/")
	g.tripperFactory = nil

	f := g.TripperFactory()

	if assert.NotNil(t, f) {
		assert.Equal(t, f, g.tripperFactory)
	}

}
开发者ID:chikin14niwa,项目名称:gomniauth,代码行数:12,代码来源:spotify_test.go


示例11: TestGetUser

func TestGetUser(t *testing.T) {

	g := New("clientID", "secret", "http://myapp.com/")
	creds := &common.Credentials{Map: objx.MSI()}

	testTripperFactory := new(test.TestTripperFactory)
	testTripper := new(test.TestTripper)
	testTripperFactory.On("NewTripper", mock.Anything, g).Return(testTripper, nil)
	testResponse := new(http.Response)
	testResponse.Header = make(http.Header)
	testResponse.Header.Set("Content-Type", "application/json")
	testResponse.StatusCode = 200
	testResponse.Body = ioutil.NopCloser(strings.NewReader(`{"full_name":"their-name","id":"uniqueid","username":"loginname","avatar_url":"http://myface.com/","online":true}`))
	testTripper.On("RoundTrip", mock.Anything).Return(testResponse, nil)

	g.tripperFactory = testTripperFactory

	user, err := g.GetUser(creds)

	if assert.NoError(t, err) && assert.NotNil(t, user) {
		assert.Equal(t, user.Name(), "their-name")
		assert.Equal(t, user.AuthCode(), "")
		assert.Equal(t, user.Nickname(), "loginname")
		assert.Equal(t, user.Email(), "") // doesn't come from soundcloud
		assert.Equal(t, user.AvatarURL(), "http://myface.com/")
		assert.Equal(t, user.Data()["online"], true)
	}

}
开发者ID:chikin14niwa,项目名称:gomniauth,代码行数:29,代码来源:soundcloud_test.go


示例12: TestGetUser

func TestGetUser(t *testing.T) {

	testProvider := new(test.TestProvider)
	creds := new(common.Credentials)

	testTripperFactory := new(test.TestTripperFactory)
	testTripper := new(test.TestTripper)
	testTripperFactory.On("NewTripper", creds, testProvider).Return(testTripper, nil)
	testResponse := new(http.Response)
	testResponse.Header = make(http.Header)
	testResponse.Header.Set("Content-Type", "application/json")
	testResponse.StatusCode = 200
	testResponse.Body = ioutil.NopCloser(strings.NewReader(`{"name":"their-name","id":"uniqueid","login":"loginname","email":"[email protected]","avatar_url":"http://myface.com/","blog":"http://blog.com/"}`))
	testTripper.On("RoundTrip", mock.Anything).Return(testResponse, nil)

	client := &http.Client{Transport: testTripper}
	testProvider.On("GetClient", creds).Return(client, nil)

	data, err := Get(testProvider, creds, "endpoint")

	if assert.NoError(t, err) && assert.NotNil(t, data) {

		assert.Equal(t, data["name"], "their-name")
		assert.Equal(t, data["id"], "uniqueid")
		assert.Equal(t, data["login"], "loginname")
		assert.Equal(t, data["email"], "[email protected]")
		assert.Equal(t, data["avatar_url"], "http://myface.com/")
		assert.Equal(t, data["blog"], "http://blog.com/")

	}

}
开发者ID:chikin14niwa,项目名称:gomniauth,代码行数:32,代码来源:get_test.go


示例13: TestWithProviders

func TestWithProviders(t *testing.T) {

	common.SetSecurityKey("ABC123")

	prov1 := new(test.TestProvider)
	prov2 := new(test.TestProvider)

	list := WithProviders(prov1, prov2)

	if assert.NotNil(t, list) {

		if assert.Equal(t, 2, len(list.providers)) {
			assert.Equal(t, prov1, list.providers[0])
			assert.Equal(t, prov2, list.providers[1])
		}

		// make sure the SharedProviderList was assigned too
		assert.Equal(t, SharedProviderList, list)

	}

}
开发者ID:chikin14niwa,项目名称:gomniauth,代码行数:22,代码来源:provider_list_test.go


示例14: TestGetUser

func TestGetUser(t *testing.T) {

	g := New("clientID", "secret", "http://myapp.com/")
	creds := &common.Credentials{Map: objx.MSI()}

	testTripperFactory := new(test.TestTripperFactory)
	testTripper := new(test.TestTripper)
	testTripperFactory.On("NewTripper", mock.Anything, g).Return(testTripper, nil)
	testResponse := new(http.Response)
	testResponse.Header = make(http.Header)
	testResponse.Header.Set("Content-Type", "application/json")
	testResponse.StatusCode = 200
	testResponse.Body = ioutil.NopCloser(strings.NewReader(`{
  "display_name":"JMWizzler",
  "email":"[email protected]",
  "external_urls":{
    "spotify":"https://open.spotify.com/user/wizzler"
  },
  "href":"https://api.spotify.com/v1/users/wizzler",
  "id":"wizzler",
  "images":[{
    "height":null,
    "url":"https://fbcdn.example.com/2330_n.jpg",
    "width":null
  }],
  "type":"user",
  "uri":"spotify:user:wizzler"
}`))
	testTripper.On("RoundTrip", mock.Anything).Return(testResponse, nil)

	g.tripperFactory = testTripperFactory

	user, err := g.GetUser(creds)

	if assert.NoError(t, err) && assert.NotNil(t, user) {

		assert.Equal(t, user.Name(), "JMWizzler")
		assert.Equal(t, user.AuthCode(), "") // doesn't come from spotify
		assert.Equal(t, user.Nickname(), "") // doesn't come from spotify
		assert.Equal(t, user.Email(), "[email protected]")
		assert.Equal(t, user.AvatarURL(), "https://fbcdn.example.com/2330_n.jpg")
		assert.Equal(t, user.Data()["href"], "https://api.spotify.com/v1/users/wizzler")

		spotifyCreds := user.ProviderCredentials()[spotifyName]
		if assert.NotNil(t, spotifyCreds) {
			assert.Equal(t, "wizzler", spotifyCreds.Get(common.CredentialsKeyID).Str())
		}

	}

}
开发者ID:chikin14niwa,项目名称:gomniauth,代码行数:51,代码来源:spotify_test.go


示例15: TestGetUser

func TestGetUser(t *testing.T) {

	g := New("clientID", "secret", "http://myapp.com/")
	creds := &common.Credentials{Map: objx.MSI()}

	testTripperFactory := new(test.TestTripperFactory)
	testTripper := new(test.TestTripper)
	testTripperFactory.On("NewTripper", mock.Anything, g).Return(testTripper, nil)
	testResponse := new(http.Response)
	testResponse.Header = make(http.Header)
	testResponse.Header.Set("Content-Type", "application/json")
	testResponse.StatusCode = 200
	testResponse.Body = ioutil.NopCloser(strings.NewReader(`{"name":"their-name","id":"uniqueid","login":"loginname","email":"[email protected]","avatar_url":"http://myface.com/","blog":"http://blog.com/"}`))
	testTripper.On("RoundTrip", mock.Anything).Return(testResponse, nil)

	g.tripperFactory = testTripperFactory

	user, err := g.GetUser(creds)

	if assert.NoError(t, err) && assert.NotNil(t, user) {

		assert.Equal(t, user.Name(), "their-name")
		assert.Equal(t, user.AuthCode(), "") // doesn't come from github
		assert.Equal(t, user.Nickname(), "loginname")
		assert.Equal(t, user.Email(), "[email protected]")
		assert.Equal(t, user.AvatarURL(), "http://myface.com/")
		assert.Equal(t, user.Data()["blog"], "http://blog.com/")

		gitlabCreds := user.ProviderCredentials()[gitlabName]
		if assert.NotNil(t, gitlabCreds) {
			assert.Equal(t, "uniqueid", gitlabCreds.Get(common.CredentialsKeyID).Str())
		}

	}

}
开发者ID:chikin14niwa,项目名称:gomniauth,代码行数:36,代码来源:gitlab_test.go


示例16: TestNewspotify

func TestNewspotify(t *testing.T) {

	g := New("clientID", "secret", "http://myapp.com/")

	if assert.NotNil(t, g) {

		// check config
		if assert.NotNil(t, g.config) {

			assert.Equal(t, "clientID", g.config.Get(oauth2.OAuth2KeyClientID).Data())
			assert.Equal(t, "secret", g.config.Get(oauth2.OAuth2KeySecret).Data())
			assert.Equal(t, "http://myapp.com/", g.config.Get(oauth2.OAuth2KeyRedirectUrl).Data())
			assert.Equal(t, spotifyDefaultScope, g.config.Get(oauth2.OAuth2KeyScope).Data())

			assert.Equal(t, spotifyAuthURL, g.config.Get(oauth2.OAuth2KeyAuthURL).Data())
			assert.Equal(t, spotifyTokenURL, g.config.Get(oauth2.OAuth2KeyTokenURL).Data())

		}

	}

}
开发者ID:chikin14niwa,项目名称:gomniauth,代码行数:22,代码来源:spotify_test.go


示例17: TestspotifyName

func TestspotifyName(t *testing.T) {
	g := New("clientID", "secret", "http://myapp.com/")
	assert.Equal(t, spotifyName, g.Name())
}
开发者ID:chikin14niwa,项目名称:gomniauth,代码行数:4,代码来源:spotify_test.go


示例18: TestSoundcloudName

func TestSoundcloudName(t *testing.T) {
	g := New("clientID", "secret", "http://myapp.com/")
	assert.Equal(t, soundcloudName, g.Name())
}
开发者ID:chikin14niwa,项目名称:gomniauth,代码行数:4,代码来源:soundcloud_test.go


示例19: TestGithubName

func TestGithubName(t *testing.T) {
	g := New("clientID", "secret", "http://myapp.com/")
	assert.Equal(t, gitlabName, g.Name())
}
开发者ID:chikin14niwa,项目名称:gomniauth,代码行数:4,代码来源:gitlab_test.go



注:本文中的github.com/chikin14niwa/testify/assert.Equal函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang assert.NotNil函数代码示例发布时间:2022-05-23
下一篇:
Golang test.TestTripperFactory类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap