github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/integration/v7/selfcontained/create_space_command_test.go (about) 1 package selfcontained_test 2 3 import ( 4 "net/http" 5 "os" 6 "path/filepath" 7 8 "code.cloudfoundry.org/cli/integration/helpers" 9 "code.cloudfoundry.org/cli/integration/v7/selfcontained/fake" 10 "code.cloudfoundry.org/cli/util/configv3" 11 . "github.com/onsi/ginkgo" 12 . "github.com/onsi/gomega" 13 "github.com/onsi/gomega/gbytes" 14 "github.com/onsi/gomega/gexec" 15 apiv1 "k8s.io/client-go/tools/clientcmd/api/v1" 16 ) 17 18 var _ = Describe("Create Space Command", func() { 19 Describe("CF-on-k8s", func() { 20 var ( 21 kubeConfigPath string 22 kubeConfig apiv1.Config 23 session *gexec.Session 24 apiConfig fake.CFAPIConfig 25 ) 26 27 BeforeEach(func() { 28 helpers.SetConfig(func(config *configv3.Config) { 29 config.ConfigFile.Target = apiServer.URL() 30 config.ConfigFile.CFOnK8s.Enabled = true 31 config.ConfigFile.CFOnK8s.AuthInfo = "my-auth" 32 config.ConfigFile.TargetedOrganization.GUID = "org-guid" 33 config.ConfigFile.TargetedOrganization.Name = "my-org" 34 }) 35 36 apiConfig = fake.CFAPIConfig{ 37 Routes: map[string]fake.Response{ 38 "POST /v3/spaces": {Code: http.StatusCreated}, 39 "POST /v3/roles": {Code: http.StatusCreated}, 40 "GET /whoami": { 41 Code: http.StatusOK, Body: map[string]interface{}{ 42 "name": "my-user", 43 "kind": "User", 44 }, 45 }, 46 }, 47 } 48 apiServer.SetConfiguration(apiConfig) 49 50 kubeConfig = apiv1.Config{ 51 Kind: "Config", 52 APIVersion: "v1", 53 AuthInfos: []apiv1.NamedAuthInfo{ 54 { 55 Name: "my-auth", 56 AuthInfo: apiv1.AuthInfo{ 57 Token: "foo", 58 }, 59 }, 60 }, 61 Clusters: []apiv1.NamedCluster{ 62 { 63 Name: "my-cluster", 64 Cluster: apiv1.Cluster{ 65 Server: "https://example.org", 66 }, 67 }, 68 }, 69 Contexts: []apiv1.NamedContext{ 70 { 71 Name: "my-context", 72 Context: apiv1.Context{ 73 Cluster: "my-cluster", 74 AuthInfo: "my-auth", 75 Namespace: "my-namespace", 76 }, 77 }, 78 }, 79 CurrentContext: "my-context", 80 } 81 82 kubeConfigPath := filepath.Join(homeDir, ".kube", "config") 83 storeKubeConfig(kubeConfig, kubeConfigPath) 84 85 env = helpers.CFEnv{ 86 EnvVars: map[string]string{ 87 "KUBECONFIG": kubeConfigPath, 88 }, 89 } 90 }) 91 92 JustBeforeEach(func() { 93 session = helpers.CustomCF(env, "create-space", "my-space") 94 }) 95 96 AfterEach(func() { 97 Expect(os.RemoveAll(kubeConfigPath)).To(Succeed()) 98 }) 99 100 It("creates a role using the name from the /whoami endpoint", func() { 101 Eventually(session).Should(gexec.Exit(0)) 102 103 Expect(session).To(gbytes.Say("Assigning role SpaceManager to user my-user in org my-org")) 104 Expect(session).To(gbytes.Say("Assigning role SpaceDeveloper to user my-user in org my-org")) 105 }) 106 }) 107 })