Skip to content

Commit

Permalink
Merge pull request #596 from SrinivasChilveri/Issue_68736518
Browse files Browse the repository at this point in the history
Fix to the delete-domain to fail early if domain is shared

[finishes #103895494]
  • Loading branch information
camelpunch committed Sep 25, 2015
2 parents af201cb + 98e4439 commit 584aeac
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cf/commands/domain/delete_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ func (cmd *DeleteDomain) Execute(c flags.FlagContext) {
domain, apiErr := cmd.domainRepo.FindByNameInOrg(domainName, cmd.orgReq.GetOrganizationFields().Guid)

switch apiErr.(type) {
case nil: //do nothing
case nil:
if domain.Shared {
cmd.ui.Failed(T("domain {{.DomainName}} is not an owned domain",
map[string]interface{}{
"DomainName": domainName}))
return
}
case *errors.ModelNotFoundError:
cmd.ui.Ok()
cmd.ui.Warn(apiErr.Error())
Expand Down
23 changes: 23 additions & 0 deletions cf/commands/domain/delete_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,29 @@ var _ = Describe("delete-domain command", func() {
})
})

Context("when the domain is shared", func() {
BeforeEach(func() {
domainRepo.FindByNameInOrgDomain = []models.DomainFields{
models.DomainFields{
Name: "foo1.com",
Guid: "foo1-guid",
Shared: true,
},
}
})
It("informs the user that the domain is shared", func() {
runCommand("foo1.com")

Expect(domainRepo.DeleteDomainGuid).To(Equal(""))
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"FAILED"},
[]string{"domain"},
[]string{"foo1.com"},
[]string{"is not an owned domain"},
))

})
})
Context("when the domain exists", func() {
BeforeEach(func() {
domainRepo.FindByNameInOrgDomain = []models.DomainFields{
Expand Down
5 changes: 5 additions & 0 deletions cf/commands/domain/delete_shared_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ func (cmd *DeleteSharedDomain) Execute(c flags.FlagContext) {
domain, apiErr := cmd.domainRepo.FindByNameInOrg(domainName, cmd.orgReq.GetOrganizationFields().Guid)
switch apiErr.(type) {
case nil:
if !domain.Shared {
cmd.ui.Failed(T("domain {{.DomainName}} is not a shared domain",
map[string]interface{}{"DomainName": domainName}))
return
}
case *errors.ModelNotFoundError:
cmd.ui.Ok()
cmd.ui.Warn(apiErr.Error())
Expand Down
24 changes: 24 additions & 0 deletions cf/commands/domain/delete_shared_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,30 @@ var _ = Describe("delete-shared-domain command", func() {
})
})

Context("when the domain is owned", func() {
BeforeEach(func() {
requirementsFactory.LoginSuccess = true
requirementsFactory.TargetedOrgSuccess = true
domainRepo.FindByNameInOrgDomain = []models.DomainFields{
models.DomainFields{
Name: "foo1.com",
Guid: "foo1-guid",
Shared: false,
},
}
})
It("informs the user that the domain is not shared", func() {
runCommand("foo1.com")

Expect(domainRepo.DeleteSharedDomainGuid).To(Equal(""))
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"FAILED"},
[]string{"domain"},
[]string{"foo1.com"},
[]string{"is not a shared domain"},
))
})
})
Context("when logged in and targeted an organiztion", func() {
BeforeEach(func() {
requirementsFactory.LoginSuccess = true
Expand Down
10 changes: 10 additions & 0 deletions cf/i18n/resources/de_DE.all.json
Original file line number Diff line number Diff line change
Expand Up @@ -5543,5 +5543,15 @@
"id": "{{.Usage}} {{.FormattedMemory}} x {{.InstanceCount}} instances",
"translation": "{{.Usage}} {{.FormattedMemory}} x {{.InstanceCount}} instances",
"modified": false
},
{
"id": "domain {{.DomainName}} is not an owned domain",
"translation": "domain {{.DomainName}} is not an owned domain",
"modified": false
},
{
"id": "domain {{.DomainName}} is not a shared domain",
"translation": "domain {{.DomainName}} is not a shared domain",
"modified": false
}
]
10 changes: 10 additions & 0 deletions cf/i18n/resources/en_US.all.json
Original file line number Diff line number Diff line change
Expand Up @@ -5543,5 +5543,15 @@
"id": "{{.Usage}} {{.FormattedMemory}} x {{.InstanceCount}} instances",
"translation": "{{.Usage}} {{.FormattedMemory}} x {{.InstanceCount}} instances",
"modified": false
},
{
"id": "domain {{.DomainName}} is not an owned domain",
"translation": "domain {{.DomainName}} is not an owned domain",
"modified": false
},
{
"id": "domain {{.DomainName}} is not a shared domain",
"translation": "domain {{.DomainName}} is not a shared domain",
"modified": false
}
]
10 changes: 10 additions & 0 deletions cf/i18n/resources/es_ES.all.json
Original file line number Diff line number Diff line change
Expand Up @@ -5543,5 +5543,15 @@
"id": "{{.Usage}} {{.FormattedMemory}} x {{.InstanceCount}} instances",
"translation": "{{.Usage}} {{.FormattedMemory}} x {{.InstanceCount}} instancias",
"modified": false
},
{
"id": "domain {{.DomainName}} is not an owned domain",
"translation": "domain {{.DomainName}} is not an owned domain",
"modified": false
},
{
"id": "domain {{.DomainName}} is not a shared domain",
"translation": "domain {{.DomainName}} is not a shared domain",
"modified": false
}
]
10 changes: 10 additions & 0 deletions cf/i18n/resources/fr_FR.all.json
Original file line number Diff line number Diff line change
Expand Up @@ -5543,5 +5543,15 @@
"id": "{{.Usage}} {{.FormattedMemory}} x {{.InstanceCount}} instances",
"translation": "{{.Usage}} {{.FormattedMemory}} x {{.InstanceCount}} instances",
"modified": false
},
{
"id": "domain {{.DomainName}} is not an owned domain",
"translation": "domain {{.DomainName}} is not an owned domain",
"modified": false
},
{
"id": "domain {{.DomainName}} is not a shared domain",
"translation": "domain {{.DomainName}} is not a shared domain",
"modified": false
}
]
10 changes: 10 additions & 0 deletions cf/i18n/resources/it_IT.all.json
Original file line number Diff line number Diff line change
Expand Up @@ -5543,5 +5543,15 @@
"id": "{{.Usage}} {{.FormattedMemory}} x {{.InstanceCount}} instances",
"translation": "{{.Usage}} {{.FormattedMemory}} x {{.InstanceCount}} instances",
"modified": false
},
{
"id": "domain {{.DomainName}} is not an owned domain",
"translation": "domain {{.DomainName}} is not an owned domain",
"modified": false
},
{
"id": "domain {{.DomainName}} is not a shared domain",
"translation": "domain {{.DomainName}} is not a shared domain",
"modified": false
}
]
10 changes: 10 additions & 0 deletions cf/i18n/resources/ja_JA.all.json
Original file line number Diff line number Diff line change
Expand Up @@ -5543,5 +5543,15 @@
"id": "{{.Usage}} {{.FormattedMemory}} x {{.InstanceCount}} instances",
"translation": "{{.Usage}} {{.FormattedMemory}} x {{.InstanceCount}} instances",
"modified": false
},
{
"id": "domain {{.DomainName}} is not an owned domain",
"translation": "domain {{.DomainName}} is not an owned domain",
"modified": false
},
{
"id": "domain {{.DomainName}} is not a shared domain",
"translation": "domain {{.DomainName}} is not a shared domain",
"modified": false
}
]
10 changes: 10 additions & 0 deletions cf/i18n/resources/pt_BR.all.json
Original file line number Diff line number Diff line change
Expand Up @@ -5543,5 +5543,15 @@
"id": "{{.Usage}} {{.FormattedMemory}} x {{.InstanceCount}} instances",
"translation": "{{.Usage}} {{.FormattedMemory}} x {{.InstanceCount}} instâncias",
"modified": false
},
{
"id": "domain {{.DomainName}} is not an owned domain",
"translation": "domain {{.DomainName}} is not an owned domain",
"modified": false
},
{
"id": "domain {{.DomainName}} is not a shared domain",
"translation": "domain {{.DomainName}} is not a shared domain",
"modified": false
}
]
10 changes: 10 additions & 0 deletions cf/i18n/resources/zh_Hans.all.json
Original file line number Diff line number Diff line change
Expand Up @@ -5543,5 +5543,15 @@
"id": "{{.Usage}} {{.FormattedMemory}} x {{.InstanceCount}} instances",
"translation": "{{.Usage}} {{.FormattedMemory}} 乘以 {{.InstanceCount}}实例数",
"modified": false
},
{
"id": "domain {{.DomainName}} is not an owned domain",
"translation": "domain {{.DomainName}} is not an owned domain",
"modified": false
},
{
"id": "domain {{.DomainName}} is not a shared domain",
"translation": "domain {{.DomainName}} is not a shared domain",
"modified": false
}
]
10 changes: 10 additions & 0 deletions cf/i18n/resources/zh_Hant.all.json
Original file line number Diff line number Diff line change
Expand Up @@ -5543,5 +5543,15 @@
"id": "{{.Usage}} {{.FormattedMemory}} x {{.InstanceCount}} instances",
"translation": "{{.Usage}} {{.FormattedMemory}} x {{.InstanceCount}} instances",
"modified": false
},
{
"id": "domain {{.DomainName}} is not an owned domain",
"translation": "domain {{.DomainName}} is not an owned domain",
"modified": false
},
{
"id": "domain {{.DomainName}} is not a shared domain",
"translation": "domain {{.DomainName}} is not a shared domain",
"modified": false
}
]

0 comments on commit 584aeac

Please sign in to comment.