github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/integration/helpers/org_and_space.go (about) 1 package helpers 2 3 import ( 4 "fmt" 5 "strings" 6 7 . "github.com/onsi/gomega" 8 . "github.com/onsi/gomega/gexec" 9 ) 10 11 func SetupReadOnlyOrgAndSpace() (string, string) { 12 homeDir := SetHomeDir() 13 SetAPI() 14 LoginCF() 15 orgName := NewOrgName() 16 spaceName1 := NewSpaceName() 17 spaceName2 := NewSpaceName() 18 Eventually(CF("create-org", orgName)).Should(Exit(0)) 19 Eventually(CF("create-space", spaceName1, "-o", orgName)).Should(Exit(0)) 20 Eventually(CF("create-space", spaceName2, "-o", orgName)).Should(Exit(0)) 21 DestroyHomeDir(homeDir) 22 return orgName, spaceName1 23 } 24 25 func CreateOrgAndSpace(org string, space string) { 26 CreateOrg(org) 27 TargetOrg(org) 28 CreateSpace(space) 29 } 30 31 func CreateOrg(org string) { 32 Eventually(CF("create-org", org)).Should(Exit(0)) 33 } 34 35 func CreateSpace(space string) { 36 Eventually(CF("create-space", space)).Should(Exit(0)) 37 } 38 39 func GetOrgGUID(orgName string) string { 40 session := CF("org", "--guid", orgName) 41 Eventually(session).Should(Exit(0)) 42 return strings.TrimSpace(string(session.Out.Contents())) 43 } 44 45 func GetSpaceGUID(spaceName string) string { 46 session := CF("space", "--guid", spaceName) 47 Eventually(session).Should(Exit(0)) 48 return strings.TrimSpace(string(session.Out.Contents())) 49 } 50 51 func QuickDeleteOrg(orgName string) { 52 guid := GetOrgGUID(orgName) 53 url := fmt.Sprintf("/v2/organizations/%s?recursive=true&async=true", guid) 54 session := CF("curl", "-X", "DELETE", url) 55 Eventually(session).Should(Exit(0)) 56 } 57 58 func QuickDeleteOrgIfExists(orgName string) { 59 session := CF("org", "--guid", orgName) 60 Eventually(session).Should(Exit()) 61 if session.ExitCode() != 0 { 62 return 63 } 64 guid := strings.TrimSpace(string(session.Out.Contents())) 65 url := fmt.Sprintf("/v2/organizations/%s?recursive=true&async=true", guid) 66 session = CF("curl", "-X", "DELETE", url) 67 Eventually(session).Should(Exit()) 68 } 69 70 func QuickDeleteSpace(spaceName string) { 71 guid := GetSpaceGUID(spaceName) 72 url := fmt.Sprintf("/v2/spaces/%s?recursive=true&async=true", guid) 73 session := CF("curl", "-X", "DELETE", url) 74 Eventually(session).Should(Exit(0)) 75 }