Skip to content

Commit

Permalink
Added test for registering env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
kidgilson committed May 8, 2024
1 parent 3226d12 commit f9c1f5a
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions pkg/ephemeral/envvar_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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) TestRegisteringOSEnvVar(c *C) {
expected := []corev1.EnvVar{
{
Name: "KANISTER_REGISTERED_OS_ENVVAR",
Value: "1",
},
}

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) TestRegisteringStaticEnvVar(c *C) {
expected := []corev1.EnvVar{
{
Name: "KANISTER_REGISTERED_STATIC_ENVVAR",
Value: "1",
},
}

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)
}

0 comments on commit f9c1f5a

Please sign in to comment.