mirror of
https://code.forgejo.org/actions/ovh-dns-update.git
synced 2024-11-22 08:01:00 -05:00
add test
This commit is contained in:
parent
dece0b62c5
commit
349b429900
1 changed files with 44 additions and 0 deletions
44
main_test.go
Normal file
44
main_test.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
// SPDX-FileCopyrightText: 2023 Olivier Charvin
|
||||
// SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/sethvargo/go-githubactions"
|
||||
)
|
||||
|
||||
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)
|
||||
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)
|
||||
}
|
||||
if string(buf) != `{"subDomain":"FAKEVALUE-INPUT_SUBDOMAIN","target":"\"FAKEVALUE-INPUT_VALUE\""}` {
|
||||
t.Errorf("unexpected body: %s", string(buf))
|
||||
}
|
||||
}
|
||||
}))
|
||||
t.Cleanup(s.Close)
|
||||
s.Listener.Addr()
|
||||
action := githubactions.New(githubactions.WithGetenv(func(key string) string {
|
||||
switch key {
|
||||
case "INPUT_OVH-ENDPOINT":
|
||||
return "http://" + s.Listener.Addr().String()
|
||||
}
|
||||
return "FAKEVALUE-" + key
|
||||
}))
|
||||
err := run(action)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue