github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+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 // If orgName is empty, the BeforeSuite has failed and attempting to delete 53 // will produce a meaningless error. 54 if orgName == "" { 55 fmt.Println("Empty org name. Skipping deletion.") 56 return 57 } 58 59 guid := GetOrgGUID(orgName) 60 url := fmt.Sprintf("/v2/organizations/%s?recursive=true&async=true", guid) 61 session := CF("curl", "-X", "DELETE", url) 62 Eventually(session).Should(Exit(0)) 63 } 64 65 func QuickDeleteOrgIfExists(orgName string) { 66 session := CF("org", "--guid", orgName) 67 Eventually(session).Should(Exit()) 68 if session.ExitCode() != 0 { 69 return 70 } 71 guid := strings.TrimSpace(string(session.Out.Contents())) 72 url := fmt.Sprintf("/v2/organizations/%s?recursive=true&async=true", guid) 73 session = CF("curl", "-X", "DELETE", url) 74 Eventually(session).Should(Exit()) 75 } 76 77 func QuickDeleteSpace(spaceName string) { 78 guid := GetSpaceGUID(spaceName) 79 url := fmt.Sprintf("/v2/spaces/%s?recursive=true&async=true", guid) 80 session := CF("curl", "-X", "DELETE", url) 81 Eventually(session).Should(Exit(0)) 82 }