git.zd.zone/hrpc/hrpc@v0.0.12/utils/hash/hash_test.go (about) 1 package hash 2 3 import ( 4 "testing" 5 ) 6 7 func TestSHA1(t *testing.T) { 8 type args struct { 9 d []interface{} 10 } 11 tests := []struct { 12 name string 13 args args 14 want string 15 }{ 16 { 17 name: "Test1", 18 args: args{ 19 d: []interface{}{"aaa", "bbb"}, 20 }, 21 want: "68d8572c2662b0f06f723d7d507954fb038b8558", 22 }, 23 { 24 name: "Test2", 25 args: args{ 26 d: []interface{}{}, 27 }, 28 want: "da39a3ee5e6b4b0d3255bfef95601890afd80709", 29 }, 30 { 31 name: "Test3", 32 args: args{ 33 d: []interface{}{"", "", ""}, 34 }, 35 want: "da39a3ee5e6b4b0d3255bfef95601890afd80709", 36 }, 37 { 38 name: "Test4", 39 args: args{ 40 d: []interface{}{"bbb", []byte("aa"), 10}, 41 }, 42 want: "ab3d52338d2099d3e451b4334434a4dddf647332", 43 }, 44 } 45 for _, tt := range tests { 46 t.Run(tt.name, func(t *testing.T) { 47 if got := SHA1(tt.args.d...); got != tt.want { 48 t.Errorf("SHA1() = %v, want %v", got, tt.want) 49 } 50 }) 51 } 52 } 53 54 func TestMD5(t *testing.T) { 55 type args struct { 56 d []interface{} 57 } 58 tests := []struct { 59 name string 60 args args 61 want string 62 }{ 63 { 64 name: "Test1", 65 args: args{ 66 d: []interface{}{"aaa", "bbb"}, 67 }, 68 want: "6547436690a26a399603a7096e876a2d", 69 }, 70 } 71 for _, tt := range tests { 72 t.Run(tt.name, func(t *testing.T) { 73 if got := MD5(tt.args.d...); got != tt.want { 74 t.Errorf("MD5() = %v, want %v", got, tt.want) 75 } 76 }) 77 } 78 } 79 80 func TestSHA256(t *testing.T) { 81 type args struct { 82 d []interface{} 83 } 84 tests := []struct { 85 name string 86 args args 87 want string 88 }{ 89 { 90 name: "Test1", 91 args: args{ 92 d: []interface{}{"aaa", "bbb"}, 93 }, 94 want: "2ce109e9d0faf820b2434e166297934e6177b65ab9951dbc3e204cad4689b39c", 95 }, 96 } 97 for _, tt := range tests { 98 t.Run(tt.name, func(t *testing.T) { 99 if got := SHA256(tt.args.d...); got != tt.want { 100 t.Errorf("SHA256() = %v, want %v", got, tt.want) 101 } 102 }) 103 } 104 }