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


Golang models.UserFields類代碼示例

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


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

示例1: deleteWithConfirmation

func deleteWithConfirmation(confirmation string) (ui *testterm.FakeUI, userRepo *testapi.FakeUserRepository) {
	ui = &testterm.FakeUI{
		Inputs: []string{confirmation},
	}
	user2 := models.UserFields{}
	user2.Username = "my-found-user"
	user2.Guid = "my-found-user-guid"
	userRepo = &testapi.FakeUserRepository{
		FindByUsernameUserFields: user2,
	}

	configRepo := testconfig.NewRepositoryWithDefaults()
	accessToken, err := testconfig.EncodeAccessToken(configuration.TokenInfo{
		Username: "current-user",
	})
	Expect(err).NotTo(HaveOccurred())
	configRepo.SetAccessToken(accessToken)

	cmd := NewDeleteUser(ui, configRepo, userRepo)

	ctxt := testcmd.NewContext("delete-user", []string{"my-user"})
	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true}

	testcmd.RunCommand(cmd, ctxt, reqFactory)
	return
}
開發者ID:knolleary,項目名稱:cli,代碼行數:26,代碼來源:delete_user_test.go

示例2:

		args := []string{"username", "org", "space", "role"}

		requirementsFactory.LoginSuccess = false
		callUnsetSpaceRole(args, spaceRepo, userRepo, requirementsFactory)
		Expect(testcmd.CommandDidPassRequirements).To(BeFalse())

		requirementsFactory.LoginSuccess = true
		callUnsetSpaceRole(args, spaceRepo, userRepo, requirementsFactory)
		Expect(testcmd.CommandDidPassRequirements).To(BeTrue())

		Expect(requirementsFactory.UserUsername).To(Equal("username"))
		Expect(requirementsFactory.OrganizationName).To(Equal("org"))
	})

	It("TestUnsetSpaceRole", func() {
		user := models.UserFields{}
		user.Username = "some-user"
		user.Guid = "some-user-guid"
		org := models.Organization{}
		org.Name = "some-org"
		org.Guid = "some-org-guid"

		requirementsFactory, spaceRepo, userRepo := getUnsetSpaceRoleDeps()
		requirementsFactory.LoginSuccess = true
		requirementsFactory.UserFields = user
		requirementsFactory.Organization = org
		spaceRepo.FindByNameInOrgSpace = models.Space{}
		spaceRepo.FindByNameInOrgSpace.Name = "some-space"
		spaceRepo.FindByNameInOrgSpace.Guid = "some-space-guid"

		args := []string{"my-username", "my-org", "my-space", "SpaceManager"}
開發者ID:nota-ja,項目名稱:cli,代碼行數:31,代碼來源:unset_space_role_test.go

示例3:

package requirements_test

import (
	"cf/models"
	. "cf/requirements"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	testapi "testhelpers/api"
	testassert "testhelpers/assert"
	testterm "testhelpers/terminal"
)

var _ = Describe("Testing with ginkgo", func() {
	It("TestUserReqExecute", func() {
		user := models.UserFields{}
		user.Username = "my-user"
		user.Guid = "my-user-guid"

		userRepo := &testapi.FakeUserRepository{FindByUsernameUserFields: user}
		ui := new(testterm.FakeUI)

		userReq := NewUserRequirement("foo", ui, userRepo)
		success := userReq.Execute()

		Expect(success).To(BeTrue())
		Expect(userRepo.FindByUsernameUsername).To(Equal("foo"))
		Expect(userReq.GetUser()).To(Equal(user))
	})

	It("TestUserReqWhenUserDoesNotExist", func() {
		userRepo := &testapi.FakeUserRepository{FindByUsernameNotFound: true}
開發者ID:normalnorman,項目名稱:cli,代碼行數:31,代碼來源:user_test.go

示例4:

		Expect(testcmd.CommandDidPassRequirements).To(BeFalse())

		requirementsFactory.LoginSuccess = true
		callOrgUsers(args, requirementsFactory, userRepo)
		Expect(testcmd.CommandDidPassRequirements).To(BeTrue())

		Expect("Org1").To(Equal(requirementsFactory.OrganizationName))
	})

	It("TestOrgUsers", func() {
		org := models.Organization{}
		org.Name = "Found Org"
		org.Guid = "found-org-guid"

		userRepo := &testapi.FakeUserRepository{}
		user := models.UserFields{}
		user.Username = "user1"
		user2 := models.UserFields{}
		user2.Username = "user2"
		user3 := models.UserFields{}
		user3.Username = "user3"
		user4 := models.UserFields{}
		user4.Username = "user4"
		userRepo.ListUsersByRole = map[string][]models.UserFields{
			models.ORG_MANAGER:     []models.UserFields{user, user2},
			models.BILLING_MANAGER: []models.UserFields{user4},
			models.ORG_AUDITOR:     []models.UserFields{user3},
		}

		requirementsFactory := &testreq.FakeReqFactory{
			LoginSuccess: true,
開發者ID:nota-ja,項目名稱:cli,代碼行數:31,代碼來源:org_users_test.go

示例5:

		Expect(userRepo.FindByUsernameUsername).To(Equal("my-user"))
		Expect(userRepo.DeleteUserGuid).To(Equal("my-found-user-guid"))
	})

	It("TestDeleteUserWhenNotConfirming", func() {
		ui, userRepo := deleteWithConfirmation("Nope")

		Expect(len(ui.Outputs)).To(Equal(0))
		testassert.SliceContains(ui.Prompts, testassert.Lines{{"Really delete"}})

		Expect(userRepo.FindByUsernameUsername).To(Equal(""))
		Expect(userRepo.DeleteUserGuid).To(Equal(""))
	})

	It("TestDeleteUserWithForceOption", func() {
		foundUserFields := models.UserFields{}
		foundUserFields.Guid = "my-found-user-guid"
		userRepo := &testapi.FakeUserRepository{FindByUsernameUserFields: foundUserFields}
		reqFactory := &testreq.FakeReqFactory{LoginSuccess: true}

		ui := callDeleteUser([]string{"-f", "my-user"}, userRepo, reqFactory)

		Expect(len(ui.Outputs)).To(Equal(2))
		Expect(len(ui.Prompts)).To(Equal(0))
		testassert.SliceContains(ui.Outputs, testassert.Lines{
			{"Deleting user", "my-user"},
			{"OK"},
		})

		Expect(userRepo.FindByUsernameUsername).To(Equal("my-user"))
		Expect(userRepo.DeleteUserGuid).To(Equal("my-found-user-guid"))
開發者ID:knolleary,項目名稱:cli,代碼行數:31,代碼來源:delete_user_test.go

示例6:

	It("TestFindByUsername", func() {
		usersResponse := `{ "resources": [{ "id": "my-guid", "userName": "my-full-username" }]}`
		uaaReq := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
			Method:   "GET",
			Path:     "/Users?attributes=id,userName&filter=userName+Eq+%22damien%2Buser1%40pivotallabs.com%22",
			Response: testnet.TestResponse{Status: http.StatusOK, Body: usersResponse},
		})

		uaa, handler, repo := createUsersRepoWithoutCCEndpoints([]testnet.TestRequest{uaaReq})
		defer uaa.Close()

		user, apiResponse := repo.FindByUsername("[email protected]")
		Expect(handler.AllRequestsCalled()).To(BeTrue())
		Expect(apiResponse.IsSuccessful()).To(BeTrue())

		expectedUserFields := models.UserFields{}
		expectedUserFields.Username = "my-full-username"
		expectedUserFields.Guid = "my-guid"
		Expect(user).To(Equal(expectedUserFields))
	})

	It("TestFindByUsernameWhenNotFound", func() {
		uaaReq := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
			Method:   "GET",
			Path:     "/Users?attributes=id,userName&filter=userName+Eq+%22my-user%22",
			Response: testnet.TestResponse{Status: http.StatusOK, Body: `{"resources": []}`},
		})

		uaa, handler, repo := createUsersRepoWithoutCCEndpoints([]testnet.TestRequest{uaaReq})
		defer uaa.Close()
開發者ID:normalnorman,項目名稱:cli,代碼行數:30,代碼來源:users_test.go


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