From 5972bb817c3de0059098431dda2c6ade1ec27442 Mon Sep 17 00:00:00 2001 From: justinsb Date: Sat, 12 Oct 2024 07:52:13 -0400 Subject: [PATCH] bare-metal: add some go tests to start to verify functionality --- tests/e2e/scenarios/bare-metal/e2e_test.go | 41 ++++++++++++++++++++++ tests/e2e/scenarios/bare-metal/run-test | 5 +++ 2 files changed, 46 insertions(+) create mode 100644 tests/e2e/scenarios/bare-metal/e2e_test.go diff --git a/tests/e2e/scenarios/bare-metal/e2e_test.go b/tests/e2e/scenarios/bare-metal/e2e_test.go new file mode 100644 index 0000000000000..dcba47f12bc16 --- /dev/null +++ b/tests/e2e/scenarios/bare-metal/e2e_test.go @@ -0,0 +1,41 @@ +package bare_metal + +import ( + "context" + "os" + "path/filepath" + "testing" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/client-go/kubernetes" + "k8s.io/client-go/tools/clientcmd" +) + +func TestNodeAddresses(t *testing.T) { + ctx := context.Background() + + kubeconfig := os.Getenv("KUBECONFIG") + if kubeconfig == "" { + homeDir, err := os.UserHomeDir() + if err != nil { + t.Fatalf("error getting user home dir: %v", err) + } + kubeconfig = filepath.Join(homeDir, ".kube", "config") + } + // use the current context in kubeconfig + restConfig, err := clientcmd.BuildConfigFromFlags("", kubeconfig) + if err != nil { + t.Fatalf("error building rest config: %v", err) + } + + client := kubernetes.NewForConfigOrDie(restConfig) + + nodes, err := client.CoreV1().Nodes().List(ctx, metav1.ListOptions{}) + if err != nil { + t.Fatalf("error listing nodes: %v", err) + } + + for _, node := range nodes.Items { + t.Logf("node: %s", node.Name) + } +} diff --git a/tests/e2e/scenarios/bare-metal/run-test b/tests/e2e/scenarios/bare-metal/run-test index c3da8254703aa..591377e2bf0e8 100755 --- a/tests/e2e/scenarios/bare-metal/run-test +++ b/tests/e2e/scenarios/bare-metal/run-test @@ -213,7 +213,12 @@ echo "Waiting 30 seconds for nodes to be ready" sleep 30 kubectl get nodes +kubectl get nodes -o yaml + kubectl get pods -A +echo "running e2e tests" +cd ${REPO_ROOT}/tests/e2e/scenarios/bare-metal +go test -v . echo "Test successful" \ No newline at end of file