mirror of
https://code.forgejo.org/actions/ovh-dns-update
synced 2025-03-15 06:46:59 +01:00
nicer test
This commit is contained in:
parent
c1afe4c4a7
commit
95e1d4e7d1
2 changed files with 30 additions and 8 deletions
|
@ -19,17 +19,17 @@ jobs:
|
||||||
id: test
|
id: test
|
||||||
run: |
|
run: |
|
||||||
go test -c
|
go test -c
|
||||||
RUN_FOREVER=1 ./ovh-dns-update.test &
|
ACTION_TESTING=1 ./ovh-dns-update.test &
|
||||||
sleep 1
|
sleep 1
|
||||||
ls .
|
ls .
|
||||||
echo $GITHUB_OUTPUT
|
echo $GITHUB_OUTPUT
|
||||||
- name: update a record
|
- name: update a record
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
subdomain: sub
|
subdomain: _release
|
||||||
domain: example.org
|
domain: example.org
|
||||||
record-id: 123
|
record-id: 12345
|
||||||
value: v=1.2.3
|
value: v=42
|
||||||
ovh-endpoint: ${{ steps.test.outputs.OVH_ENDPOINT }}
|
ovh-endpoint: ${{ steps.test.outputs.OVH_ENDPOINT }}
|
||||||
ovh-app-key: KEY
|
ovh-app-key: KEY
|
||||||
ovh-app-secret: SECRET
|
ovh-app-secret: SECRET
|
||||||
|
|
30
main_test.go
30
main_test.go
|
@ -39,8 +39,6 @@ func TestRun(t *testing.T) {
|
||||||
t.Cleanup(s.Close)
|
t.Cleanup(s.Close)
|
||||||
action := githubactions.New(githubactions.WithGetenv(func(key string) string {
|
action := githubactions.New(githubactions.WithGetenv(func(key string) string {
|
||||||
switch key {
|
switch key {
|
||||||
case "GITHUB_OUTPUT":
|
|
||||||
return os.Getenv(key)
|
|
||||||
case "INPUT_OVH-ENDPOINT":
|
case "INPUT_OVH-ENDPOINT":
|
||||||
return "http://" + s.Listener.Addr().String()
|
return "http://" + s.Listener.Addr().String()
|
||||||
}
|
}
|
||||||
|
@ -50,8 +48,32 @@ 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())
|
// 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 {}
|
select {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue