Skip to content

Commit

Permalink
bare-metal: add some go tests to start to verify functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
justinsb committed Oct 12, 2024
1 parent e604939 commit 5972bb8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/e2e/scenarios/bare-metal/e2e_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
5 changes: 5 additions & 0 deletions tests/e2e/scenarios/bare-metal/run-test
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 5972bb8

Please sign in to comment.