| 8 | ) |
| 9 | |
| 10 | func TestHash(t *testing.T) { |
| 11 | tests := []struct { |
| 12 | name string |
| 13 | record string |
| 14 | src string |
| 15 | dst string |
| 16 | hash string |
| 17 | encode string |
| 18 | want []byte |
| 19 | wantErr bool |
| 20 | }{ |
| 21 | { |
| 22 | name: "md5", |
| 23 | record: "abc,def,ghi", |
| 24 | src: "f1", |
| 25 | dst: "f3", |
| 26 | hash: "md5", |
| 27 | encode: "", |
| 28 | want: []byte{144, 1, 80, 152, 60, 210, 79, 176, 214, 150, 63, 125, 40, 225, 127, 114}, |
| 29 | }, |
| 30 | { |
| 31 | name: "md5 + hex", |
| 32 | record: "abc,def,ghi", |
| 33 | src: "f1", |
| 34 | dst: "f3", |
| 35 | hash: "md5", |
| 36 | encode: "hex", |
| 37 | want: []byte{57, 48, 48, 49, 53, 48, 57, 56, 51, 99, 100, 50, 52, 102, 98, 48, 100, 54, 57, 54, 51, 102, 55, 100, 50, 56, 101, 49, 55, 102, 55, 50}, |
| 38 | }, |
| 39 | { |
| 40 | name: "sha256", |
| 41 | record: "abc,def,ghi", |
| 42 | src: "f1", |
| 43 | dst: "f3", |
| 44 | hash: "sha256", |
| 45 | encode: "", |
| 46 | want: []byte{186, 120, 22, 191, 143, 1, 207, 234, 65, 65, 64, 222, 93, 174, 34, 35, 176, 3, 97, 163, 150, 23, 122, 156, 180, 16, 255, 97, 242, 0, 21, 173}, |
| 47 | }, |
| 48 | { |
| 49 | name: "sha256 + hex", |
| 50 | record: "abc,def,ghi", |
| 51 | src: "f1", |
| 52 | dst: "f3", |
| 53 | hash: "sha256", |
| 54 | encode: "hex", |
| 55 | want: []byte{98, 97, 55, 56, 49, 54, 98, 102, 56, 102, 48, 49, 99, 102, 101, 97, 52, 49, 52, 49, 52, 48, 100, 101, 53, 100, 97, 101, 50, 50, 50, 51, 98, 48, 48, 51, 54, 49, 97, 51, 57, 54, 49, 55, 55, 97, 57, 99, 98, 52, 49, 48, 102, 102, 54, 49, 102, 50, 48, 48, 49, 53, 97, 100}, |
| 56 | }, |
| 57 | |
| 58 | // errors |
| 59 | { |
| 60 | name: "Function error", |
| 61 | src: "f1", |
| 62 | dst: "f3", |
| 63 | hash: "hash-not-exist", |
| 64 | encode: "hex", |
| 65 | wantErr: true, |
| 66 | }, |
| 67 | { |