package helper import ( "fmt" "testing" ) // 测试 StringToInt32方法 func TestStringToInt32(t *testing.T) { // 测试用例 type args struct { s string } tests := []struct { name string args args want int32 }{ {name: "测试1", args: args{s: "123"}, want: 123}, {name: "测试2", args: args{s: "123.123"}, want: 0}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { // 调用方法 if got := StringToInt32(tt.args.s); got != tt.want { // 判断结果 t.Errorf("StringToInt32() = %v, want %v", got, tt.want) } }) } } func TestReplaceStar(t *testing.T) { type args struct { secretKey string } tests := []struct { name string args args want string }{ {name: "测试1", args: args{secretKey: "123456789"}, want: "12******89"}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got := StringToAsterisk(tt.args.secretKey) t.Logf("StringToAsterisk() = %v, want %v \n", got, tt.want) if got != tt.want { t.Errorf("StringToAsterisk() = %v, want %v \n", got, tt.want) } }) } } func TestRandomPassword(t *testing.T) { password := GetRandomStr(6) fmt.Println("生成的随机密码为:", password) }