本文整理匯總了Golang中testhelpers.FakeConfigRepository類的典型用法代碼示例。如果您正苦於以下問題:Golang FakeConfigRepository類的具體用法?Golang FakeConfigRepository怎麽用?Golang FakeConfigRepository使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了FakeConfigRepository類的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestUnsuccessfullyLoggingIn
func TestUnsuccessfullyLoggingIn(t *testing.T) {
configRepo := testhelpers.FakeConfigRepository{}
configRepo.Delete()
config, _ := configRepo.Get()
ui := new(testhelpers.FakeUI)
ui.Inputs = []string{
"[email protected]",
"bar",
"bar",
"bar",
"bar",
}
callLogin(
[]string{},
ui,
configRepo,
&testhelpers.FakeOrgRepository{},
&testhelpers.FakeSpaceRepository{},
&testhelpers.FakeAuthenticator{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.Equal(t, ui.Outputs[5], "Authenticating...")
assert.Equal(t, ui.Outputs[6], "FAILED")
assert.Equal(t, ui.Outputs[9], "Authenticating...")
assert.Equal(t, ui.Outputs[10], "FAILED")
}
示例2: TestSuccessfullyLoggingInWithUsernameAsArgument
func TestSuccessfullyLoggingInWithUsernameAsArgument(t *testing.T) {
configRepo := testhelpers.FakeConfigRepository{}
configRepo.Delete()
config, _ := configRepo.Get()
ui := new(testhelpers.FakeUI)
ui.Inputs = []string{"bar"}
auth := &testhelpers.FakeAuthenticator{
AccessToken: "my_access_token",
RefreshToken: "my_refresh_token",
ConfigRepo: configRepo,
}
callLogin(
[]string{"[email protected]"},
ui,
configRepo,
&testhelpers.FakeOrgRepository{},
&testhelpers.FakeSpaceRepository{},
auth,
)
savedConfig := testhelpers.SavedConfiguration
assert.Contains(t, ui.Outputs[0], config.Target)
assert.Contains(t, ui.Outputs[2], "OK")
assert.Contains(t, ui.Prompts[0], "Password")
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, "bar")
}
示例3: TestUnsuccessfullyLoggingInWithoutInteractivity
func TestUnsuccessfullyLoggingInWithoutInteractivity(t *testing.T) {
configRepo := testhelpers.FakeConfigRepository{}
configRepo.Delete()
config, _ := configRepo.Get()
ui := new(testhelpers.FakeUI)
callLogin(
[]string{
"[email protected]",
"bar",
},
ui,
configRepo,
&testhelpers.FakeOrgRepository{},
&testhelpers.FakeSpaceRepository{},
&testhelpers.FakeAuthenticator{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)
}
示例4: TestLoggingInWithOneOrgAndNoSpace
func TestLoggingInWithOneOrgAndNoSpace(t *testing.T) {
configRepo := testhelpers.FakeConfigRepository{}
configRepo.Delete()
config, _ := configRepo.Get()
ui := new(testhelpers.FakeUI)
ui.Inputs = []string{"[email protected]", "bar"}
orgs := []cf.Organization{
cf.Organization{"FirstOrg", "org-1-guid"},
}
spaces := []cf.Space{}
callLogin(
[]string{},
ui,
configRepo,
&testhelpers.FakeOrgRepository{Organizations: orgs},
&testhelpers.FakeSpaceRepository{Spaces: spaces},
&testhelpers.FakeAuthenticator{ConfigRepo: configRepo},
)
assert.Contains(t, ui.Outputs[0], config.Target)
assert.Contains(t, ui.Prompts[0], "Username")
assert.Contains(t, ui.Prompts[1], "Password")
assert.Contains(t, ui.Outputs[2], "OK")
assert.Contains(t, ui.Outputs[5], "API endpoint:")
assert.Contains(t, ui.Outputs[7], "FirstOrg")
assert.Contains(t, ui.Outputs[8], "No spaces found")
savedConfig := testhelpers.SavedConfiguration
assert.Equal(t, orgs[0], savedConfig.Organization)
assert.Equal(t, cf.Space{}, savedConfig.Space)
}
示例5: testSuccessfulLogin
func testSuccessfulLogin(t *testing.T, args []string, inputs []string) (ui *testhelpers.FakeUI) {
configRepo := testhelpers.FakeConfigRepository{}
configRepo.Delete()
config, _ := configRepo.Get()
ui = new(testhelpers.FakeUI)
ui.Inputs = inputs
auth := &testhelpers.FakeAuthenticator{
AccessToken: "my_access_token",
RefreshToken: "my_refresh_token",
ConfigRepo: configRepo,
}
callLogin(
args,
ui,
configRepo,
&testhelpers.FakeOrgRepository{},
&testhelpers.FakeSpaceRepository{},
auth,
)
savedConfig := testhelpers.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
}
示例6: TestRefreshingTheToken
func TestRefreshingTheToken(t *testing.T) {
ccServer := httptest.NewTLSServer(http.HandlerFunc(refreshTokenApiEndpoint))
defer ccServer.Close()
authServer := httptest.NewTLSServer(http.HandlerFunc(refreshTokenAuthEndpoint))
defer authServer.Close()
configRepo := testhelpers.FakeConfigRepository{}
configRepo.Delete()
config, err := configRepo.Get()
assert.NoError(t, err)
config.AuthorizationEndpoint = authServer.URL
config.Target = ccServer.URL
config.AccessToken = "bearer initial-access-token"
config.RefreshToken = "initial-refresh-token"
auth := NewUAAAuthenticator(configRepo)
client := NewApiClient(auth)
request, err := NewRequest("GET", config.Target+"/v2/foo", config.AccessToken, nil)
assert.NoError(t, err)
_, err = client.PerformRequest(request)
assert.NoError(t, err)
savedConfig := testhelpers.SavedConfiguration
assert.Equal(t, savedConfig.AccessToken, "bearer new-access-token")
assert.Equal(t, savedConfig.RefreshToken, "new-refresh-token")
}
示例7: createAuthenticator
func createAuthenticator(t *testing.T, apiServer *httptest.Server, authServer *httptest.Server) (configuration.ConfigurationRepository, api.Authenticator) {
configRepo := testhelpers.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 := NewUAAAuthGateway()
authenticator := api.NewUAAAuthenticator(authGateway, configRepo)
return configRepo, authenticator
}
示例8: TestLoggingInWithMultipleOrgsAndSpaces
func TestLoggingInWithMultipleOrgsAndSpaces(t *testing.T) {
configRepo := testhelpers.FakeConfigRepository{}
configRepo.Delete()
config, _ := configRepo.Get()
ui := new(testhelpers.FakeUI)
ui.Inputs = []string{"[email protected]", "bar", "2", "1"}
orgs := []cf.Organization{
cf.Organization{"FirstOrg", "org-1-guid"},
cf.Organization{"SecondOrg", "org-2-guid"},
}
spaces := []cf.Space{
cf.Space{Name: "FirstSpace", Guid: "space-1-guid"},
cf.Space{Name: "SecondSpace", Guid: "space-2-guid"},
}
callLogin(
[]string{},
ui,
configRepo,
&testhelpers.FakeOrgRepository{Organizations: orgs},
&testhelpers.FakeSpaceRepository{Spaces: spaces},
&testhelpers.FakeAuthenticator{ConfigRepo: configRepo},
)
assert.Contains(t, ui.Outputs[0], config.Target)
assert.Contains(t, ui.Prompts[0], "Username")
assert.Contains(t, ui.Prompts[1], "Password")
assert.Contains(t, ui.Outputs[2], "OK")
assert.Contains(t, ui.Outputs[3], "FirstOrg")
assert.Contains(t, ui.Outputs[4], "SecondOrg")
assert.Contains(t, ui.Prompts[2], "Organization")
assert.Contains(t, ui.Outputs[5], "SecondOrg")
assert.Contains(t, ui.Outputs[7], "FirstSpace")
assert.Contains(t, ui.Outputs[8], "SecondSpace")
assert.Contains(t, ui.Prompts[3], "Space")
assert.Contains(t, ui.Outputs[9], "FirstSpace")
savedConfig := testhelpers.SavedConfiguration
assert.Equal(t, orgs[1], savedConfig.Organization)
assert.Equal(t, spaces[0], savedConfig.Space)
}
示例9: TestServerErrorLoggingIn
func TestServerErrorLoggingIn(t *testing.T) {
ts := httptest.NewTLSServer(http.HandlerFunc(errorLoginEndpoint))
defer ts.Close()
configRepo := testhelpers.FakeConfigRepository{}
configRepo.Delete()
config, err := configRepo.Get()
assert.NoError(t, err)
config.AuthorizationEndpoint = ts.URL
config.AccessToken = ""
auth := NewUAAAuthenticator(configRepo)
err = auth.Authenticate("[email protected]", "bar")
assert.Error(t, err)
assert.Equal(t, err.Error(), "Server error, status code: 500, error code: 0, message: ")
savedConfig := testhelpers.SavedConfiguration
assert.Empty(t, savedConfig.AccessToken)
}
示例10: TestUnsuccessfullyLoggingIn
func TestUnsuccessfullyLoggingIn(t *testing.T) {
ts := httptest.NewTLSServer(http.HandlerFunc(unsuccessfulLoginEndpoint))
defer ts.Close()
configRepo := testhelpers.FakeConfigRepository{}
configRepo.Delete()
config, err := configRepo.Get()
assert.NoError(t, err)
config.AuthorizationEndpoint = ts.URL
config.AccessToken = ""
auth := NewUAAAuthenticator(configRepo)
err = auth.Authenticate("[email protected]", "oops wrong pass")
assert.Error(t, err)
assert.Equal(t, err.Error(), "Password in incorrect, please try again.")
savedConfig := testhelpers.SavedConfiguration
assert.Empty(t, savedConfig.AccessToken)
}
示例11: TestSuccessfullyLoggingIn
func TestSuccessfullyLoggingIn(t *testing.T) {
ts := httptest.NewTLSServer(http.HandlerFunc(successfulLoginEndpoint))
defer ts.Close()
configRepo := testhelpers.FakeConfigRepository{}
configRepo.Delete()
config, err := configRepo.Get()
assert.NoError(t, err)
config.AuthorizationEndpoint = ts.URL
config.AccessToken = ""
auth := NewUAAAuthenticator(configRepo)
err = auth.Authenticate("[email protected]", "bar")
savedConfig := testhelpers.SavedConfiguration
assert.Equal(t, savedConfig.AccessToken, "BEARER my_access_token")
assert.Equal(t, savedConfig.RefreshToken, "my_refresh_token")
}
示例12: TestWhenUserPicksInvalidOrgNumberAndSpaceNumber
func TestWhenUserPicksInvalidOrgNumberAndSpaceNumber(t *testing.T) {
configRepo := testhelpers.FakeConfigRepository{}
configRepo.Delete()
orgs := []cf.Organization{
cf.Organization{"Org1", "org-1-guid"},
cf.Organization{"Org2", "org-2-guid"},
}
spaces := []cf.Space{
cf.Space{Name: "FirstSpace", Guid: "space-1-guid"},
cf.Space{Name: "SecondSpace", Guid: "space-2-guid"},
}
ui := new(testhelpers.FakeUI)
ui.Inputs = []string{"[email protected]", "bar", "3", "2", "3", "1"}
callLogin(
[]string{},
ui,
configRepo,
&testhelpers.FakeOrgRepository{Organizations: orgs},
&testhelpers.FakeSpaceRepository{Spaces: spaces},
&testhelpers.FakeAuthenticator{ConfigRepo: configRepo},
)
assert.Contains(t, ui.Prompts[2], "Organization")
assert.Contains(t, ui.Outputs[5], "FAILED")
assert.Contains(t, ui.Prompts[3], "Organization")
assert.Contains(t, ui.Outputs[9], "Targeting org")
assert.Contains(t, ui.Prompts[4], "Space")
assert.Contains(t, ui.Outputs[13], "FAILED")
assert.Contains(t, ui.Prompts[5], "Space")
assert.Contains(t, ui.Outputs[17], "Targeting space")
savedConfig := testhelpers.SavedConfiguration
assert.Equal(t, orgs[1], savedConfig.Organization)
assert.Equal(t, spaces[0], savedConfig.Space)
}