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


Golang configuration.FakeConfigRepository類代碼示例

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


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

示例1: testSuccessfulAuthenticate

func testSuccessfulAuthenticate(t *testing.T, args []string) (ui *testterm.FakeUI) {
	configRepo := testconfig.FakeConfigRepository{}
	configRepo.Delete()
	config, _ := configRepo.Get()

	auth := &testapi.FakeAuthenticationRepository{
		AccessToken:  "my_access_token",
		RefreshToken: "my_refresh_token",
		ConfigRepo:   configRepo,
	}
	ui = callAuthenticate(
		args,
		configRepo,
		auth,
	)

	savedConfig := testconfig.SavedConfiguration

	assert.Contains(t, ui.Outputs[0], config.Target)
	assert.Contains(t, ui.Outputs[2], "OK")

	assert.Equal(t, savedConfig.AccessToken, "my_access_token")
	assert.Equal(t, savedConfig.RefreshToken, "my_refresh_token")
	assert.Equal(t, auth.Email, "[email protected]")
	assert.Equal(t, auth.Password, "password")

	return
}
開發者ID:jalateras,項目名稱:cli,代碼行數:28,代碼來源:authenticate_test.go

示例2: TestUpdateEndpointWhenEndpointReturnsInvalidJson

func TestUpdateEndpointWhenEndpointReturnsInvalidJson(t *testing.T) {
	configRepo := testconfig.FakeConfigRepository{}
	configRepo.Login()

	ts, repo := createEndpointRepoForUpdate(configRepo, invalidJsonResponseApiEndpoint)
	defer ts.Close()

	_, apiResponse := repo.UpdateEndpoint(ts.URL)

	assert.True(t, apiResponse.IsNotSuccessful())
}
開發者ID:pmuellr,項目名稱:cli,代碼行數:11,代碼來源:endpoints_test.go

示例3: TestUpdateEndpointWhenEndpointReturns404

func TestUpdateEndpointWhenEndpointReturns404(t *testing.T) {
	configRepo := testconfig.FakeConfigRepository{}
	configRepo.Login()

	ts, repo := createEndpointRepoForUpdate(configRepo, func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusNotFound)
	})

	defer ts.Close()

	_, apiResponse := repo.UpdateEndpoint(ts.URL)

	assert.True(t, apiResponse.IsNotSuccessful())
}
開發者ID:nsnt,項目名稱:cli,代碼行數:14,代碼來源:endpoints_test.go

示例4: setupAuthWithEndpoint

func setupAuthWithEndpoint(t *testing.T, request testnet.TestRequest) (ts *httptest.Server, handler *testnet.TestHandler, auth UAAAuthenticationRepository) {
	ts, handler = testnet.NewTLSServer(t, []testnet.TestRequest{request})

	configRepo := testconfig.FakeConfigRepository{}
	configRepo.Delete()
	config, err := configRepo.Get()
	assert.NoError(t, err)
	config.AuthorizationEndpoint = ts.URL
	config.AccessToken = ""

	gateway := net.NewUAAGateway()

	auth = NewUAAAuthenticationRepository(gateway, configRepo)
	return
}
開發者ID:nsnt,項目名稱:cli,代碼行數:15,代碼來源:authentication_test.go

示例5: createAuthenticationRepository

func createAuthenticationRepository(t *testing.T, apiServer *httptest.Server, authServer *httptest.Server) (*configuration.Configuration, api.AuthenticationRepository) {
	configRepo := testconfig.FakeConfigRepository{}
	configRepo.Delete()
	config, err := configRepo.Get()
	assert.NoError(t, err)

	config.AuthorizationEndpoint = authServer.URL
	config.Target = apiServer.URL
	config.AccessToken = "bearer initial-access-token"
	config.RefreshToken = "initial-refresh-token"

	authGateway := NewUAAGateway()
	authenticator := api.NewUAAAuthenticationRepository(authGateway, configRepo)

	return config, authenticator
}
開發者ID:nsnt,項目名稱:cli,代碼行數:16,代碼來源:gateway_test.go

示例6: TestUpdateEndpointWhenUrlIsAlreadyTargeted

func TestUpdateEndpointWhenUrlIsAlreadyTargeted(t *testing.T) {
	configRepo := testconfig.FakeConfigRepository{}
	configRepo.Delete()
	configRepo.Login()

	ts, repo := createEndpointRepoForUpdate(configRepo, validApiInfoEndpoint)
	defer ts.Close()

	org := cf.OrganizationFields{}
	org.Name = "my-org"
	org.Guid = "my-org-guid"

	space := cf.SpaceFields{}
	space.Name = "my-space"
	space.Guid = "my-space-guid"

	config, _ := configRepo.Get()
	config.Target = ts.URL
	config.AccessToken = "some access token"
	config.RefreshToken = "some refresh token"
	config.OrganizationFields = org
	config.SpaceFields = space

	repo.UpdateEndpoint(ts.URL)

	assert.Equal(t, config.OrganizationFields, org)
	assert.Equal(t, config.SpaceFields, space)
	assert.Equal(t, config.AccessToken, "some access token")
	assert.Equal(t, config.RefreshToken, "some refresh token")
}
開發者ID:pmuellr,項目名稱:cli,代碼行數:30,代碼來源:endpoints_test.go

