本文整理汇总了Golang中testhelpers.FakeUI类的典型用法代码示例。如果您正苦于以下问题:Golang FakeUI类的具体用法?Golang FakeUI怎么用?Golang FakeUI使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FakeUI类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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")
}
示例2: 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")
}
示例3: 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)
}
示例4: TestSpaceRequirement
func TestSpaceRequirement(t *testing.T) {
ui := new(testhelpers.FakeUI)
config := &configuration.Configuration{
Organization: cf.Organization{
Name: "my-org",
Guid: "my-org-guid",
},
Space: cf.Space{
Name: "my-space",
Guid: "my-space-guid",
},
}
req := NewTargetedSpaceRequirement(ui, config)
success := req.Execute()
assert.True(t, success)
config.Space = cf.Space{}
req = NewTargetedSpaceRequirement(ui, config)
success = req.Execute()
assert.False(t, success)
assert.Contains(t, ui.Outputs[0], "FAILED")
assert.Contains(t, ui.Outputs[1], "No space targeted")
ui.ClearOutputs()
config.Organization = cf.Organization{}
req = NewTargetedSpaceRequirement(ui, config)
success = req.Execute()
assert.False(t, success)
assert.Contains(t, ui.Outputs[0], "FAILED")
assert.Contains(t, ui.Outputs[1], "No org and space targeted")
}
示例5: 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)
}
示例6: 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)
}