pomerium/config/envoyconfig/filemgr/filemgr_test.go
Caleb Doxsey dc9a6bdb81
replace xxhash with xxh3 (#5457)
* update config file paths hash

* update filemgr

* use xxh3 for hashutil.Hash

* update hashutil digest, fix trace buffer test

* update comments

* update namegen, go mod tidy
2025-01-31 08:44:08 -07:00

52 lines
1.3 KiB
Go

package filemgr
import (
"os"
"path/filepath"
"testing"
envoy_config_core_v3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
"github.com/stretchr/testify/assert"
)
func Test(t *testing.T) {
t.Parallel()
dir := t.TempDir()
t.Run("bytes", func(t *testing.T) {
mgr := NewManager(WithCacheDir(dir))
ds := mgr.BytesDataSource("test.txt", []byte{1, 2, 3, 4, 5})
assert.Equal(t, &envoy_config_core_v3.DataSource{
Specifier: &envoy_config_core_v3.DataSource_Filename{
Filename: filepath.Join(dir, "test-31443434314d425355414b4539.txt"),
},
}, ds)
mgr.ClearCache()
})
t.Run("file", func(t *testing.T) {
tmpFilePath := filepath.Join(dir, "test.txt")
_ = os.WriteFile(tmpFilePath, []byte("TEST1"), 0o777)
mgr := NewManager(WithCacheDir(dir))
ds := mgr.FileDataSource(tmpFilePath)
assert.Equal(t, &envoy_config_core_v3.DataSource{
Specifier: &envoy_config_core_v3.DataSource_Filename{
Filename: filepath.Join(dir, "test-3246454c394658475133414f35.txt"),
},
}, ds)
_ = os.WriteFile(tmpFilePath, []byte("TEST2"), 0o777)
ds = mgr.FileDataSource(tmpFilePath)
assert.Equal(t, &envoy_config_core_v3.DataSource{
Specifier: &envoy_config_core_v3.DataSource_Filename{
Filename: filepath.Join(dir, "test-33343439385257475847375443.txt"),
},
}, ds)
mgr.ClearCache()
})
}