2022-10-03 12:31:16 +07:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/tls"
|
|
|
|
"fmt"
|
2024-01-18 19:58:13 +07:00
|
|
|
"os"
|
2022-10-03 12:31:16 +07:00
|
|
|
"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"},
|
|
|
|
{"gitea", "gitea"},
|
2023-11-27 18:53:19 +07:00
|
|
|
{"grafana", "grafana"},
|
2024-01-17 21:15:16 +07:00
|
|
|
{"homepage", "homepage"},
|
2024-01-06 00:40:20 +07:00
|
|
|
{"kanidm", "kanidm"},
|
2024-03-27 10:58:55 +07:00
|
|
|
{"zot", "zot"},
|
2022-10-03 12:31:16 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2022-12-24 13:34:40 +07:00
|
|
|
k8s.WaitUntilIngressAvailable(t, options, app.name, 30, 60*time.Second)
|
2022-10-03 12:31:16 +07:00
|
|
|
|
|
|
|
// 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{
|
2024-01-18 19:58:13 +07:00
|
|
|
InsecureSkipVerify: os.Getenv("INSECURE_SKIP_VERIFY") != "",
|
2022-10-03 12:31:16 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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,
|
2022-10-27 13:37:18 +07:00
|
|
|
60*time.Second,
|
2022-10-03 12:31:16 +07:00
|
|
|
func(statusCode int, body string) bool {
|
|
|
|
return statusCode == 200
|
|
|
|
},
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|