1
0
Fork 0
mirror of https://code.forgejo.org/actions/ovh-dns-update synced 2025-03-15 06:46:59 +01:00
This commit is contained in:
oliverpool 2023-08-18 16:07:50 +02:00
parent 3ec0204437
commit cb09b4af4d
2 changed files with 23 additions and 3 deletions

View file

@ -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

View file

@ -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 {}
}
}