49 lines
2.2 KiB
Go
49 lines
2.2 KiB
Go
package appconfig
|
|
|
|
import "testing"
|
|
|
|
func identityForTest(c Config) string {
|
|
return c.LibraryTargetIdentity()
|
|
}
|
|
|
|
func TestLibraryTargetIdentityIgnoresTransportButBindsData(t *testing.T) {
|
|
a := Config{LibraryTargetInstance: "cloud-test", LibraryTargetProject: "weknora-test",
|
|
LibraryProductionDatabaseURL: "postgres://local@127.0.0.1:5433/target_db", LibraryProductionTenantID: 10000,
|
|
LibraryProductionInternalKB: "internal-a", LibraryProductionExternalKB: "external-a",
|
|
LibraryProductionIndex: "index-a", LibraryProductionS3Bucket: "bucket-a", LibraryProductionS3Provider: "s3", LibraryProductionS3Endpoint: "https://objects.example"}
|
|
want := identityForTest(a)
|
|
if want == "" {
|
|
t.Fatal("live services must never bind the empty legacy namespace")
|
|
}
|
|
transport := a
|
|
transport.LibraryProductionDatabaseURL = "postgres://remote@database:5432/target_db"
|
|
transport.LibraryTargetDockerSocket = "/other/docker.sock"
|
|
transport.LibraryArchiveRoot = "/other/archive"
|
|
if got := identityForTest(transport); got != want {
|
|
t.Fatal("SSH routing must not change logical identity")
|
|
}
|
|
cases := map[string]func(*Config){
|
|
"instance": func(c *Config) { c.LibraryTargetInstance = "other" },
|
|
"project": func(c *Config) { c.LibraryTargetProject = "other" },
|
|
"database": func(c *Config) { c.LibraryProductionDatabaseURL = "postgres://local@127.0.0.1:5433/other_db" },
|
|
"tenant": func(c *Config) { c.LibraryProductionTenantID = 20000 },
|
|
"internal": func(c *Config) { c.LibraryProductionInternalKB = "other" },
|
|
"external": func(c *Config) { c.LibraryProductionExternalKB = "other" },
|
|
"index": func(c *Config) { c.LibraryProductionIndex = "other" },
|
|
"bucket": func(c *Config) { c.LibraryProductionS3Bucket = "other" },
|
|
"object_endpoint": func(c *Config) { c.LibraryProductionS3Endpoint = "https://other.example" },
|
|
}
|
|
for name, change := range cases {
|
|
t.Run(name, func(t *testing.T) {
|
|
c := a
|
|
change(&c)
|
|
if identityForTest(c) == want {
|
|
t.Fatal("changed data target reused old identity")
|
|
}
|
|
})
|
|
}
|
|
if identityForTest(Config{}) == "" {
|
|
t.Fatal("unconfigured service must not adopt unbound historical evidence")
|
|
}
|
|
}
|