Add public facade value wrappers
This commit is contained in:
43
internal/facade/facade_external_test.go
Normal file
43
internal/facade/facade_external_test.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package configkit_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
configkit "gitea.maximumdirect.net/eric/ConfigKit/internal/facade"
|
||||
)
|
||||
|
||||
var (
|
||||
_ error = (*configkit.LoadError)(nil)
|
||||
_ fmt.Formatter = configkit.Secret{}
|
||||
_ fmt.Stringer = configkit.Path{}
|
||||
_ json.Marshaler = configkit.Secret{}
|
||||
)
|
||||
|
||||
func TestFacadeValuesRemainRootOwned(t *testing.T) {
|
||||
t.Parallel()
|
||||
const packagePath = "gitea.maximumdirect.net/eric/ConfigKit/internal/facade"
|
||||
for _, candidate := range []reflect.Type{
|
||||
reflect.TypeFor[configkit.Path](), reflect.TypeFor[configkit.Source](),
|
||||
reflect.TypeFor[configkit.Secret](), reflect.TypeFor[configkit.Diagnostic](),
|
||||
reflect.TypeFor[configkit.LoadError](),
|
||||
} {
|
||||
if candidate.PkgPath() != packagePath {
|
||||
t.Fatalf("type %s belongs to %q", candidate, candidate.PkgPath())
|
||||
}
|
||||
}
|
||||
secret := configkit.SecretEnv("SAFE_NAME")
|
||||
formatted := fmt.Sprintf("%#v", secret)
|
||||
encoded, err := json.Marshal(secret)
|
||||
if formatted == "" || err != nil || string(encoded) != `"SAFE_NAME"` {
|
||||
t.Fatalf("secret rendering = %q, %s, %v", formatted, encoded, err)
|
||||
}
|
||||
if got := configkit.Keys("a/b~").Index(0).String(); got != "/a~1b~0/0" {
|
||||
t.Fatalf("path = %q", got)
|
||||
}
|
||||
if got := (&configkit.LoadError{}).Error(); got != "configkit: configuration load failed" {
|
||||
t.Fatalf("zero LoadError = %q", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user