Skip to content

Commit 5d691f4

Browse files
committed
feat: add integration tests
1 parent f81204e commit 5d691f4

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Integration Tests
2+
3+
on: [push]
4+
5+
jobs:
6+
build-and-deploy:
7+
runs-on: ubuntu-22.04
8+
9+
steps:
10+
- name: Set up k3d
11+
run: |
12+
curl -s https://raw.githubusercontent.com/rancher/k3d/main/install.sh | bash
13+
k3d cluster create test-cluster
14+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
15+
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
16+
kubectl version
17+
kubectl get nodes
18+
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
with:
22+
path: project
23+
24+
- name: Build nginx-supportpkg binary
25+
run: |
26+
cd project
27+
go build -o nginx-supportpkg
28+
chmod +x nginx-supportpkg
29+
cp nginx-supportpkg /usr/local/bin/
30+
kubectl nginx-supportpkg
31+
32+
- name: Run tests
33+
run: go test ./tests -v

tests/supportpkg_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package tests
2+
3+
import (
4+
"bytes"
5+
"os/exec"
6+
"strings"
7+
"testing"
8+
)
9+
10+
func TestKubectlCommands(t *testing.T) {
11+
// Execute `kubectl` command
12+
cmd := exec.Command("kubectl", "nginx-supportpkg")
13+
var stdout, stderr bytes.Buffer
14+
cmd.Stdout = &stdout
15+
cmd.Stderr = &stderr
16+
_ = cmd.Run()
17+
18+
// Compare the output with expected result
19+
expectedOutput := "required flag(s)"
20+
actualOutput := stdout.String()
21+
if !strings.Contains(actualOutput, expectedOutput) {
22+
t.Errorf("Expected output should contain \"%s\" but got \"%s\"", expectedOutput, actualOutput)
23+
}
24+
}

0 commit comments

Comments
 (0)