-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
109 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package ephemeral_test | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
. "gopkg.in/check.v1" | ||
corev1 "k8s.io/api/core/v1" | ||
|
||
"github.com/kanisterio/kanister/pkg/ephemeral" | ||
"github.com/kanisterio/kanister/pkg/kube" | ||
) | ||
|
||
// Hook up gocheck into the "go test" runner. | ||
func Test(t *testing.T) { TestingT(t) } | ||
|
||
type EphemeralSuite struct{} | ||
|
||
var _ = Suite(&EphemeralSuite{}) | ||
|
||
func (s *EphemeralSuite) TestRegisteringOSEnvVarKubePodOptions(c *C) { | ||
expected := []corev1.EnvVar{ | ||
{ | ||
Name: "KANISTER_REGISTERED_OS_ENVVAR", | ||
Value: "1", | ||
}, | ||
} | ||
|
||
var options kube.PodOptions | ||
|
||
// OS environment variable not set | ||
var registeredAppliers ephemeral.ApplierList | ||
registeredAppliers.Register(ephemeral.OSEnvVar(expected[0].Name)) | ||
registeredAppliers.Apply(&options) | ||
|
||
c.Assert(options.EnvironmentVariables, DeepEquals, []corev1.EnvVar(nil)) | ||
|
||
// OS environment variable set | ||
os.Setenv(expected[0].Name, expected[0].Value) | ||
defer os.Unsetenv(expected[0].Name) | ||
|
||
registeredAppliers = ephemeral.ApplierList{} | ||
registeredAppliers.Register(ephemeral.OSEnvVar(expected[0].Name)) | ||
registeredAppliers.Apply(&options) | ||
|
||
c.Assert(options.EnvironmentVariables, DeepEquals, expected) | ||
} | ||
|
||
func (s *EphemeralSuite) TestRegisteringOSEnvVarCoreV1Container(c *C) { | ||
expected := []corev1.EnvVar{ | ||
{ | ||
Name: "KANISTER_REGISTERED_OS_ENVVAR", | ||
Value: "1", | ||
}, | ||
} | ||
|
||
var options corev1.Container | ||
|
||
// OS environment variable not set | ||
var registeredAppliers ephemeral.ApplierList | ||
registeredAppliers.Register(ephemeral.OSEnvVar(expected[0].Name)) | ||
registeredAppliers.Apply(&options) | ||
|
||
c.Assert(options.Env, DeepEquals, []corev1.EnvVar(nil)) | ||
|
||
// OS environment variable set | ||
os.Setenv(expected[0].Name, expected[0].Value) | ||
defer os.Unsetenv(expected[0].Name) | ||
|
||
registeredAppliers = ephemeral.ApplierList{} | ||
registeredAppliers.Register(ephemeral.OSEnvVar(expected[0].Name)) | ||
registeredAppliers.Apply(&options) | ||
|
||
c.Assert(options.Env, DeepEquals, expected) | ||
} | ||
|
||
func (s *EphemeralSuite) TestRegisteringStaticEnvVarKubePodOptions(c *C) { | ||
expected := []corev1.EnvVar{ | ||
{ | ||
Name: "KANISTER_REGISTERED_STATIC_ENVVAR", | ||
Value: "1", | ||
}, | ||
} | ||
|
||
var options kube.PodOptions | ||
|
||
var registeredAppliers ephemeral.ApplierList | ||
registeredAppliers.Register(ephemeral.StaticEnvVar(expected[0].Name, expected[0].Value)) | ||
registeredAppliers.Apply(&options) | ||
|
||
c.Assert(options.EnvironmentVariables, DeepEquals, expected) | ||
} | ||
|
||
func (s *EphemeralSuite) TestRegisteringStaticEnvVarCoreV1Container(c *C) { | ||
expected := []corev1.EnvVar{ | ||
{ | ||
Name: "KANISTER_REGISTERED_STATIC_ENVVAR", | ||
Value: "1", | ||
}, | ||
} | ||
|
||
var options corev1.Container | ||
|
||
var registeredAppliers ephemeral.ApplierList | ||
registeredAppliers.Register(ephemeral.StaticEnvVar(expected[0].Name, expected[0].Value)) | ||
registeredAppliers.Apply(&options) | ||
|
||
c.Assert(options.Env, DeepEquals, expected) | ||
} |