123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- package utils_test
-
- import (
- "wechat-conf/utils"
- "strings"
- "testing"
- "time"
- )
-
- func TestStrSliceIndexOf(t *testing.T) {
- cases := []map[string]interface{}{
- map[string]interface{}{
- "case": []string{"a", "b", "c"},
- "expected": int64(1),
- },
- map[string]interface{}{
- "case": []string{"aa", "bb", "cc"},
- "expected": int64(-1),
- },
- }
-
- for _, cs := range cases {
- td := cs["case"].([]string)
- ex := cs["expected"].(int64)
-
- res := utils.StrSliceIndexOf(td, "b")
-
- if ex != res {
- t.Fatalf("TestStrSliceIndexOf case fail : %v", res)
- }
- }
- }
-
- func TestGUIID2IntString(t *testing.T) {
- cases := []map[string]string{
- map[string]string{
- "case": "3b2da085-8881-4029-9a3d-6d33caf870d0",
- "expected": "553-217-207-305-861",
- },
- }
-
- for _, cs := range cases {
- res := utils.GUIID2IntString(cs["case"])
- if strings.Join(res, "-") != cs["expected"] {
- t.Fatalf("TestGUIID2IntString fail")
- }
- }
-
- }
-
- func TestEncodeBase64TrimTail(t *testing.T) {
- cases := []map[string]string{
- map[string]string{
- "case": "1",
- "expected": "MQ",
- },
- map[string]string{
- "case": "111",
- "expected": "MTEx",
- },
- }
-
- for _, cs := range cases {
- res := utils.EncodeBase64TrimTail(cs["case"])
- if res != cs["expected"] {
- t.Fatalf("TestEncodeBase64TrimTail fail")
- }
- }
- }
-
- func TestDecodeBase64NoTail(t *testing.T) {
- cases := []map[string]string{
- map[string]string{
- "case": "MQ",
- "expected": "1",
- },
- map[string]string{
- "case": "MTEx",
- "expected": "111",
- },
- }
-
- for _, cs := range cases {
- res := utils.DecodeBase64NoTail(cs["case"])
- if res != cs["expected"] {
- t.Fatalf("TestDecodeBase64NoTail fail : %s", cs["case"])
- }
- }
- }
-
- func TestGetFiveSeconds(t *testing.T) {
- cases := []map[string]string{
- map[string]string{
- "case": "2018-10-07 13:21:40",
- "expected": "20181007132140",
- },
- map[string]string{
- "case": "2018-10-07 13:21:42",
- "expected": "20181007132140",
- },
- map[string]string{
- "case": "2018-10-07 13:21:45",
- "expected": "20181007132145",
- },
- map[string]string{
- "case": "2018-10-07 13:21:48",
- "expected": "20181007132145",
- },
- }
-
- for _, cs := range cases {
- dt, _ := time.Parse("2006-01-02 15:04:05", cs["case"])
- res := utils.GetFiveSeconds(dt)
- if res != cs["expected"] {
- t.Fatalf("TestGetFiveSeconds fail : %s", cs["case"])
- }
- }
- }
|