diff --git a/.forgejo/workflows/pr.yml b/.forgejo/workflows/pr.yml index 3fdc211..b91bbfa 100644 --- a/.forgejo/workflows/pr.yml +++ b/.forgejo/workflows/pr.yml @@ -31,3 +31,7 @@ jobs: ovh-app-key: APP_KEY ovh-app-secret: APP_SECRET ovh-consumer-key: CON_KEY + - name: check record update + run: | + echo ${{ steps.test.outputs.DNS_TXT }} + test ${{ steps.test.outputs.DNS_TXT }} = "v1.42" diff --git a/main_test.go b/main_test.go index 732068e..109a498 100644 --- a/main_test.go +++ b/main_test.go @@ -4,6 +4,7 @@ package main import ( + "encoding/json" "fmt" "io" "net/http" @@ -59,16 +60,22 @@ func TestRun(t *testing.T) { t.Error(msg) case "/auth/time": case "/domain/zone/example.org/record/12345": - buf, err := io.ReadAll(r.Body) + var body struct { + SubDomain string `json:"subDomain"` + Target string `json:"target"` + } + err := json.NewDecoder(r.Body).Decode(&body) if err != nil { - msg := fmt.Sprintf("could not read request body: %v", err) + msg := fmt.Sprintf("could not decode 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)) + if body.SubDomain != "_release" { + msg := fmt.Sprintf("unexpected subdomain: %s", body.SubDomain) http.Error(w, msg, http.StatusBadRequest) t.Error(msg) + } else { + githubactions.SetOutput("DNS_TXT", body.Target) } } }))