github.com/qiniu/go-sdk/v7@v7.27.0/storage/endpoint_test.go (about) 1 //go:build unit 2 // +build unit 3 4 package storage 5 6 import ( 7 "testing" 8 ) 9 10 func TestEndpoint(t *testing.T) { 11 type input struct { 12 UseHttps bool 13 Host string 14 } 15 testInputs := []input{ 16 {UseHttps: true, Host: "rs.qiniu.com"}, 17 {UseHttps: false, Host: "rs.qiniu.com"}, 18 {UseHttps: true, Host: ""}, 19 {UseHttps: false, Host: ""}, 20 {UseHttps: true, Host: "https://rs.qiniu.com"}, 21 {UseHttps: false, Host: "https://rs.qiniu.com"}, 22 {UseHttps: false, Host: "http://rs.qiniu.com"}, 23 } 24 testWants := []string{ 25 "https://rs.qiniu.com", 26 "http://rs.qiniu.com", 27 "", 28 "", 29 "https://rs.qiniu.com", 30 "https://rs.qiniu.com", 31 "http://rs.qiniu.com", 32 } 33 34 for ind, testInput := range testInputs { 35 testGot := endpoint(testInput.UseHttps, testInput.Host) 36 testWant := testWants[ind] 37 if testGot != testWant { 38 t.Fatalf("index:%d Got:%s Want:%s", ind, testGot, testWant) 39 } 40 } 41 }