github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/helpers/domains.go (about) 1 package helpers 2 3 import ( 4 "fmt" 5 "regexp" 6 "strings" 7 8 . "github.com/onsi/gomega" 9 . "github.com/onsi/gomega/gbytes" 10 . "github.com/onsi/gomega/gexec" 11 ) 12 13 // DomainName returns a random domain name, with a given prefix if provided. 14 func DomainName(prefix ...string) string { 15 if len(prefix) > 0 { 16 return fmt.Sprintf("integration-%s.com", PrefixedRandomName(prefix[0])) 17 } 18 return fmt.Sprintf("integration%s.com", PrefixedRandomName("")) 19 } 20 21 // Domain represents a domain scoped to an organization. 22 type Domain struct { 23 Org string 24 Name string 25 } 26 27 // NewDomain constructs a new Domain with given owning organization and name. 28 func NewDomain(org string, name string) Domain { 29 return Domain{ 30 Org: org, 31 Name: name, 32 } 33 } 34 35 // globally cached 36 var foundDefaultDomain string 37 38 // DefaultSharedDomain runs 'cf domains' to find the default domain, caching 39 // the result so that the same domain is returned each time it is called. 40 func DefaultSharedDomain() string { 41 if foundDefaultDomain == "" { 42 session := CF("domains") 43 Eventually(session).Should(Exit(0)) 44 45 regex := regexp.MustCompile(`(.+?)\s+shared`) 46 47 output := strings.Split(string(session.Out.Contents()), "\n") 48 for _, line := range output { 49 if line != "" && !strings.HasPrefix(line, "integration-") { 50 matches := regex.FindStringSubmatch(line) 51 if len(matches) == 2 { 52 foundDefaultDomain = matches[1] 53 break 54 } 55 } 56 } 57 Expect(foundDefaultDomain).ToNot(BeEmpty()) 58 } 59 return foundDefaultDomain 60 } 61 62 // Create uses 'cf create-domain' to create the domain in org d.Org with name 63 // d.Name. 64 func (d Domain) Create() { 65 Eventually(CF("create-domain", d.Org, d.Name)).Should(Exit(0)) 66 Eventually(CF("domains")).Should(And(Exit(0), Say(d.Name))) 67 } 68 69 // CreatePrivate uses 'cf create-private-domain' to create the domain in org 70 // d.Org with name d.Name. 71 func (d Domain) CreatePrivate() { 72 Eventually(CF("create-private-domain", d.Org, d.Name)).Should(Exit(0)) 73 } 74 75 // CreateShared uses 'cf create-shared-domain' to create an shared domain 76 // with name d.Name. 77 func (d Domain) CreateShared() { 78 Eventually(CF("create-shared-domain", d.Name)).Should(Exit(0)) 79 } 80 81 // CreateWithRouterGroup uses 'cf create-shared-domain' to create a shared 82 // domain with name d.Name and given router group. 83 func (d Domain) CreateWithRouterGroup(routerGroup string) { 84 Eventually(CF("create-shared-domain", d.Name, "--router-group", routerGroup)).Should(Exit(0)) 85 } 86 87 // CreateInternal uses 'cf create-shared-domain' to create an shared, 88 // internal domain with name d.Name. 89 func (d Domain) CreateInternal() { 90 Eventually(CF("create-shared-domain", d.Name, "--internal")).Should(Exit(0)) 91 } 92 93 // V7Share uses 'cf share-private-domain' to share the domain with the given 94 // org. 95 func (d Domain) V7Share(orgName string) { 96 Eventually(CF("share-private-domain", orgName, d.Name)).Should(Exit(0)) 97 } 98 99 // Delete uses 'cf delete-domain' to delete the domain without asking for 100 // confirmation. 101 func (d Domain) Delete() { 102 Eventually(CF("delete-domain", d.Name, "-f")).Should(Exit(0)) 103 } 104 105 // DeletePrivate uses 'cf delete-private-domain' to delete the domain without asking for 106 // confirmation. 107 func (d Domain) DeletePrivate() { 108 Eventually(CF("delete-private-domain", d.Name, "-f")).Should(Exit(0)) 109 } 110 111 // DeleteShared uses 'cf delete-shared-domain' to delete the shared domain 112 // without asking for confirmation. 113 func (d Domain) DeleteShared() { 114 Eventually(CF("delete-shared-domain", d.Name, "-f")).Should(Exit(0)) 115 }