1 Commits
Author SHA1 Message Date
sneak f807c54b92 End-to-end tests for freshen and fetch (closes #66)
check / check (push) Failing after 2s
The freshen tests built a fixture and never ran freshen. They now run
gen and freshen through the command entry point on a temp dir: an
unchanged tree leaves the manifest's entries as they were, and a
modified, new or deleted file gives a manifest that lists exactly the
tree, with sizes, hashes and mtimes from disk, on which check passes.

New fetch tests run the command against an httptest server: a nested
tree lands complete, a hash mismatch exits non-zero and writes nothing,
and a partly filled destination gets every listed file downloaded again
and replaced, while a file the manifest does not list is left alone.

Model: opus-5-5
2026-10-04 13:58:15 +00:00
5 changed files with 28 additions and 28 deletions

No files matched your search

+1 -1
View File
@@ -974,7 +974,7 @@ func TestFetchIntoPartlyFilledDestination(t *testing.T) {
defer mu.Unlock() defer mu.Unlock()
assert.ElementsMatch(t, []string{ assert.ElementsMatch(t, []string{
"/" + defaultManifestName, "/current.txt", "/sub/changed.txt", "/sub/partial.txt", "/index.mf", "/current.txt", "/sub/changed.txt", "/sub/partial.txt",
}, requested) }, requested)
} }
+24 -24
View File
@@ -32,21 +32,18 @@ func (s stubFileInfo) ModTime() time.Time { return s.mtime }
func (s stubFileInfo) IsDir() bool { return false } func (s stubFileInfo) IsDir() bool { return false }
func (s stubFileInfo) Sys() any { return nil } func (s stubFileInfo) Sys() any { return nil }
// setupFreshenDir writes files, by path and content, into a fresh temp // setupFreshenDir writes file1.txt and sub/file2.txt, holding "content1"
// dir and runs gen on it. It returns the temp dir and the path of the // and "content2", into a fresh temp dir and runs gen on it. It returns
// manifest gen wrote there. // the temp dir and the path of the manifest gen wrote there.
func setupFreshenDir( func setupFreshenDir(t *testing.T, fs afero.Fs) (string, string) {
t *testing.T, fs afero.Fs, files map[string]string,
) (string, string) {
t.Helper() t.Helper()
root := t.TempDir() root := t.TempDir()
manifestPath := filepath.Join(root, defaultManifestName) manifestPath := filepath.Join(root, defaultManifestName)
for path, content := range files { require.NoError(t, fs.MkdirAll(filepath.Join(root, "sub"), 0o750))
require.NoError(t, fs.MkdirAll(filepath.Dir(filepath.Join(root, path)), 0o750)) writeTestFile(t, fs, filepath.Join(root, "file1.txt"), "content1")
writeTestFile(t, fs, filepath.Join(root, path), content) writeTestFile(t, fs, filepath.Join(root, "sub", "file2.txt"), "content2")
}
opts := testOpts([]string{testApp, cmdGenerate, "-q", "-o", manifestPath, root}, fs) opts := testOpts([]string{testApp, cmdGenerate, "-q", "-o", manifestPath, root}, fs)
require.Equal(t, 0, runCLI(opts), "stderr: %s", testStderr(t, opts)) require.Equal(t, 0, runCLI(opts), "stderr: %s", testStderr(t, opts))
@@ -84,8 +81,7 @@ func TestFreshenUnchanged(t *testing.T) {
t.Parallel() t.Parallel()
fs := afero.NewOsFs() fs := afero.NewOsFs()
root, manifestPath := setupFreshenDir(t, fs, root, manifestPath := setupFreshenDir(t, fs)
map[string]string{testFileTxt: "content1", testDirFile: "content2"})
before := manifestFiles(t, fs, manifestPath) before := manifestFiles(t, fs, manifestPath)
runFreshen(t, fs, root, manifestPath) runFreshen(t, fs, root, manifestPath)
@@ -144,48 +140,52 @@ func assertManifestLists(
func TestFreshenWithChanges(t *testing.T) { func TestFreshenWithChanges(t *testing.T) {
t.Parallel() t.Parallel()
tree := map[string]string{testFileTxt: "content1", testDirFile: "content2"}
for _, tc := range []struct { for _, tc := range []struct {
name string name string
write map[string]string // files to write, by path and content write map[string]string // files to write, by path and content
remove string // file to delete, if any remove string // file to delete, if any
want map[string]string // files the manifest must then list
}{ }{
{ {
name: "modified file", name: "modified file",
write: map[string]string{testDirFile: "modified content2"}, write: map[string]string{"sub/file2.txt": "modified content2"},
want: map[string]string{
"file1.txt": "content1",
"sub/file2.txt": "modified content2",
},
}, },
{ {
name: "new file", name: "new file",
write: map[string]string{"dir/new.txt": "content3"}, write: map[string]string{"sub/file3.txt": "content3"},
want: map[string]string{
"file1.txt": "content1",
"sub/file2.txt": "content2",
"sub/file3.txt": "content3",
},
}, },
{ {
name: "deleted file", name: "deleted file",
remove: testFileTxt, remove: "file1.txt",
want: map[string]string{"sub/file2.txt": "content2"},
}, },
} { } {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
t.Parallel() t.Parallel()
fs := afero.NewOsFs() fs := afero.NewOsFs()
root, manifestPath := setupFreshenDir(t, fs, tree) root, manifestPath := setupFreshenDir(t, fs)
// want is the tree as it is after the change.
want := maps.Clone(tree)
for path, content := range tc.write { for path, content := range tc.write {
writeTestFile(t, fs, filepath.Join(root, path), content) writeTestFile(t, fs, filepath.Join(root, path), content)
want[path] = content
} }
if tc.remove != "" { if tc.remove != "" {
require.NoError(t, fs.Remove(filepath.Join(root, tc.remove))) require.NoError(t, fs.Remove(filepath.Join(root, tc.remove)))
delete(want, tc.remove)
} }
runFreshen(t, fs, root, manifestPath) runFreshen(t, fs, root, manifestPath)
assertManifestLists(t, fs, root, manifestPath, want) assertManifestLists(t, fs, root, manifestPath, tc.want)
opts := testOpts([]string{ opts := testOpts([]string{
testApp, cmdCheck, "-q", testFlagNoExtra, testFlagBase, root, manifestPath, testApp, cmdCheck, "-q", testFlagNoExtra, testFlagBase, root, manifestPath,
+1 -1
View File
@@ -587,7 +587,7 @@ const file_mf_proto_rawDesc = "" +
"\fVERSION_NONE\x10\x00\x12\x0f\n" + "\fVERSION_NONE\x10\x00\x12\x0f\n" +
"\vVERSION_ONE\x10\x01B\f\n" + "\vVERSION_ONE\x10\x01B\f\n" +
"\n" + "\n" +
"_createdAtB\x1bZ\x19sneak.berlin/go/mfer/mferb\x06proto3" "_createdAtB\x1dZ\x1bgit.eeqj.de/sneak/mfer/mferb\x06proto3"
var ( var (
file_mf_proto_rawDescOnce sync.Once file_mf_proto_rawDescOnce sync.Once
+1 -1
View File
@@ -1,6 +1,6 @@
syntax = "proto3"; syntax = "proto3";
option go_package = "sneak.berlin/go/mfer/mfer"; option go_package = "git.eeqj.de/sneak/mfer/mfer";
message Timestamp { message Timestamp {
int64 seconds = 1; int64 seconds = 1;
+1 -1
View File
@@ -1 +1 @@
fa6fceaba5553c8667c631994535fe5c307c8adb19f3ad289babf79a0f438650 mf.proto 103901c42b94396aa7ae128fd503ef693a4b7a03b2169481f25fda3d2c254e00 mf.proto