go-url-shortener/shortener/shortener_test.go
2023-12-25 11:08:11 +08:00

27 lines
622 B
Go

package shortener
import (
"testing"
"github.com/stretchr/testify/assert"
)
const userId = "7c729139-7ff4-445f-976b-2d842f55cb0e"
func TestGenerateShortLink(t *testing.T) {
link1 := "https://www.baidu.com/"
short1, err := GenerateShortLink(link1, userId)
assert.NoError(t, err)
assert.Equal(t, short1, "egtq236P5f3")
link2 := "https://www.163.com/"
short2, err := GenerateShortLink(link2, userId)
assert.NoError(t, err)
assert.Equal(t, short2, "DiCqg9YpV89")
link3 := "https://www.qq.com/"
short3, err := GenerateShortLink(link3, userId)
assert.NoError(t, err)
assert.Equal(t, short3, "4QhQ62cZem1")
}