diff --git a/.forgejo/workflows/pr.yml b/.forgejo/workflows/pr.yml index d0c6bd1..a93d79b 100644 --- a/.forgejo/workflows/pr.yml +++ b/.forgejo/workflows/pr.yml @@ -19,17 +19,17 @@ jobs: id: test run: | go test -c - RUN_FOREVER=1 ./ovh-dns-update.test & + ACTION_TESTING=1 ./ovh-dns-update.test & sleep 1 ls . echo $GITHUB_OUTPUT - name: update a record uses: ./ with: - subdomain: sub + subdomain: _release domain: example.org - record-id: 123 - value: v=1.2.3 + record-id: 12345 + value: v=42 ovh-endpoint: ${{ steps.test.outputs.OVH_ENDPOINT }} ovh-app-key: KEY ovh-app-secret: SECRET diff --git a/main_test.go b/main_test.go index 5e1acf4..732068e 100644 --- a/main_test.go +++ b/main_test.go @@ -39,8 +39,6 @@ func TestRun(t *testing.T) { t.Cleanup(s.Close) action := githubactions.New(githubactions.WithGetenv(func(key string) string { switch key { - case "GITHUB_OUTPUT": - return os.Getenv(key) case "INPUT_OVH-ENDPOINT": return "http://" + s.Listener.Addr().String() } @@ -50,8 +48,32 @@ 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()) + + // for action testing (see .forgejo/workflows/pr.yml) + if os.Getenv("ACTION_TESTING") == "1" { + s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + default: + 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/example.org/record/12345": + buf, err := io.ReadAll(r.Body) + if err != nil { + msg := fmt.Sprintf("could not read request body: %v", err) + http.Error(w, msg, http.StatusBadRequest) + t.Error(msg) + } + if string(buf) != `{"subDomain":"_release","target":"\"v=1.42\""}` { + msg := fmt.Sprintf("unexpected body: %s", string(buf)) + http.Error(w, msg, http.StatusBadRequest) + t.Error(msg) + } + } + })) + t.Cleanup(s.Close) + githubactions.SetOutput("OVH_ENDPOINT", "http://"+s.Listener.Addr().String()) select {} } }