39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestStartupPathsAndIsolation(t *testing.T) {
|
|
dir, id := fixture(t)
|
|
config := startupConfig{Listen: "0.0.0.0:8089", DispatcherID: id, DispatcherSecret: "secret", BrokerURL: "amqp://guest:guest@localhost/saas-mock-unit", Snapshots: ".", Feedback: "../feedback"}
|
|
path := filepath.Join(dir, "server.json")
|
|
raw, _ := json.Marshal(config)
|
|
if err := os.WriteFile(path, raw, 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got, err := loadStartup(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got.Snapshots != dir || got.Feedback != filepath.Join(filepath.Dir(dir), "feedback") {
|
|
t.Fatalf("paths not relative to config: %+v", got)
|
|
}
|
|
config.Feedback = "tasks"
|
|
raw, _ = json.Marshal(config)
|
|
os.WriteFile(path, raw, 0600)
|
|
if _, err := loadStartup(path); err == nil {
|
|
t.Fatal("accepted feedback inside config dataset")
|
|
}
|
|
config.Feedback = "../feedback"
|
|
config.BrokerURL = "http://guest:guest@localhost/production"
|
|
raw, _ = json.Marshal(config)
|
|
os.WriteFile(path, raw, 0600)
|
|
if _, err := loadStartup(path); err == nil {
|
|
t.Fatal("accepted non-AMQP endpoint")
|
|
}
|
|
}
|