github.com/cloudfoundry-community/cloudfoundry-cli@v6.44.1-0.20240130060226-cda5ed8e89a5+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 func DomainName(prefix ...string) string { 14 if len(prefix) > 0 { 15 return fmt.Sprintf("integration-%s.com", PrefixedRandomName(prefix[0])) 16 } 17 return fmt.Sprintf("integration%s.com", PrefixedRandomName("")) 18 } 19 20 type Domain struct { 21 Org string 22 Name string 23 } 24 25 func NewDomain(org string, name string) Domain { 26 return Domain{ 27 Org: org, 28 Name: name, 29 } 30 } 31 32 // globally cached 33 var foundDefaultDomain string 34 35 func DefaultSharedDomain() string { 36 if foundDefaultDomain == "" { 37 session := CF("domains") 38 Eventually(session).Should(Exit(0)) 39 40 regex := regexp.MustCompile(`(.+?)\s+shared`) 41 42 output := strings.Split(string(session.Out.Contents()), "\n") 43 for _, line := range output { 44 if line != "" && !strings.HasPrefix(line, "integration-") { 45 matches := regex.FindStringSubmatch(line) 46 if len(matches) == 2 { 47 foundDefaultDomain = matches[1] 48 break 49 } 50 } 51 } 52 Expect(foundDefaultDomain).ToNot(BeEmpty()) 53 } 54 return foundDefaultDomain 55 } 56 57 func (d Domain) Create() { 58 Eventually(CF("create-domain", d.Org, d.Name)).Should(Exit(0)) 59 Eventually(CF("domains")).Should(And(Exit(0), Say(d.Name))) 60 } 61 62 func (d Domain) CreatePrivate() { 63 Eventually(CF("create-private-domain", d.Org, d.Name)).Should(Exit(0)) 64 } 65 66 func (d Domain) CreateShared() { 67 Eventually(CF("create-shared-domain", d.Name)).Should(Exit(0)) 68 } 69 70 func (d Domain) CreateWithRouterGroup(routerGroup string) { 71 Eventually(CF("create-shared-domain", d.Name, "--router-group", routerGroup)).Should(Exit(0)) 72 } 73 74 func (d Domain) CreateInternal() { 75 Eventually(CF("create-shared-domain", d.Name, "--internal")).Should(Exit(0)) 76 } 77 78 func (d Domain) Share() { 79 Eventually(CF("share-private-domain", d.Org, d.Name)).Should(Exit(0)) 80 } 81 82 func (d Domain) V7Share(orgName string) { 83 Eventually(CF("share-private-domain", orgName, d.Name)).Should(Exit(0)) 84 } 85 86 func (d Domain) Delete() { 87 Eventually(CF("delete-domain", d.Name, "-f")).Should(Exit(0)) 88 } 89 90 func (d Domain) DeleteShared() { 91 Eventually(CF("delete-shared-domain", d.Name, "-f")).Should(Exit(0)) 92 }