예제 #1
1
파일: login_test.go 프로젝트: nsnt/cli
func TestLoggingInWithTooManyOrgsDoesNotShowOrgList(t *testing.T) {
	c := LoginTestContext{
		Inputs: []string{"api.example.com", "*****@*****.**", "password", "my-org-1", "my-space"},
	}

	callLogin(t, &c, func(c *LoginTestContext) {
		for i := 0; i < 60; i++ {
			id := strconv.Itoa(i)
			org := cf.Organization{}
			org.Guid = "my-org-guid-" + id
			org.Name = "my-org-" + id
			c.orgRepo.Organizations = append(c.orgRepo.Organizations, org)
		}

		c.orgRepo.FindByNameOrganization = c.orgRepo.Organizations[1]

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

		space2 := cf.Space{}
		space2.Guid = "some-space-guid"
		space2.Name = "some-space"

		c.spaceRepo.Spaces = []cf.Space{space1, space2}
	})

	savedConfig := testconfig.SavedConfiguration

	testassert.SliceDoesNotContain(t, c.ui.Outputs, testassert.Lines{
		{"my-org-2"},
	})
	assert.Equal(t, c.orgRepo.FindByNameName, "my-org-1")
	assert.Equal(t, savedConfig.OrganizationFields.Guid, "my-org-guid-1")
}
예제 #2
1
파일: target_test.go 프로젝트: nsnt/cli
func TestTargetSpaceWhenUserHasAccess(t *testing.T) {
	orgRepo, spaceRepo, configRepo, reqFactory := getTargetDependencies()

	configRepo.Delete()
	config := configRepo.Login()
	config.OrganizationFields = cf.OrganizationFields{}
	config.OrganizationFields.Name = "my-org"
	config.OrganizationFields.Guid = "my-org-guid"

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

	spaceRepo.Spaces = []cf.Space{space}
	spaceRepo.FindByNameSpace = space

	ui := callTarget([]string{"-s", "my-space"}, reqFactory, configRepo, orgRepo, spaceRepo)

	assert.Equal(t, spaceRepo.FindByNameName, "my-space")
	savedConfig := testconfig.SavedConfiguration
	assert.Equal(t, savedConfig.SpaceFields.Guid, "my-space-guid")
	assert.True(t, ui.ShowConfigurationCalled)
}
예제 #3
0
파일: login_test.go 프로젝트: nsnt/cli
func TestSuccessfullyLoggingInWithNumericalPrompts(t *testing.T) {
	OUT_OF_RANGE_CHOICE := "3"
	c := LoginTestContext{
		Inputs: []string{"api.example.com", "*****@*****.**", "password", OUT_OF_RANGE_CHOICE, "2", OUT_OF_RANGE_CHOICE, "1"},
	}

	org1 := cf.Organization{}
	org1.Guid = "some-org-guid"
	org1.Name = "some-org"

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

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

	space2 := cf.Space{}
	space2.Guid = "some-space-guid"
	space2.Name = "some-space"

	callLogin(t, &c, func(c *LoginTestContext) {
		c.orgRepo.Organizations = []cf.Organization{org1, org2}
		c.spaceRepo.Spaces = []cf.Space{space1, space2}
	})

	savedConfig := testconfig.SavedConfiguration

	expectedOutputs := testassert.Lines{
		testassert.Line{"Select an org:"},
		testassert.Line{"1. some-org"},
		testassert.Line{"2. my-org"},
		testassert.Line{"Select a space:"},
		testassert.Line{"1. my-space"},
		testassert.Line{"2. some-space"},
	}

	testassert.SliceContains(t, c.ui.Outputs, expectedOutputs)

	assert.Equal(t, savedConfig.Target, "api.example.com")
	assert.Equal(t, savedConfig.OrganizationFields.Guid, "my-org-guid")
	assert.Equal(t, savedConfig.SpaceFields.Guid, "my-space-guid")
	assert.Equal(t, savedConfig.AccessToken, "my_access_token")
	assert.Equal(t, savedConfig.RefreshToken, "my_refresh_token")

	assert.Equal(t, c.endpointRepo.UpdateEndpointReceived, "api.example.com")
	assert.Equal(t, c.authRepo.Email, "*****@*****.**")
	assert.Equal(t, c.authRepo.Password, "password")

	assert.Equal(t, c.orgRepo.FindByNameName, "my-org")
	assert.Equal(t, c.spaceRepo.FindByNameName, "my-space")

	assert.True(t, c.ui.ShowConfigurationCalled)
}
예제 #4
0
파일: login_test.go 프로젝트: nsnt/cli
func TestSuccessfullyLoggingInWithOnlyOneSpace(t *testing.T) {
	space := cf.Space{}
	space.Guid = "my-space-guid"
	space.Name = "my-space"

	c := LoginTestContext{
		Flags:  []string{"-o", "my-org"},
		Inputs: []string{"http://api.example.com", "*****@*****.**", "password"},
	}

	callLogin(t, &c, func(c *LoginTestContext) {
		c.spaceRepo.Spaces = []cf.Space{space}
	})

	savedConfig := testconfig.SavedConfiguration

	assert.Equal(t, savedConfig.Target, "http://api.example.com")
	assert.Equal(t, savedConfig.OrganizationFields.Guid, "my-org-guid")
	assert.Equal(t, savedConfig.SpaceFields.Guid, "my-space-guid")
	assert.Equal(t, savedConfig.AccessToken, "my_access_token")
	assert.Equal(t, savedConfig.RefreshToken, "my_refresh_token")

	assert.Equal(t, c.endpointRepo.UpdateEndpointReceived, "http://api.example.com")
	assert.Equal(t, c.authRepo.Email, "*****@*****.**")
	assert.Equal(t, c.authRepo.Password, "password")

	assert.True(t, c.ui.ShowConfigurationCalled)
}
예제 #5
0
파일: target_test.go 프로젝트: nsnt/cli
func TestTargetOrganizationAndSpace(t *testing.T) {
	orgRepo, spaceRepo, configRepo, reqFactory := getTargetDependencies()
	configRepo.Delete()
	configRepo.Login()

	org := cf.Organization{}
	org.Name = "my-organization"
	org.Guid = "my-organization-guid"
	orgRepo.FindByNameOrganization = org

	space := cf.Space{}
	space.Name = "my-space"
	space.Guid = "my-space-guid"
	spaceRepo.FindByNameSpace = space

	ui := callTarget([]string{"-o", "my-organization", "-s", "my-space"}, reqFactory, configRepo, orgRepo, spaceRepo)

	savedConfig := testconfig.SavedConfiguration
	assert.True(t, ui.ShowConfigurationCalled)

	assert.Equal(t, orgRepo.FindByNameName, "my-organization")
	assert.Equal(t, savedConfig.OrganizationFields.Guid, "my-organization-guid")

	assert.Equal(t, spaceRepo.FindByNameName, "my-space")
	assert.Equal(t, savedConfig.SpaceFields.Guid, "my-space-guid")
}
예제 #6
0
파일: space_test.go 프로젝트: nsnt/cli
func TestSpaceReqExecute(t *testing.T) {
	space := cf.Space{}
	space.Name = "my-space"
	space.Guid = "my-space-guid"
	spaceRepo := &testapi.FakeSpaceRepository{FindByNameSpace: space}
	ui := new(testterm.FakeUI)

	spaceReq := newSpaceRequirement("foo", ui, spaceRepo)
	success := spaceReq.Execute()

	assert.True(t, success)
	assert.Equal(t, spaceRepo.FindByNameName, "foo")
	assert.Equal(t, spaceReq.GetSpace(), space)
}
예제 #7
0
func TestRenameSpaceRun(t *testing.T) {
	spaceRepo := &testapi.FakeSpaceRepository{}
	space := cf.Space{}
	space.Name = "my-space"
	space.Guid = "my-space-guid"
	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedOrgSuccess: true, Space: space}
	ui := callRenameSpace(t, []string{"my-space", "my-new-space"}, reqFactory, spaceRepo)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Renaming space", "my-space", "my-new-space", "my-org", "my-user"},
		{"OK"},
	})

	assert.Equal(t, spaceRepo.RenameSpaceGuid, "my-space-guid")
	assert.Equal(t, spaceRepo.RenameNewName, "my-new-space")
}
예제 #8
0
func TestSpaceUsers(t *testing.T) {
	org := cf.Organization{}
	org.Name = "Org1"
	org.Guid = "org1-guid"
	space := cf.Space{}
	space.Name = "Space1"
	space.Guid = "space1-guid"

	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, Organization: org}
	spaceRepo := &testapi.FakeSpaceRepository{FindByNameInOrgSpace: space}
	userRepo := &testapi.FakeUserRepository{}

	user := cf.UserFields{}
	user.Username = "******"
	user2 := cf.UserFields{}
	user2.Username = "******"
	user3 := cf.UserFields{}
	user3.Username = "******"
	user4 := cf.UserFields{}
	user4.Username = "******"
	userRepo.ListUsersByRole = map[string][]cf.UserFields{
		cf.SPACE_MANAGER:   []cf.UserFields{user, user2},
		cf.SPACE_DEVELOPER: []cf.UserFields{user4},
		cf.SPACE_AUDITOR:   []cf.UserFields{user3},
	}

	ui := callSpaceUsers(t, []string{"my-org", "my-space"}, reqFactory, spaceRepo, userRepo)

	assert.Equal(t, spaceRepo.FindByNameInOrgName, "my-space")
	assert.Equal(t, spaceRepo.FindByNameInOrgOrgGuid, "org1-guid")
	assert.Equal(t, userRepo.ListUsersSpaceGuid, "space1-guid")

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Getting users in org", "Org1", "Space1", "my-user"},
		{"SPACE MANAGER"},
		{"user1"},
		{"user2"},
		{"SPACE DEVELOPER"},
		{"user4"},
		{"SPACE AUDITOR"},
		{"user3"},
	})
}
예제 #9
0
파일: login_test.go 프로젝트: nsnt/cli
func callLogin(t *testing.T, c *LoginTestContext, beforeBlock func(*LoginTestContext)) {

	c.configRepo = testconfig.FakeConfigRepository{}
	c.ui = &testterm.FakeUI{
		Inputs: c.Inputs,
	}
	c.authRepo = &testapi.FakeAuthenticationRepository{
		AccessToken:  "my_access_token",
		RefreshToken: "my_refresh_token",
		ConfigRepo:   c.configRepo,
	}
	c.endpointRepo = &testapi.FakeEndpointRepo{}

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

	c.orgRepo = &testapi.FakeOrgRepository{
		FindByNameOrganization: org,
	}

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

	c.spaceRepo = &testapi.FakeSpaceRepository{
		FindByNameSpace: space,
	}

	c.configRepo.Delete()
	config, _ := c.configRepo.Get()
	config.Target = c.Config.Target
	config.OrganizationFields = c.Config.OrganizationFields
	config.SpaceFields = c.Config.SpaceFields

	beforeBlock(c)

	l := NewLogin(c.ui, c.configRepo, c.authRepo, c.endpointRepo, c.orgRepo, c.spaceRepo)
	l.Run(testcmd.NewContext("login", c.Flags))
}
예제 #10
0
func getDomainMapperDeps() (reqFactory *testreq.FakeReqFactory, domainRepo *testapi.FakeDomainRepository) {
	domain := cf.Domain{}
	domain.Name = "foo.com"
	domain.Guid = "foo-guid"
	domainRepo = &testapi.FakeDomainRepository{
		FindByNameInOrgDomain: domain,
	}

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

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

	reqFactory = &testreq.FakeReqFactory{
		LoginSuccess:       true,
		TargetedOrgSuccess: true,
		Organization:       org,
		Space:              space,
	}
	return
}
예제 #11
0
func defaultDeleteSpaceSpace() cf.Space {
	space := cf.Space{}
	space.Name = "space-to-delete"
	space.Guid = "space-to-delete-guid"
	return space
}