mirror of
https://code.forgejo.org/actions/ovh-dns-update
synced 2025-03-15 06:46:59 +01:00
run test
This commit is contained in:
parent
3ec0204437
commit
cb09b4af4d
2 changed files with 23 additions and 3 deletions
|
@ -15,8 +15,16 @@ jobs:
|
||||||
with:
|
with:
|
||||||
go-version: ">=1.21"
|
go-version: ">=1.21"
|
||||||
check-latest: true
|
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
|
- name: update a record
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
subdomain: /tmp/website
|
subdomain: /tmp/website
|
||||||
|
ovh-endpoint: ${{ steps.test.outputs.OVH_ENDPOINT }}
|
||||||
# TODO: verify it runned
|
# TODO: verify it runned
|
18
main_test.go
18
main_test.go
|
@ -4,9 +4,11 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/sethvargo/go-githubactions"
|
"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) {
|
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
switch r.URL.Path {
|
switch r.URL.Path {
|
||||||
default:
|
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 "/auth/time":
|
||||||
case "/domain/zone/FAKEVALUE-INPUT_DOMAIN/record/FAKEVALUE-INPUT_RECORD-ID":
|
case "/domain/zone/FAKEVALUE-INPUT_DOMAIN/record/FAKEVALUE-INPUT_RECORD-ID":
|
||||||
buf, err := io.ReadAll(r.Body)
|
buf, err := io.ReadAll(r.Body)
|
||||||
if err != nil {
|
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\""}` {
|
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 {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
if os.Getenv("RUN_FOREVER") == "1" {
|
||||||
|
action.SetOutput("OVH_ENDPOINT", "http://"+s.Listener.Addr().String())
|
||||||
|
select {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue