t.Errorf("Test %d: Expected isVirtualHostSupported to be '%v' for input url \"%s\" and bucket \"%s\", but found it to be '%v' instead",i+1,testCase.result,testCase.url,testCase.bucket,result)
}
}
}
// Tests validate Amazon endpoint validator.
funcTestIsAmazonEndpoint(t*testing.T){
testCases:=[]struct{
urlstring
// Expected result.
resultbool
}{
{"https://192.168.1.1",false},
{"192.168.1.1",false},
{"http://storage.googleapis.com",false},
{"https://storage.googleapis.com",false},
{"storage.googleapis.com",false},
{"s3.amazonaws.com",false},
{"https://amazons3.amazonaws.com",false},
{"-192.168.1.1",false},
{"260.192.1.1",false},
// valid inputs.
{"https://s3.amazonaws.com",true},
{"https://s3.cn-north-1.amazonaws.com.cn",true},
}
fori,testCase:=rangetestCases{
u,err:=url.Parse(testCase.url)
iferr!=nil{
t.Errorf("Test %d: Expected to pass, but failed with: <ERROR> %s",i+1,err)
}
result:=IsAmazonEndpoint(*u)
iftestCase.result!=result{
t.Errorf("Test %d: Expected isAmazonEndpoint to be '%v' for input \"%s\", but found it to be '%v' instead",i+1,testCase.result,testCase.url,result)
}
}
}
// Tests validate Amazon S3 China endpoint validator.
funcTestIsAmazonChinaEndpoint(t*testing.T){
testCases:=[]struct{
urlstring
// Expected result.
resultbool
}{
{"https://192.168.1.1",false},
{"192.168.1.1",false},
{"http://storage.googleapis.com",false},
{"https://storage.googleapis.com",false},
{"storage.googleapis.com",false},
{"s3.amazonaws.com",false},
{"https://amazons3.amazonaws.com",false},
{"-192.168.1.1",false},
{"260.192.1.1",false},
// s3.amazonaws.com is not a valid Amazon S3 China end point.
{"https://s3.amazonaws.com",false},
// valid input.
{"https://s3.cn-north-1.amazonaws.com.cn",true},
}
fori,testCase:=rangetestCases{
u,err:=url.Parse(testCase.url)
iferr!=nil{
t.Errorf("Test %d: Expected to pass, but failed with: <ERROR> %s",i+1,err)
}
result:=IsAmazonChinaEndpoint(*u)
iftestCase.result!=result{
t.Errorf("Test %d: Expected isAmazonEndpoint to be '%v' for input \"%s\", but found it to be '%v' instead",i+1,testCase.result,testCase.url,result)
}
}
}
// Tests validate Google Cloud end point validator.
funcTestIsGoogleEndpoint(t*testing.T){
testCases:=[]struct{
urlstring
// Expected result.
resultbool
}{
{"192.168.1.1",false},
{"https://192.168.1.1",false},
{"s3.amazonaws.com",false},
{"http://s3.amazonaws.com",false},
{"https://s3.amazonaws.com",false},
{"https://s3.cn-north-1.amazonaws.com.cn",false},
{"-192.168.1.1",false},
{"260.192.1.1",false},
// valid inputs.
{"http://storage.googleapis.com",true},
{"https://storage.googleapis.com",true},
}
fori,testCase:=rangetestCases{
u,err:=url.Parse(testCase.url)
iferr!=nil{
t.Errorf("Test %d: Expected to pass, but failed with: <ERROR> %s",i+1,err)
}
result:=IsGoogleEndpoint(*u)
iftestCase.result!=result{
t.Errorf("Test %d: Expected isGoogleEndpoint to be '%v' for input \"%s\", but found it to be '%v' instead",i+1,testCase.result,testCase.url,result)