// When the api/o endpoint is not available, the server should accquire a token
// through api/v2/users/<name>/personal_tokens
When the api/o endpoint is not available, the server should accquire a token
through api/v2/users//personal_tokens
// When the api / o endpoint is not available the server should accquire a token // through api / v2 / users / <name > / personal_tokens
func TestOAUTH2Token(t *testing.T) {
	connection, err := NewConnectionBuilder().
		URL("http://localhost:9100/api").
		Username("admin").
		Password("password").
		Build()
	if err != nil {
		t.Error(err)
	}
	defer connection.Close()
	vcr := govcr.NewVCR("connection_oauth2",
		&govcr.VCRConfig{
			Client:           connection.client,
			DisableRecording: true,
		})
	connection.client = vcr.Client
	projectsResource := connection.Projects()
	getProjectsRequest := projectsResource.Get()
	if len(connection.token) != 0 || len(connection.bearer) != 0 {
		t.Errorf("Connection should have no tokens. token: '%s', bearer: '%s'",
			connection.token,
			connection.bearer)
	}
	_, err = getProjectsRequest.Send()
	if err != nil {
		panic(err)
	}
	if len(connection.token) != 0 || len(connection.bearer) == 0 {
		t.Errorf("Connection should have only a bearer token. token: '%s', bearer: '%s'",
			connection.token,
			connection.bearer)
	}
}
func TestOAUTH2Token ( t * testing . T ) { connection , err := NewConnectionBuilder ( ) . URL ( " " ) . Username ( " " ) . Password ( " " ) . Build ( ) if err != nil { t . Error ( err ) } defer connection . Close ( ) vcr := govcr . NewVCR ( " " , & govcr . VCRConfig { Client : connection . client , DisableRecording : true , } ) connection . client = vcr . Client projectsResource := connection . Projects ( ) getProjectsRequest := projectsResource . Get ( ) if len ( connection . token ) != 0 || len ( connection . bearer ) != 0 { t . Errorf ( " " , connection . token , connection . bearer ) } _ , err = getProjectsRequest . Send ( ) if err != nil { panic ( err ) } if len ( connection . token ) != 0 || len ( connection . bearer ) == 0 { t . Errorf ( " " , connection . token , connection . bearer ) } }
When the api/o endpoint is not available, the server should accquire a token
through api/v2/users//personal_tokens
When the api / o endpoint is not available the server should accquire a token through api / v2 / users // personal_tokens
// Replace our HTTPClient with a vcr client wrapping it // Trigger the auth flow.