2021-03-20 20:40:40 +00:00
|
|
|
// SPDX-FileCopyrightText: 2021 Luke Granger-Brown <depot@lukegb.com>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2021-03-20 23:43:59 +00:00
|
|
|
package hashfs
|
2021-03-20 19:51:32 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"testing/fstest"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestHashingFS(t *testing.T) {
|
|
|
|
baseFS := fstest.MapFS{
|
|
|
|
"foo": &fstest.MapFile{
|
|
|
|
Data: []byte("hello, world"),
|
|
|
|
},
|
|
|
|
"bar/bar.txt": &fstest.MapFile{
|
|
|
|
Data: []byte("foo bar baz"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-03-20 23:43:59 +00:00
|
|
|
f := New(baseFS)
|
2021-03-20 19:51:32 +00:00
|
|
|
|
|
|
|
tcs := []struct {
|
|
|
|
origName string
|
|
|
|
newName string
|
|
|
|
wantContent string
|
|
|
|
}{
|
2021-03-22 19:25:55 +00:00
|
|
|
{"foo", "foo.8710339dcb68", "hello, world"},
|
|
|
|
{"bar/bar.txt", "bar/bar.bce50343a56f.txt", "foo bar baz"},
|
2021-03-20 19:51:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range tcs {
|
|
|
|
t.Run(tc.origName, func(t *testing.T) {
|
|
|
|
n, ok := f.LookupHashedName(tc.origName)
|
|
|
|
if !ok {
|
|
|
|
t.Errorf("LookupHashedName returned false")
|
|
|
|
} else if n != tc.newName {
|
|
|
|
t.Errorf("LookupHashedName returned %q; want %q", n, tc.newName)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := fstest.TestFS(f, tc.newName); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|