1
0
Fork 0
mirror of https://code.forgejo.org/actions/ovh-dns-update synced 2025-03-14 22:36:58 +01:00

nicer test

This commit is contained in:
oliverpool 2023-08-18 16:20:01 +02:00
parent c1afe4c4a7
commit 95e1d4e7d1
2 changed files with 30 additions and 8 deletions

View file

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

View file

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