Luke Granger-Brown
5846385513
We need to depend on its API for fuphttp, so it's better if it's a separate package to avoid embedding things we don't need. In general it's probably a good idea to separate the logic from the embedded content...
47 lines
953 B
Go
47 lines
953 B
Go
// SPDX-FileCopyrightText: 2021 Luke Granger-Brown <depot@lukegb.com>
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package hashfs
|
|
|
|
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"),
|
|
},
|
|
}
|
|
|
|
f := New(baseFS)
|
|
|
|
tcs := []struct {
|
|
origName string
|
|
newName string
|
|
wantContent string
|
|
}{
|
|
{"foo", "foo.68656c6c6f2c", "hello, world"},
|
|
{"bar/bar.txt", "bar/bar.666f6f206261.txt", "foo bar baz"},
|
|
}
|
|
|
|
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)
|
|
}
|
|
})
|
|
}
|
|
}
|