Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
viveksinghggits committed Mar 24, 2020
1 parent d5a002b commit a622ea5
Showing 1 changed file with 41 additions and 10 deletions.
51 changes: 41 additions & 10 deletions pkg/kube/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"time"

. "gopkg.in/check.v1"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -62,17 +62,48 @@ func (s *PodSuite) TearDownSuite(c *C) {
}

func (s *PodSuite) TestPod(c *C) {
// get controllers's namespace
cns, err := GetControllerNamespace()
c.Assert(err, IsNil)

// get controller's SA
sa, err := GetControllerServiceAccount(s.cli)
c.Assert(err, IsNil)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
pod, err := CreatePod(context.Background(), s.cli, &PodOptions{
Namespace: s.namespace,
GenerateName: "test-",
Image: "kanisterio/kanister-tools:0.28.0",
Command: []string{"sh", "-c", "tail -f /dev/null"},
})
c.Assert(err, IsNil)
c.Assert(WaitForPodReady(ctx, s.cli, s.namespace, pod.Name), IsNil)
c.Assert(DeletePod(context.Background(), s.cli, pod), IsNil)

podOptions := []*PodOptions{
{
Namespace: s.namespace,
GenerateName: "test-",
Image: "kanisterio/kanister-tools:0.28.0",
Command: []string{"sh", "-c", "tail -f /dev/null"},
},
{
Namespace: s.namespace,
GenerateName: "test-",
Image: "kanisterio/kanister-tools:0.28.0",
Command: []string{"sh", "-c", "tail -f /dev/null"},
ServiceAccountName: "dummy-sa",
},
}

for _, po := range podOptions {
pod, err := CreatePod(context.Background(), s.cli, po)

// we have not specified the SA, if the pod is being created in the
// same ns as controller's, controller's SA should have been set.
if po.ServiceAccountName != "" && s.namespace == cns {
c.Assert(pod.Spec.ServiceAccountName, Equals, sa)
} else {
c.Assert(pod.Spec.ServiceAccountName, Equals, po.ServiceAccountName)
}

c.Assert(err, IsNil)
c.Assert(WaitForPodReady(ctx, s.cli, s.namespace, pod.Name), IsNil)
c.Assert(DeletePod(context.Background(), s.cli, pod), IsNil)
}
}

func (s *PodSuite) TestPodWithVolumes(c *C) {
Expand Down

0 comments on commit a622ea5

Please sign in to comment.