to Config struct for configging

This commit is contained in:
Bel LaPointe
2024-04-11 16:36:23 -06:00
parent 8b732b196d
commit 4c4d92478d
3 changed files with 125 additions and 7 deletions

23
config_test.go Normal file
View File

@@ -0,0 +1,23 @@
package main
import "testing"
func TestNewConfig(t *testing.T) {
if got, err := newConfigFromEnv(func(k string) string {
t.Logf("getenv(%s)", k)
switch k {
case "PORT":
return "1"
case "A_B":
return "2"
default:
return ""
}
}); err != nil {
t.Fatal(err)
} else if got.Port != 1 {
t.Error(got)
} else if got.AB != "2" {
t.Error(got)
}
}