feat(instance): announce-domain naming default + capitalized fallback
Identity chain is now instance.json → DCNTRLIZED_INSTANCE_NAME → DCNTRLIZED_INSTANCE_DOMAIN (the domain the instance announces as, e.g. maestro.dcntrlized.org) → human-readable hostname → 'Maestro'.
This commit is contained in:
@@ -38,15 +38,25 @@ func TestDefaultIdentityFallbacks(t *testing.T) {
|
||||
orig := osHostname
|
||||
defer func() { osHostname = orig }()
|
||||
|
||||
t.Run("env wins", func(t *testing.T) {
|
||||
t.Run("env wins over domain", func(t *testing.T) {
|
||||
t.Setenv("DCNTRLIZED_INSTANCE_NAME", "edge-1")
|
||||
t.Setenv("DCNTRLIZED_INSTANCE_DOMAIN", "maestro.dcntrlized.org")
|
||||
if id := defaultIdentity(); id.Name != "edge-1" {
|
||||
t.Fatalf("got %q", id.Name)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("announced domain used before hostname", func(t *testing.T) {
|
||||
t.Setenv("DCNTRLIZED_INSTANCE_DOMAIN", "maestro.dcntrlized.org")
|
||||
osHostname = func() (string, error) { return "archlinux", nil }
|
||||
if id := defaultIdentity(); id.Name != "maestro.dcntrlized.org" {
|
||||
t.Fatalf("got %q", id.Name)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("hostname used when human-readable", func(t *testing.T) {
|
||||
os.Unsetenv("DCNTRLIZED_INSTANCE_NAME")
|
||||
os.Unsetenv("DCNTRLIZED_INSTANCE_DOMAIN")
|
||||
osHostname = func() (string, error) { return "archlinux", nil }
|
||||
if id := defaultIdentity(); id.Name != "archlinux" {
|
||||
t.Fatalf("got %q", id.Name)
|
||||
@@ -55,9 +65,10 @@ func TestDefaultIdentityFallbacks(t *testing.T) {
|
||||
|
||||
t.Run("container-id hostname replaced", func(t *testing.T) {
|
||||
os.Unsetenv("DCNTRLIZED_INSTANCE_NAME")
|
||||
os.Unsetenv("DCNTRLIZED_INSTANCE_DOMAIN")
|
||||
for _, host := range []string{"6079761d6e4d", "6079761d6e4dabcdef1234567890abcdef1234567890abcdef1234567890abcd"} {
|
||||
osHostname = func() (string, error) { return host, nil }
|
||||
if id := defaultIdentity(); id.Name != "maestro" {
|
||||
if id := defaultIdentity(); id.Name != "Maestro" {
|
||||
t.Fatalf("host %q: got %q", host, id.Name)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user