-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test retrieval of configuration variables
JIRA: LMCROSSITXSADEPLOY-1456
- Loading branch information
Showing
6 changed files
with
133 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package configuration | ||
|
||
import ( | ||
"github.com/cloudfoundry-incubator/multiapps-cli-plugin/ui" | ||
"os" | ||
"strconv" | ||
) | ||
|
||
const ( | ||
ChunkSizeInMBEnv = "CHUNK_SIZE_IN_MB" | ||
TargetURLEnv = "DEPLOY_SERVICE_URL" | ||
DefaultChunkSizeInMB = uint64(45) | ||
) | ||
|
||
func GetChunkSizeInMB() uint64 { | ||
chunkSizeInMb, isSet := os.LookupEnv(ChunkSizeInMBEnv) | ||
if isSet { | ||
parsedChunkSizeInMb, err := strconv.ParseUint(chunkSizeInMb, 10, 64) | ||
if err == nil && parsedChunkSizeInMb != 0 { | ||
ui.Say("Attention: You've specified a custom chunk size (%d MB) via the environment variable \"%s\".", parsedChunkSizeInMb, ChunkSizeInMBEnv) | ||
return parsedChunkSizeInMb | ||
} | ||
ui.Warn("Attention: You've specified an INVALID custom chunk size (%s) via the environment variable \"%s\". Using default: %d", chunkSizeInMb, ChunkSizeInMBEnv, DefaultChunkSizeInMB) | ||
} | ||
return DefaultChunkSizeInMB | ||
} | ||
|
||
func GetTargetURL() string { | ||
targetURL := os.Getenv(TargetURLEnv) | ||
if targetURL != "" { | ||
ui.Say("Attention: You've specified a custom Deploy Service URL (%s) via the environment variable \"%s\". The application listening on that URL may be outdated, contain bugs or unreleased features or may even be modified by a potentially untrused person. Use at your own risk.\n", targetURL, TargetURLEnv) | ||
} | ||
return targetURL | ||
} |
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,13 @@ | ||
package configuration_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
"testing" | ||
) | ||
|
||
func TestUtil(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Configuration Suite") | ||
} |
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,76 @@ | ||
package configuration_test | ||
|
||
import ( | ||
"github.com/cloudfoundry-incubator/multiapps-cli-plugin/configuration" | ||
"github.com/cloudfoundry-incubator/multiapps-cli-plugin/ui" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"os" | ||
"strconv" | ||
) | ||
|
||
var _ = Describe("Configuration", func() { | ||
|
||
BeforeEach(func() { | ||
ui.DisableTerminalOutput(true) | ||
}) | ||
|
||
Describe("GetTargetURL", func() { | ||
|
||
BeforeEach(func() { | ||
os.Unsetenv(configuration.TargetURLEnv) | ||
}) | ||
|
||
Context("with a set environment variable", func() { | ||
It("should return its value", func() { | ||
targetURL := "http://my-multiapps-controller.domain.com" | ||
os.Setenv(configuration.TargetURLEnv, targetURL) | ||
Expect(configuration.GetTargetURL()).To(Equal(targetURL)) | ||
}) | ||
}) | ||
Context("without a set environment variable", func() { | ||
It("should return an empty string", func() { | ||
Expect(configuration.GetTargetURL()).To(BeEmpty()) | ||
}) | ||
}) | ||
|
||
}) | ||
|
||
Describe("GetChunkSizeInMB", func() { | ||
|
||
BeforeEach(func() { | ||
os.Unsetenv(configuration.TargetURLEnv) | ||
}) | ||
|
||
Context("with a set environment variable", func() { | ||
Context("containing a positive integer", func() { | ||
It("should return its value", func() { | ||
chunkSizeInMB := uint64(5) | ||
os.Setenv(configuration.ChunkSizeInMBEnv, strconv.Itoa(int(chunkSizeInMB))) | ||
Expect(configuration.GetChunkSizeInMB()).To(Equal(chunkSizeInMB)) | ||
}) | ||
}) | ||
Context("containing zero", func() { | ||
It("should return the default value", func() { | ||
chunkSizeInMB := 0 | ||
os.Setenv(configuration.ChunkSizeInMBEnv, strconv.Itoa(chunkSizeInMB)) | ||
Expect(configuration.GetChunkSizeInMB()).To(Equal(configuration.DefaultChunkSizeInMB)) | ||
}) | ||
}) | ||
Context("containing a string", func() { | ||
It("should return the default value", func() { | ||
chunkSizeInMB := "abc" | ||
os.Setenv(configuration.ChunkSizeInMBEnv, chunkSizeInMB) | ||
Expect(configuration.GetChunkSizeInMB()).To(Equal(configuration.DefaultChunkSizeInMB)) | ||
}) | ||
}) | ||
}) | ||
Context("without a set environment variable", func() { | ||
It("should return the default value", func() { | ||
Expect(configuration.GetChunkSizeInMB()).To(Equal(configuration.DefaultChunkSizeInMB)) | ||
}) | ||
}) | ||
|
||
}) | ||
|
||
}) |
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