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


Golang FakeUI.Inputs方法代碼示例

本文整理匯總了Golang中testhelpers.FakeUI.Inputs方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeUI.Inputs方法的具體用法?Golang FakeUI.Inputs怎麽用?Golang FakeUI.Inputs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在testhelpers.FakeUI的用法示例。


在下文中一共展示了FakeUI.Inputs方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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")
}
開發者ID:KaiYoung,項目名稱:cli,代碼行數:32,代碼來源:login_test.go

示例2: 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)
}
開發者ID:KaiYoung,項目名稱:cli,代碼行數:35,代碼來源:login_test.go

示例3: 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")
}
開發者ID:KaiYoung,項目名稱:cli,代碼行數:31,代碼來源:login_test.go

示例4: 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)
}
開發者ID:KaiYoung,項目名稱:cli,代碼行數:47,代碼來源:login_test.go

示例5: 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)
}
開發者ID:KaiYoung,項目名稱:cli,代碼行數:42,代碼來源:login_test.go


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