this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

test: additional test cases

+68 -11
+1 -1
Makefile
··· 41 41 @temporal workflow result --workflow-id apps-manual 42 42 43 43 test: 44 - cd test && go test 44 + cd test && CLOUDLAB_ENV=${env} go test 45 45 46 46 fmt: 47 47 nixfmt flake.nix
+67 -10
test/smoke_test.go
··· 1 1 package e2e 2 2 3 3 import ( 4 + "errors" 4 5 "net/http" 6 + "os" 5 7 "testing" 6 8 ) 7 9 8 - func TestBlog(t *testing.T) { 9 - resp, err := http.Get("https://khuedoan.com") // TODO get domain name automatically 10 + func assertStatusCode(t *testing.T, url string, expectedStatusCode int) { 11 + t.Helper() 12 + assertStatusCodeWithRedirects(t, url, true, expectedStatusCode) 13 + } 14 + 15 + func assertStatusCodeWithRedirects(t *testing.T, url string, followRedirects bool, expectedStatusCodes ...int) { 16 + t.Helper() 17 + 18 + client := &http.Client{} 19 + if !followRedirects { 20 + client.CheckRedirect = func(_ *http.Request, _ []*http.Request) error { 21 + return http.ErrUseLastResponse 22 + } 23 + } 24 + 25 + resp, err := client.Get(url) 10 26 if err != nil { 27 + if !errors.Is(err, http.ErrUseLastResponse) { 28 + t.Fatal(err) 29 + } 30 + } 31 + 32 + if resp == nil { 11 33 t.Fatal(err) 12 34 } 13 35 defer resp.Body.Close() 14 36 15 - if resp.StatusCode != http.StatusOK { 16 - t.Fatalf("expected status code to be 200, but got %d", resp.StatusCode) 37 + for _, expectedStatusCode := range expectedStatusCodes { 38 + if resp.StatusCode == expectedStatusCode { 39 + return 40 + } 17 41 } 42 + 43 + t.Fatalf("expected status code %v, but got %d for %s", expectedStatusCodes, resp.StatusCode, url) 44 + } 45 + 46 + func TestBlog(t *testing.T) { 47 + assertStatusCode(t, "https://khuedoan.com", http.StatusOK) // TODO get domain name automatically 18 48 } 19 49 20 50 func TestHomelabDocs(t *testing.T) { 21 - resp, err := http.Get("https://homelab.khuedoan.com") // TODO get domain name automatically 22 - if err != nil { 23 - t.Fatal(err) 51 + assertStatusCode(t, "https://homelab.khuedoan.com", http.StatusOK) // TODO get domain name automatically 52 + } 53 + 54 + // TODO remove env-specific stuff once we migrate everything to the same setup 55 + func TestStaging(t *testing.T) { 56 + if os.Getenv("CLOUDLAB_ENV") != "staging" && os.Getenv("SMOKE_STAGING") == "" { 57 + t.Skip("set CLOUDLAB_ENV=staging or SMOKE_STAGING=1 to run staging smoke tests") 24 58 } 25 - defer resp.Body.Close() 26 59 27 - if resp.StatusCode != http.StatusOK { 28 - t.Fatalf("expected status code to be 200, but got %d", resp.StatusCode) 60 + testCases := []struct { 61 + name string 62 + url string 63 + expectedStatusCode int 64 + }{ 65 + { 66 + name: "Vault", 67 + url: "https://vault.staging.khuedoan.com", 68 + expectedStatusCode: http.StatusTemporaryRedirect, 69 + }, 70 + { 71 + name: "Dex", 72 + url: "https://dex.staging.khuedoan.com", 73 + expectedStatusCode: http.StatusOK, 74 + }, 75 + { 76 + name: "Forgejo", 77 + url: "https://code.staging.khuedoan.com", 78 + expectedStatusCode: http.StatusSeeOther, 79 + }, 80 + } 81 + 82 + for _, testCase := range testCases { 83 + t.Run(testCase.name, func(t *testing.T) { 84 + assertStatusCodeWithRedirects(t, testCase.url, false, testCase.expectedStatusCode) 85 + }) 29 86 } 30 87 }