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


Golang assert.NotNil函數代碼示例

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


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

示例1: TestNewUser

func TestNewUser(t *testing.T) {

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

	data := objx.MSI(
		soundcloudKeyID, "123435467890",
		soundcloudKeyName, "Mathew",
		soundcloudKeyNickname, "mathew_testington",
		soundcloudKeyAvatarUrl, "http://myface.com/")
	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, "Mathew", user.Name())
		assert.Equal(t, "mathew_testington", user.Nickname())
		assert.Equal(t, "http://myface.com/", user.AvatarURL())

		// 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,代碼行數:34,代碼來源:user_test.go

示例2: 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

示例3: 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

示例4: 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

示例5: TestUserInterface

func TestUserInterface(t *testing.T) {

	var user common.User = new(User)

	assert.NotNil(t, user)

}
開發者ID:chikin14niwa,項目名稱:gomniauth,代碼行數:7,代碼來源:user_test.go

示例6: 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

示例7: TestSoundcloudImplementsProvider

func TestSoundcloudImplementsProvider(t *testing.T) {

	var provider common.Provider
	provider = new(SoundcloudProvider)

	assert.NotNil(t, provider)

}
開發者ID:chikin14niwa,項目名稱:gomniauth,代碼行數:8,代碼來源:soundcloud_test.go

示例8: TestherokuImplementrsProvider

func TestherokuImplementrsProvider(t *testing.T) {

	var provider common.Provider
	provider = new(HerokuProvider)

	assert.NotNil(t, provider)

}
開發者ID:chikin14niwa,項目名稱:gomniauth,代碼行數:8,代碼來源:heroku_test.go

示例9: TestGitlabImplementrsProvider

func TestGitlabImplementrsProvider(t *testing.T) {

	var provider common.Provider
	provider = new(GitlabProvider)

	assert.NotNil(t, provider)

}
開發者ID:chikin14niwa,項目名稱:gomniauth,代碼行數:8,代碼來源:gitlab_test.go

示例10: TestGitHubImplementrsProvider

func TestGitHubImplementrsProvider(t *testing.T) {

	var provider common.Provider
	provider = new(SpotifyProvider)

	assert.NotNil(t, provider)

}
開發者ID:chikin14niwa,項目名稱:gomniauth,代碼行數:8,代碼來源:spotify_test.go

示例11: TestInterface

func TestInterface(t *testing.T) {

	var list common.ProviderList
	list = new(ProviderList)

	assert.NotNil(t, list)

}
開發者ID:chikin14niwa,項目名稱:gomniauth,代碼行數:8,代碼來源:provider_list_test.go

示例12: 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

示例13: 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

示例14: 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

示例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


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