-
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.
3: Refactor package-naming and add env-util r=Jaskaranbir a=Jaskaranbir Co-authored-by: Jaskaranbir <jaskaranbir.dhillon@gmail.com>
- Loading branch information
Showing
12 changed files
with
123 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,3 @@ | ||
// Package commonutil provides some commonly used | ||
// convenient utilities for TerrexTech. | ||
package commonutil |
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,25 @@ | ||
package commonutil | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
) | ||
|
||
// ValidateEnv checks if the provided environment variables are set to some value. | ||
// Otherwise the missing variable's name is returned along with an error. | ||
// If multiple variables are missing, this will return error on the first variable | ||
// which was not found. | ||
func ValidateEnv(envVars ...string) (string, error) { | ||
for _, varname := range envVars { | ||
envVar := os.Getenv(varname) | ||
if envVar == "" { | ||
err := errors.New( | ||
"Error while bootstrapping Cassandra table: " + | ||
"Following env-var is required but was not found: " + | ||
varname, | ||
) | ||
return varname, err | ||
} | ||
} | ||
return "", nil | ||
} |
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,56 @@ | ||
package commonutil | ||
|
||
import ( | ||
"os" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("ErrorUtils", func() { | ||
Describe("ValidateEnv", func() { | ||
var unsetEnv = func(envVars ...string) { | ||
for _, v := range envVars { | ||
os.Unsetenv(v) | ||
} | ||
} | ||
|
||
It("should not return any error if all specified env-vars are set", func() { | ||
// Just trying not to override any existing env-vars | ||
envVars := []string{ | ||
"v113451e1234", | ||
"v213451e1234", | ||
"v313451e1234", | ||
"v413451e1234", | ||
} | ||
|
||
for _, v := range envVars { | ||
os.Setenv(v, v) | ||
} | ||
|
||
varName, err := ValidateEnv(envVars...) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(varName).To(BeEmpty()) | ||
unsetEnv(envVars...) | ||
}) | ||
|
||
It("should return error if some env-vars is missing", func() { | ||
envVars := []string{ | ||
"v113451e1234", | ||
"v213451e1234", | ||
"v513451e1234", | ||
} | ||
|
||
for _, v := range envVars { | ||
os.Setenv(v, v) | ||
} | ||
|
||
envVars = append(envVars, "v313451e1234") | ||
envVars = append(envVars, "v413451e1234") | ||
varName, err := ValidateEnv(envVars...) | ||
Expect(err).To(HaveOccurred()) | ||
Expect(varName).To(Equal("v313451e1234")) | ||
unsetEnv(envVars...) | ||
}) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package utils | ||
package commonutil | ||
|
||
import "fmt" | ||
|
||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package utils | ||
package commonutil | ||
|
||
import ( | ||
"reflect" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package utils | ||
package commonutil | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package utils | ||
package commonutil | ||
|
||
import ( | ||
"strings" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package utils | ||
package commonutil | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
|
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