github.com/supabase/cli@v1.168.1/internal/hostnames/common_test.go (about) 1 package hostnames 2 3 import ( 4 "context" 5 "net/http" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 "gopkg.in/h2non/gock.v1" 10 ) 11 12 func TestVerifyCNAME(t *testing.T) { 13 defer gock.OffAll() 14 gock.New("https://1.1.1.1"). 15 Get("/dns-query"). 16 MatchParam("name", "hello.custom-domain.com"). 17 MatchParam("type", "5"). 18 MatchHeader("accept", "application/dns-json"). 19 Reply(http.StatusOK). 20 JSON(&map[string]interface{}{"Answer": []map[string]interface{}{ 21 { 22 "Type": 5, "Data": "foobarbaz.supabase.co.", 23 }, 24 }}) 25 err := VerifyCNAME(context.Background(), "foobarbaz", "hello.custom-domain.com") 26 assert.Empty(t, err) 27 } 28 29 func TestVerifyCNAMEFailures(t *testing.T) { 30 defer gock.OffAll() 31 gock.New("https://1.1.1.1"). 32 Get("/dns-query"). 33 MatchParam("name", "hello.custom-domain.com"). 34 MatchParam("type", "5"). 35 MatchHeader("accept", "application/dns-json"). 36 Reply(http.StatusOK). 37 JSON(&map[string]interface{}{"Answer": []map[string]interface{}{ 38 { 39 "Type": 28, "Data": "127.0.0.1", 40 }, 41 }}) 42 err := VerifyCNAME(context.Background(), "foobarbaz", "hello.custom-domain.com") 43 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") 44 }