forked from mtusi2026/mtusi2026lab3
28 lines
519 B
Go
28 lines
519 B
Go
package config
|
|
|
|
import "testing"
|
|
|
|
func TestInstanceIDUsesConfiguredValue(t *testing.T) {
|
|
t.Setenv("INSTANCE_ID", " api-1 ")
|
|
|
|
got, err := instanceID()
|
|
if err != nil {
|
|
t.Fatalf("instanceID: %v", err)
|
|
}
|
|
if got != "api-1" {
|
|
t.Fatalf("instanceID = %q, want api-1", got)
|
|
}
|
|
}
|
|
|
|
func TestInstanceIDFallsBackToHostname(t *testing.T) {
|
|
t.Setenv("INSTANCE_ID", " ")
|
|
|
|
got, err := instanceID()
|
|
if err != nil {
|
|
t.Fatalf("instanceID: %v", err)
|
|
}
|
|
if got == "" {
|
|
t.Fatal("instanceID returned an empty value")
|
|
}
|
|
}
|