diff --git a/.forgejo/workflows/pr.yml b/.forgejo/workflows/pr.yml index df4d707..0f13a5d 100644 --- a/.forgejo/workflows/pr.yml +++ b/.forgejo/workflows/pr.yml @@ -15,8 +15,16 @@ jobs: with: go-version: ">=1.21" check-latest: true + - name: run the fake API server + id: test + run: | + go test -o=gotest + ls . + RUN_FOREVER=1 gotest & + sleep 1 - name: update a record uses: ./ with: subdomain: /tmp/website + ovh-endpoint: ${{ steps.test.outputs.OVH_ENDPOINT }} # TODO: verify it runned \ No newline at end of file diff --git a/main_test.go b/main_test.go index 75fe7e0..418e6b6 100644 --- a/main_test.go +++ b/main_test.go @@ -4,9 +4,11 @@ package main import ( + "fmt" "io" "net/http" "net/http/httptest" + "os" "testing" "github.com/sethvargo/go-githubactions" @@ -16,15 +18,21 @@ func TestRun(t *testing.T) { s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { switch r.URL.Path { default: - t.Errorf("unexpected request on %s", r.URL.Path) + msg := fmt.Sprintf("unexpected request on %s", r.URL.Path) + http.Error(w, msg, http.StatusBadRequest) + t.Error(msg) case "/auth/time": case "/domain/zone/FAKEVALUE-INPUT_DOMAIN/record/FAKEVALUE-INPUT_RECORD-ID": buf, err := io.ReadAll(r.Body) if err != nil { - t.Errorf("could not read request body: %v", err) + msg := fmt.Sprintf("could not read request body: %v", err) + http.Error(w, msg, http.StatusBadRequest) + t.Error(msg) } if string(buf) != `{"subDomain":"FAKEVALUE-INPUT_SUBDOMAIN","target":"\"FAKEVALUE-INPUT_VALUE\""}` { - t.Errorf("unexpected body: %s", string(buf)) + msg := fmt.Sprintf("unexpected body: %s", string(buf)) + http.Error(w, msg, http.StatusBadRequest) + t.Error(msg) } } })) @@ -40,4 +48,8 @@ func TestRun(t *testing.T) { if err != nil { t.Fatal(err) } + if os.Getenv("RUN_FOREVER") == "1" { + action.SetOutput("OVH_ENDPOINT", "http://"+s.Listener.Addr().String()) + select {} + } }