Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e33b87f142 | ||
|
|
5c7ef94799 |
No files matched your search
@@ -974,7 +974,7 @@ func TestFetchIntoPartlyFilledDestination(t *testing.T) {
|
|||||||
defer mu.Unlock()
|
defer mu.Unlock()
|
||||||
|
|
||||||
assert.ElementsMatch(t, []string{
|
assert.ElementsMatch(t, []string{
|
||||||
"/index.mf", "/current.txt", "/sub/changed.txt", "/sub/partial.txt",
|
"/" + defaultManifestName, "/current.txt", "/sub/changed.txt", "/sub/partial.txt",
|
||||||
}, requested)
|
}, requested)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,18 +32,21 @@ 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 file1.txt and sub/file2.txt, holding "content1"
|
// setupFreshenDir writes files, by path and content, into a fresh temp
|
||||||
// and "content2", into a fresh temp dir and runs gen on it. It returns
|
// dir and runs gen on it. It returns the temp dir and the path of the
|
||||||
// the temp dir and the path of the manifest gen wrote there.
|
// manifest gen wrote there.
|
||||||
func setupFreshenDir(t *testing.T, fs afero.Fs) (string, string) {
|
func setupFreshenDir(
|
||||||
|
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)
|
||||||
|
|
||||||
require.NoError(t, fs.MkdirAll(filepath.Join(root, "sub"), 0o750))
|
for path, content := range files {
|
||||||
writeTestFile(t, fs, filepath.Join(root, "file1.txt"), "content1")
|
require.NoError(t, fs.MkdirAll(filepath.Dir(filepath.Join(root, path)), 0o750))
|
||||||
writeTestFile(t, fs, filepath.Join(root, "sub", "file2.txt"), "content2")
|
writeTestFile(t, fs, filepath.Join(root, path), content)
|
||||||
|
}
|
||||||
|
|
||||||
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))
|
||||||
@@ -81,7 +84,8 @@ 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)
|
||||||
@@ -140,52 +144,48 @@ 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{"sub/file2.txt": "modified content2"},
|
write: map[string]string{testDirFile: "modified content2"},
|
||||||
want: map[string]string{
|
|
||||||
"file1.txt": "content1",
|
|
||||||
"sub/file2.txt": "modified content2",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "new file",
|
name: "new file",
|
||||||
write: map[string]string{"sub/file3.txt": "content3"},
|
write: map[string]string{"dir/new.txt": "content3"},
|
||||||
want: map[string]string{
|
|
||||||
"file1.txt": "content1",
|
|
||||||
"sub/file2.txt": "content2",
|
|
||||||
"sub/file3.txt": "content3",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "deleted file",
|
name: "deleted file",
|
||||||
remove: "file1.txt",
|
remove: testFileTxt,
|
||||||
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)
|
root, manifestPath := setupFreshenDir(t, fs, tree)
|
||||||
|
|
||||||
|
// 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, tc.want)
|
assertManifestLists(t, fs, root, manifestPath, want)
|
||||||
|
|
||||||
opts := testOpts([]string{
|
opts := testOpts([]string{
|
||||||
testApp, cmdCheck, "-q", testFlagNoExtra, testFlagBase, root, manifestPath,
|
testApp, cmdCheck, "-q", testFlagNoExtra, testFlagBase, root, manifestPath,
|
||||||
|
|||||||
+1
-1
@@ -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\x1dZ\x1bgit.eeqj.de/sneak/mfer/mferb\x06proto3"
|
"_createdAtB\x1bZ\x19sneak.berlin/go/mfer/mferb\x06proto3"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
file_mf_proto_rawDescOnce sync.Once
|
file_mf_proto_rawDescOnce sync.Once
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
|
|
||||||
option go_package = "git.eeqj.de/sneak/mfer/mfer";
|
option go_package = "sneak.berlin/go/mfer/mfer";
|
||||||
|
|
||||||
message Timestamp {
|
message Timestamp {
|
||||||
int64 seconds = 1;
|
int64 seconds = 1;
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
103901c42b94396aa7ae128fd503ef693a4b7a03b2169481f25fda3d2c254e00 mf.proto
|
fa6fceaba5553c8667c631994535fe5c307c8adb19f3ad289babf79a0f438650 mf.proto
|
||||||
Reference in new issue
Block a user