MCPcopy
hub / github.com/bitfield/script / TestHashSums_OutputsCorrectHashForEachSpecifiedFile

Function TestHashSums_OutputsCorrectHashForEachSpecifiedFile

script_test.go:2118–2156  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2116}
2117
2118func TestHashSums_OutputsCorrectHashForEachSpecifiedFile(t *testing.T) {
2119 t.Parallel()
2120 tcs := []struct {
2121 testFileName string
2122 hasher hash.Hash
2123 want string
2124 }{
2125 // To get the checksum run: openssl dgst -sha256 <file_name>
2126 {
2127 testFileName: "testdata/hashSum.input.txt",
2128 hasher: sha256.New(),
2129 want: "1870478d23b0b4db37735d917f4f0ff9393dd3e52d8b0efa852ab85536ddad8e\n",
2130 },
2131 {
2132 testFileName: "testdata/hashSum.input.txt",
2133 hasher: sha512.New(),
2134 want: "3543bd0d68129e860598ccabcee1beb6bb90d91105cea74a8e555588634ec6f6d6d02033139972da2dc4929b1fb61bd24c91c8e82054e9ae865cf7f70909be8c\n",
2135 },
2136 {
2137 testFileName: "testdata/hello.txt",
2138 hasher: sha256.New(),
2139 want: "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9\n",
2140 },
2141 {
2142 testFileName: "testdata/multiple_files",
2143 hasher: sha256.New(),
2144 want: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\ne3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\ne3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n",
2145 },
2146 }
2147 for _, tc := range tcs {
2148 got, err := script.ListFiles(tc.testFileName).HashSums(tc.hasher).String()
2149 if err != nil {
2150 t.Fatal(err)
2151 }
2152 if got != tc.want {
2153 t.Errorf("%q: want %q, got %q", tc.testFileName, tc.want, got)
2154 }
2155 }
2156}
2157
2158func TestHash_ReturnsErrorGivenReadErrorOnPipe(t *testing.T) {
2159 t.Parallel()

Callers

nothing calls this directly

Calls 3

ListFilesFunction · 0.92
StringMethod · 0.80
HashSumsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…