| 2072 | } |
| 2073 | |
| 2074 | func TestHash_OutputsCorrectHash(t *testing.T) { |
| 2075 | t.Parallel() |
| 2076 | tcs := []struct { |
| 2077 | name, input, want string |
| 2078 | hasher hash.Hash |
| 2079 | }{ |
| 2080 | { |
| 2081 | name: "for no data", |
| 2082 | input: "", |
| 2083 | hasher: sha256.New(), |
| 2084 | want: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", |
| 2085 | }, |
| 2086 | { |
| 2087 | name: "for short string with SHA 256 hasher", |
| 2088 | input: "hello, world", |
| 2089 | hasher: sha256.New(), |
| 2090 | want: "09ca7e4eaa6e8ae9c7d261167129184883644d07dfba7cbfbc4c8a2e08360d5b", |
| 2091 | }, |
| 2092 | { |
| 2093 | name: "for short string with SHA 512 hasher", |
| 2094 | input: "hello, world", |
| 2095 | hasher: sha512.New(), |
| 2096 | want: "8710339dcb6814d0d9d2290ef422285c9322b7163951f9a0ca8f883d3305286f44139aa374848e4174f5aada663027e4548637b6d19894aec4fb6c46a139fbf9", |
| 2097 | }, |
| 2098 | { |
| 2099 | name: "for string containing newline with SHA 256 hasher", |
| 2100 | input: "The tao that can be told\nis not the eternal Tao", |
| 2101 | hasher: sha256.New(), |
| 2102 | want: "788542cb92d37f67e187992bdb402fdfb68228a1802947f74c6576e04790a688", |
| 2103 | }, |
| 2104 | } |
| 2105 | for _, tc := range tcs { |
| 2106 | t.Run(tc.name, func(t *testing.T) { |
| 2107 | got, err := script.Echo(tc.input).Hash(tc.hasher) |
| 2108 | if err != nil { |
| 2109 | t.Fatal(err) |
| 2110 | } |
| 2111 | if got != tc.want { |
| 2112 | t.Errorf("want %q, got %q", tc.want, got) |
| 2113 | } |
| 2114 | }) |
| 2115 | } |
| 2116 | } |
| 2117 | |
| 2118 | func TestHashSums_OutputsCorrectHashForEachSpecifiedFile(t *testing.T) { |
| 2119 | t.Parallel() |