Skip to content

Commit

Permalink
test: adding test for init validation (#629)
Browse files Browse the repository at this point in the history
  • Loading branch information
smritidahal653 authored Aug 2, 2024
1 parent c18ceab commit 2b01145
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmd/init-container/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,21 @@ import (
"k8s.io/client-go/util/retry"
)

var (
logLevel = "info"
)

func main() {
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()

logger := logrus.StandardLogger()
lvl, err := logrus.ParseLevel(logLevel)
if err != nil {
logrus.WithError(err).Fatal("Error parsing log level")
}
logger.SetLevel(lvl)

log.L = logruslogger.FromLogrus(logrus.NewEntry(logger))

log.G(ctx).Debug("Init container started")
Expand Down
27 changes: 27 additions & 0 deletions e2e/initvalidation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package e2e

import (
"strings"
"testing"
)

func TestInitVaidationContainer(t *testing.T) {
cmd := kubectl("get", "pod", "-l", "app=aci-connector-linux", "-n", "kube-system", "-o", "jsonpath={.items[1].status.phase}")

out, err := cmd.CombinedOutput()
if err != nil {
t.Fatal(string(out))
}
if string(out) != "Running" {
t.Fatal("pod is not in running state")
}

cmd = kubectl("logs", "-l", "app=aci-connector-linux", "-c", "init-validation", "-n", "kube-system", "--tail=1")
logOut, logErr := cmd.CombinedOutput()
if logErr != nil {
t.Fatal(string(out))
}
if !strings.Contains(string(logOut), "initial setup for virtual kubelet Azure ACI is successful") {
t.Fatalf("init container setup is not successful. log: %s", string(logOut))
}
}

0 comments on commit 2b01145

Please sign in to comment.