48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package shortUrlMgr
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestShortUrl(t *testing.T) {
|
|
// ShortUrl_SERVICE_URL = "http://a.app366.com/get"
|
|
|
|
appId := "unittest"
|
|
appId_wrong := "wrong"
|
|
appSecret := "c5746980-5d52-4ba9-834f-13d0066ad1d0"
|
|
appSecret_wrong := "wrong"
|
|
fullUrl := "http://unittest.PlayerId=123&Name=Jordan"
|
|
fullUrl_wrong := ""
|
|
timeout := 3
|
|
|
|
// Test with wrong AppId
|
|
shortUrl, err := GetShortUrl(appId_wrong, appSecret, fullUrl, timeout)
|
|
if err == nil {
|
|
t.Errorf("There should be an error, but now there is no error")
|
|
return
|
|
}
|
|
|
|
// Test with wrong AppSecret
|
|
shortUrl, err = GetShortUrl(appId, appSecret_wrong, fullUrl, timeout)
|
|
if err == nil {
|
|
t.Errorf("There should be an error, but now there is no error")
|
|
return
|
|
}
|
|
|
|
// Test with wrong FullUrl
|
|
shortUrl, err = GetShortUrl(appId, appSecret, fullUrl_wrong, timeout)
|
|
if err == nil {
|
|
t.Errorf("There should be an error, but now there is no error")
|
|
return
|
|
}
|
|
|
|
// Test with correct information and domestic ip
|
|
shortUrl, err = GetShortUrl(appId, appSecret, fullUrl, timeout)
|
|
if err != nil {
|
|
t.Errorf("There should be no error, but now there is one:%s", err)
|
|
return
|
|
}
|
|
fmt.Printf("shortUrl:%v\n", shortUrl)
|
|
}
|