mirror of
https://github.com/danielmiessler/Fabric.git
synced 2026-02-12 23:15:05 -05:00
### CHANGES - Introduce `cmd` directory for all main application binaries. - Move all Go packages into the `internal` directory. - Rename the `restapi` package to `server` for clarity. - Consolidate patterns and strategies into a new `data` directory. - Group all auxiliary scripts into a new `scripts` directory. - Move all documentation and images into a `docs` directory. - Update all Go import paths to reflect the new structure. - Adjust CI/CD workflows and build commands for new layout.
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package fsdb
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestDb_Configure(t *testing.T) {
|
|
dir := t.TempDir()
|
|
db := NewDb(dir)
|
|
err := db.Configure()
|
|
if err == nil {
|
|
t.Fatalf("db is configured, but must not be at empty dir: %v", dir)
|
|
}
|
|
if db.IsEnvFileExists() {
|
|
t.Fatalf("db file exists, but must not be at empty dir: %v", dir)
|
|
}
|
|
|
|
err = db.SaveEnv("")
|
|
if err != nil {
|
|
t.Fatalf("db can't save env for empty conf.: %v", err)
|
|
}
|
|
|
|
err = db.Configure()
|
|
if err != nil {
|
|
t.Fatalf("db is not configured, but shall be after save: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestDb_LoadEnvFile(t *testing.T) {
|
|
dir := t.TempDir()
|
|
db := NewDb(dir)
|
|
content := "KEY=VALUE\n"
|
|
err := os.WriteFile(db.EnvFilePath, []byte(content), 0644)
|
|
if err != nil {
|
|
t.Fatalf("failed to write .env file: %v", err)
|
|
}
|
|
err = db.LoadEnvFile()
|
|
if err != nil {
|
|
t.Errorf("failed to load .env file: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestDb_SaveEnv(t *testing.T) {
|
|
dir := t.TempDir()
|
|
db := NewDb(dir)
|
|
content := "KEY=VALUE\n"
|
|
err := db.SaveEnv(content)
|
|
if err != nil {
|
|
t.Errorf("failed to save .env file: %v", err)
|
|
}
|
|
if _, err := os.Stat(db.EnvFilePath); os.IsNotExist(err) {
|
|
t.Errorf("expected .env file to be saved")
|
|
}
|
|
}
|