mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/khuedoan/homelab.git
synced 2026-09-20 08:03:58 +08:00
refactor: replace wait-main-apps script with Terratest test cases
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
.POSIX:
|
||||
|
||||
filter=.
|
||||
|
||||
default: test
|
||||
|
||||
test:
|
||||
gotestsum --format testname -- --timeout 30m
|
||||
gotestsum --format testname -- -timeout 30m -run "${filter}"
|
||||
|
||||
57
test/smoke_test.go
Normal file
57
test/smoke_test.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
http_helper "github.com/gruntwork-io/terratest/modules/http-helper"
|
||||
"github.com/gruntwork-io/terratest/modules/k8s"
|
||||
)
|
||||
|
||||
func TestSmoke(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var mainApps = []struct {
|
||||
name string
|
||||
namespace string
|
||||
}{
|
||||
{"argocd-server", "argocd"},
|
||||
{"hajimari", "hajimari"},
|
||||
{"vault", "vault"},
|
||||
{"gitea", "gitea"},
|
||||
}
|
||||
|
||||
for _, app := range mainApps {
|
||||
app := app // https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables
|
||||
t.Run(app.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
options := k8s.NewKubectlOptions("", "", app.namespace)
|
||||
|
||||
// Wait the service to become available to ensure that we can access it
|
||||
k8s.WaitUntilIngressAvailable(t, options, app.name, 10, 30*time.Second)
|
||||
|
||||
// Now we verify that the service will successfully boot and start serving requests
|
||||
ingress := k8s.GetIngress(t, options, app.name)
|
||||
|
||||
// Setup a TLS configuration, ignore the certificate because we may not use cert-manager (like the sandbox environment)
|
||||
tlsConfig := tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
}
|
||||
|
||||
// Test the endpoint, this will only fail if we timeout waiting for the service to return a 200 response
|
||||
http_helper.HttpGetWithRetryWithCustomValidation(
|
||||
t,
|
||||
fmt.Sprintf("https://%s", ingress.Spec.Rules[0].Host),
|
||||
&tlsConfig,
|
||||
30,
|
||||
30*time.Second,
|
||||
func(statusCode int, body string) bool {
|
||||
return statusCode == 200
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -31,9 +31,9 @@ func TestToolsVersions(t *testing.T) {
|
||||
|
||||
for _, tool := range tools {
|
||||
params := version_checker.CheckVersionParams{
|
||||
BinaryPath: tool.binaryPath,
|
||||
BinaryPath: tool.binaryPath,
|
||||
VersionConstraint: tool.versionConstraint,
|
||||
WorkingDir: ".",
|
||||
WorkingDir: ".",
|
||||
}
|
||||
|
||||
version_checker.CheckVersion(t, params)
|
||||
|
||||
Reference in New Issue
Block a user