forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This makes `cf api` able to detect the `cf-on-k8s` flag in the root endpoint response and persist this information in the config. This will allow us to enable CF-on-K8s-specific behaviour for every following command. We have introduced a new `selfcontained` integration suite which contains tests that do not need to be run against a cf deployment. Issue: cloudfoundry/cf-k8s-api#10 Co-authored-by: Danail Branekov <danailster@gmail.com> Co-authored-by: Giuseppe Capizzi <gcapizzi@pivotal.io> Co-authored-by: Georgi Sabev <georgethebeatle@gmail.com>
- Loading branch information
1 parent
e8d41cf
commit 42a8473
Showing
11 changed files
with
145 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package selfcontained_test | ||
|
||
import ( | ||
"encoding/json" | ||
"io/ioutil" | ||
"net/http" | ||
"path/filepath" | ||
|
||
"code.cloudfoundry.org/cli/integration/helpers" | ||
"code.cloudfoundry.org/cli/util/configv3" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"github.com/onsi/gomega/gexec" | ||
"github.com/onsi/gomega/ghttp" | ||
) | ||
|
||
var _ = Describe("cf api", func() { | ||
var ( | ||
server *ghttp.Server | ||
responseBody string | ||
) | ||
|
||
BeforeEach(func() { | ||
responseBody = "{}" | ||
}) | ||
|
||
JustBeforeEach(func() { | ||
server = ghttp.NewServer() | ||
server.AppendHandlers( | ||
ghttp.CombineHandlers( | ||
ghttp.VerifyRequest("GET", "/"), | ||
ghttp.RespondWith(http.StatusOK, responseBody), | ||
), | ||
) | ||
|
||
Eventually(helpers.CF("api", server.URL())).Should(gexec.Exit(0)) | ||
}) | ||
|
||
AfterEach(func() { | ||
server.Close() | ||
}) | ||
|
||
It("disables cf-on-k8s in config", func() { | ||
Expect(loadConfig().CFOnK8s.Enabled).To(BeFalse()) | ||
}) | ||
|
||
When("pointed to cf-on-k8s", func() { | ||
BeforeEach(func() { | ||
responseBody = `{ "cf_on_k8s": true }` | ||
}) | ||
|
||
It("enables cf-on-k8s in config", func() { | ||
Expect(loadConfig().CFOnK8s.Enabled).To(BeTrue()) | ||
}) | ||
}) | ||
}) | ||
|
||
func loadConfig() configv3.JSONConfig { | ||
rawConfig, err := ioutil.ReadFile(filepath.Join(homeDir, ".cf", "config.json")) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
var configFile configv3.JSONConfig | ||
Expect(json.Unmarshal(rawConfig, &configFile)).To(Succeed()) | ||
|
||
return configFile | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package selfcontained_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"code.cloudfoundry.org/cli/integration/helpers" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var homeDir string | ||
|
||
func TestSelfcontained(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Selfcontained Suite") | ||
} | ||
|
||
var _ = BeforeEach(func() { | ||
homeDir = helpers.SetHomeDir() | ||
}) | ||
|
||
var _ = AfterEach(func() { | ||
helpers.DestroyHomeDir(homeDir) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters