github.com/fastwego/offiaccount@v1.0.1/util/randstring_test.go (about) 1 // Copyright 2020 FastWeGo 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package util 16 17 import ( 18 "fmt" 19 "testing" 20 ) 21 22 func TestGetRandString(t *testing.T) { 23 type args struct { 24 length int 25 } 26 tests := []struct { 27 name string 28 args args 29 want string 30 wantLen int 31 }{ 32 {name: "case1", args: args{length: 6}, wantLen: 6}, 33 } 34 for _, tt := range tests { 35 t.Run(tt.name, func(t *testing.T) { 36 got := GetRandString(tt.args.length) 37 if len(got) != tt.wantLen { 38 t.Errorf("GetRandString() = %v, want %v", got, tt.want) 39 } 40 41 fmt.Println(got) 42 }) 43 } 44 } 45 46 func TestGetRandStringWithCharset(t *testing.T) { 47 type args struct { 48 length int 49 charset string 50 } 51 tests := []struct { 52 name string 53 args args 54 want string 55 wantLen int 56 }{ 57 {name: "case1", args: args{length: 6, charset: "0x0x0x"}, wantLen: 6}, 58 } 59 for _, tt := range tests { 60 t.Run(tt.name, func(t *testing.T) { 61 got := GetRandStringWithCharset(tt.args.length, tt.args.charset) 62 if len(got) != tt.wantLen { 63 t.Errorf("GetRandStringWithCharset() = %v, want %v", got, tt.want) 64 } 65 fmt.Println(got) 66 }) 67 } 68 }