mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-06-10 00:19:40 +08:00
32
internal/app/methods_data_root_test.go
Normal file
32
internal/app/methods_data_root_test.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMigrateDataRootContentsCopiesKnownFilesAndDirectories(t *testing.T) {
|
||||
sourceRoot := t.TempDir()
|
||||
targetRoot := filepath.Join(t.TempDir(), "gonavi-data")
|
||||
|
||||
if err := os.WriteFile(filepath.Join(sourceRoot, "connections.json"), []byte(`{"connections":[]}`), 0o644); err != nil {
|
||||
t.Fatalf("write connections.json failed: %v", err)
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Join(sourceRoot, "sessions"), 0o755); err != nil {
|
||||
t.Fatalf("mkdir sessions failed: %v", err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(sourceRoot, "sessions", "s1.json"), []byte(`{}`), 0o644); err != nil {
|
||||
t.Fatalf("write session file failed: %v", err)
|
||||
}
|
||||
|
||||
if err := migrateDataRootContents(sourceRoot, targetRoot); err != nil {
|
||||
t.Fatalf("migrateDataRootContents returned error: %v", err)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(targetRoot, "connections.json")); err != nil {
|
||||
t.Fatalf("expected connections.json in target root: %v", err)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(targetRoot, "sessions", "s1.json")); err != nil {
|
||||
t.Fatalf("expected session file in target root: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user