示例7: TestUpdateEndpointWhenUrlIsValidHttpsInfoEndpoint

func TestUpdateEndpointWhenUrlIsValidHttpsInfoEndpoint(t *testing.T) {
	configRepo := testconfig.FakeConfigRepository{}
	configRepo.Delete()
	configRepo.Login()

	ts, repo := createEndpointRepoForUpdate(configRepo, validApiInfoEndpoint)
	defer ts.Close()
	org := cf.OrganizationFields{}
	org.Name = "my-org"
	org.Guid = "my-org-guid"

	space := cf.SpaceFields{}
	space.Name = "my-space"
	space.Guid = "my-space-guid"

	config, _ := configRepo.Get()
	config.OrganizationFields = org
	config.SpaceFields = space

	repo.UpdateEndpoint(ts.URL)

	savedConfig := testconfig.SavedConfiguration

	assert.Equal(t, savedConfig.AccessToken, "")
	assert.Equal(t, savedConfig.AuthorizationEndpoint, "https://login.example.com")
	assert.Equal(t, savedConfig.Target, ts.URL)
	assert.Equal(t, savedConfig.ApiVersion, "42.0.0")
	assert.False(t, savedConfig.HasOrganization())
	assert.False(t, savedConfig.HasSpace())
}
開發者ID:pmuellr,項目名稱:cli,代碼行數:30,代碼來源:endpoints_test.go

示例8: TestUnsuccessfullyAuthenticatingWithoutInteractivity

func TestUnsuccessfullyAuthenticatingWithoutInteractivity(t *testing.T) {
	configRepo := testconfig.FakeConfigRepository{}
	configRepo.Delete()
	config, _ := configRepo.Get()

	ui := callAuthenticate(
		[]string{
			"[email protected]",
			"bar",
		},
		configRepo,
		&testapi.FakeAuthenticationRepository{AuthError: true, ConfigRepo: configRepo},
	)

	assert.Contains(t, ui.Outputs[0], config.Target)
	assert.Equal(t, ui.Outputs[1], "Authenticating...")
	assert.Equal(t, ui.Outputs[2], "FAILED")
	assert.Contains(t, ui.Outputs[3], "Error authenticating")
	assert.Equal(t, len(ui.Outputs), 4)
}
開發者ID:jalateras,項目名稱:cli,代碼行數:20,代碼來源:authenticate_test.go

示例9: TestAuthenticateFailsWithUsage

func TestAuthenticateFailsWithUsage(t *testing.T) {
	configRepo := testconfig.FakeConfigRepository{}
	configRepo.Delete()

	auth := &testapi.FakeAuthenticationRepository{
		AccessToken:  "my_access_token",
		RefreshToken: "my_refresh_token",
		ConfigRepo:   configRepo,
	}

	ui := callAuthenticate([]string{}, configRepo, auth)
	assert.True(t, ui.FailedWithUsage)

	ui = callAuthenticate([]string{"my-username"}, configRepo, auth)
	assert.True(t, ui.FailedWithUsage)

	ui = callAuthenticate([]string{"my-username", "my-password"}, configRepo, auth)
	assert.False(t, ui.FailedWithUsage)

}
開發者ID:jalateras,項目名稱:cli,代碼行數:20,代碼來源:authenticate_test.go

示例10: TestUpdateEndpointWhenUrlIsMissingSchemeAndHttpsEndpointExists

func TestUpdateEndpointWhenUrlIsMissingSchemeAndHttpsEndpointExists(t *testing.T) {
	configRepo := testconfig.FakeConfigRepository{}
	configRepo.Delete()
	configRepo.Login()

	ts, repo := createEndpointRepoForUpdate(configRepo, validApiInfoEndpoint)
	defer ts.Close()

	schemelessURL := strings.Replace(ts.URL, "https://", "", 1)
	endpoint, apiResponse := repo.UpdateEndpoint(schemelessURL)
	assert.Equal(t, "https://"+schemelessURL, endpoint)

	assert.True(t, apiResponse.IsSuccessful())

	savedConfig := testconfig.SavedConfiguration

	assert.Equal(t, savedConfig.AccessToken, "")
	assert.Equal(t, savedConfig.AuthorizationEndpoint, "https://login.example.com")
	assert.Equal(t, savedConfig.Target, ts.URL)
	assert.Equal(t, savedConfig.ApiVersion, "42.0.0")
}
開發者ID:pmuellr,項目名稱:cli,代碼行數:21,代碼來源:endpoints_test.go

示例11: makeRepo

func makeRepo(configRepo testconfig.FakeConfigRepository) (repo EndpointRepository) {
	config, _ := configRepo.Get()
	gateway := net.NewCloudControllerGateway()
	return NewEndpointRepository(config, gateway, configRepo)
}
開發者ID:pmuellr,項目名稱:cli,代碼行數:5,代碼來源:endpoints_test.go


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