github.com/qri-io/qri@v0.10.1-0.20220104210721-c771715036cb/api/transports_test.go (about) 1 package api 2 3 import ( 4 "net/http" 5 "testing" 6 ) 7 8 func TestHTTPSRedirect(t *testing.T) { 9 HTTPSRedirect("foobar") 10 11 go HTTPSRedirect(":5432") 12 13 cli := http.Client{ 14 CheckRedirect: func(req *http.Request, via []*http.Request) error { 15 if req.URL.String() != "https://localhost:5432/foo" { 16 t.Errorf("expected to be redirect to https. got: %s", req.URL.String()) 17 } 18 if req.Response.StatusCode != http.StatusMovedPermanently { 19 t.Errorf("expected permanent redirect. got: %d", req.Response.StatusCode) 20 } 21 return nil 22 }, 23 } 24 25 req, _ := http.NewRequest("GET", "http://localhost:5432/foo", nil) 26 cli.Do(req) 27 }