···4141 @temporal workflow result --workflow-id apps-manual
42424343test:
4444- cd test && go test
4444+ cd test && CLOUDLAB_ENV=${env} go test
45454646fmt:
4747 nixfmt flake.nix
+67-10
test/smoke_test.go
···11package e2e
2233import (
44+ "errors"
45 "net/http"
66+ "os"
57 "testing"
68)
7988-func TestBlog(t *testing.T) {
99- resp, err := http.Get("https://khuedoan.com") // TODO get domain name automatically
1010+func assertStatusCode(t *testing.T, url string, expectedStatusCode int) {
1111+ t.Helper()
1212+ assertStatusCodeWithRedirects(t, url, true, expectedStatusCode)
1313+}
1414+1515+func assertStatusCodeWithRedirects(t *testing.T, url string, followRedirects bool, expectedStatusCodes ...int) {
1616+ t.Helper()
1717+1818+ client := &http.Client{}
1919+ if !followRedirects {
2020+ client.CheckRedirect = func(_ *http.Request, _ []*http.Request) error {
2121+ return http.ErrUseLastResponse
2222+ }
2323+ }
2424+2525+ resp, err := client.Get(url)
1026 if err != nil {
2727+ if !errors.Is(err, http.ErrUseLastResponse) {
2828+ t.Fatal(err)
2929+ }
3030+ }
3131+3232+ if resp == nil {
1133 t.Fatal(err)
1234 }
1335 defer resp.Body.Close()
14361515- if resp.StatusCode != http.StatusOK {
1616- t.Fatalf("expected status code to be 200, but got %d", resp.StatusCode)
3737+ for _, expectedStatusCode := range expectedStatusCodes {
3838+ if resp.StatusCode == expectedStatusCode {
3939+ return
4040+ }
1741 }
4242+4343+ t.Fatalf("expected status code %v, but got %d for %s", expectedStatusCodes, resp.StatusCode, url)
4444+}
4545+4646+func TestBlog(t *testing.T) {
4747+ assertStatusCode(t, "https://khuedoan.com", http.StatusOK) // TODO get domain name automatically
1848}
19492050func TestHomelabDocs(t *testing.T) {
2121- resp, err := http.Get("https://homelab.khuedoan.com") // TODO get domain name automatically
2222- if err != nil {
2323- t.Fatal(err)
5151+ assertStatusCode(t, "https://homelab.khuedoan.com", http.StatusOK) // TODO get domain name automatically
5252+}
5353+5454+// TODO remove env-specific stuff once we migrate everything to the same setup
5555+func TestStaging(t *testing.T) {
5656+ if os.Getenv("CLOUDLAB_ENV") != "staging" && os.Getenv("SMOKE_STAGING") == "" {
5757+ t.Skip("set CLOUDLAB_ENV=staging or SMOKE_STAGING=1 to run staging smoke tests")
2458 }
2525- defer resp.Body.Close()
26592727- if resp.StatusCode != http.StatusOK {
2828- t.Fatalf("expected status code to be 200, but got %d", resp.StatusCode)
6060+ testCases := []struct {
6161+ name string
6262+ url string
6363+ expectedStatusCode int
6464+ }{
6565+ {
6666+ name: "Vault",
6767+ url: "https://vault.staging.khuedoan.com",
6868+ expectedStatusCode: http.StatusTemporaryRedirect,
6969+ },
7070+ {
7171+ name: "Dex",
7272+ url: "https://dex.staging.khuedoan.com",
7373+ expectedStatusCode: http.StatusOK,
7474+ },
7575+ {
7676+ name: "Forgejo",
7777+ url: "https://code.staging.khuedoan.com",
7878+ expectedStatusCode: http.StatusSeeOther,
7979+ },
8080+ }
8181+8282+ for _, testCase := range testCases {
8383+ t.Run(testCase.name, func(t *testing.T) {
8484+ assertStatusCodeWithRedirects(t, testCase.url, false, testCase.expectedStatusCode)
8585+ })
2986 }
3087}