github.com/qiniu/go-sdk/v7@v7.27.0/storage/config_test.go (about)

     1  //go:build unit
     2  // +build unit
     3  
     4  package storage
     5  
     6  import (
     7  	"testing"
     8  )
     9  
    10  func TestReqHost(t *testing.T) {
    11  	zoneHuadong := Zone{
    12  		SrcUpHosts: []string{
    13  			"up.qiniup.com",
    14  			"up-nb.qiniup.com",
    15  			"up-xs.qiniup.com",
    16  		},
    17  		CdnUpHosts: []string{
    18  			"upload.qiniup.com",
    19  			"upload-nb.qiniup.com",
    20  			"upload-xs.qiniup.com",
    21  		},
    22  		RsHost:    "rs.qbox.me",
    23  		RsfHost:   "rsf.qbox.me",
    24  		ApiHost:   "api.qiniu.com",
    25  		IovipHost: "iovip.qbox.me",
    26  	}
    27  	cfgs := []Config{
    28  		{UseHTTPS: true, Zone: &zoneHuadong},
    29  		{UseHTTPS: true, RsHost: "http://rshost.com"},
    30  		{UseHTTPS: true, RsHost: "https://rshost.com"},
    31  		{UseHTTPS: true, Zone: &zoneHuadong, RsHost: "http://rshost.com"},
    32  		{UseHTTPS: false, Zone: &zoneHuadong},
    33  		{UseHTTPS: false, RsHost: "http://rshost.com"},
    34  		{UseHTTPS: false, RsHost: "https://rshost.com"},
    35  		{UseHTTPS: false, Zone: &zoneHuadong, RsHost: "http://rshost.com"},
    36  		{UseHTTPS: false, Region: &zoneHuadong, RsHost: "http://rshost.com"},
    37  	}
    38  	wantRsHosts := []string{
    39  		"https://rs.qbox.me",
    40  		"http://rshost.com",
    41  		"https://rshost.com",
    42  		"https://rs.qbox.me",
    43  		"http://rs.qbox.me",
    44  		"http://rshost.com",
    45  		"https://rshost.com",
    46  		"http://rs.qbox.me",
    47  		"http://rs.qbox.me",
    48  	}
    49  
    50  	for ind, cfg := range cfgs {
    51  		got := cfg.RsReqHost()
    52  		want := wantRsHosts[ind]
    53  		if got != want {
    54  			t.Errorf("ind = %d, want = %q, got = %q\n", ind, want, got)
    55  		}
    56  	}
    57  }