-
Notifications
You must be signed in to change notification settings - Fork 242
/
Copy pathcommon_test.go
44 lines (40 loc) · 1.32 KB
/
common_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package hostnames
import (
"context"
"net/http"
"testing"
"github.com/h2non/gock"
"github.com/stretchr/testify/assert"
)
func TestVerifyCNAME(t *testing.T) {
defer gock.OffAll()
gock.New("https://1.1.1.1").
Get("/dns-query").
MatchParam("name", "hello.custom-domain.com").
MatchParam("type", "5").
MatchHeader("accept", "application/dns-json").
Reply(http.StatusOK).
JSON(&map[string]interface{}{"Answer": []map[string]interface{}{
{
"Type": 5, "Data": "foobarbaz.supabase.co.",
},
}})
err := VerifyCNAME(context.Background(), "foobarbaz", "hello.custom-domain.com")
assert.Empty(t, err)
}
func TestVerifyCNAMEFailures(t *testing.T) {
defer gock.OffAll()
gock.New("https://1.1.1.1").
Get("/dns-query").
MatchParam("name", "hello.custom-domain.com").
MatchParam("type", "5").
MatchHeader("accept", "application/dns-json").
Reply(http.StatusOK).
JSON(&map[string]interface{}{"Answer": []map[string]interface{}{
{
"Type": 28, "Data": "127.0.0.1",
},
}})
err := VerifyCNAME(context.Background(), "foobarbaz", "hello.custom-domain.com")
assert.ErrorContains(t, err, "expected custom hostname 'hello.custom-domain.com' to have a CNAME record pointing to your project at 'foobarbaz.supabase.co.', but it failed to resolve: failed to locate appropriate CNAME record for hello.custom-domain.com")
}