add support for getting a user name from config
Some checks failed
Declarative Tests / test (push) Successful in 41s
Lint / golangci-lint (push) Failing after 10m37s

This commit is contained in:
Matthew Rich 2024-10-04 10:35:27 -07:00
parent dae9c1cf45
commit ea97070fea
2 changed files with 25 additions and 0 deletions

View File

@ -182,6 +182,11 @@ func (u *User) UseConfig(config data.ConfigurationValueGetter) {
}
func (u *User) ResolveId(ctx context.Context) string {
if u.config != nil {
if configUser, configUserErr := u.config.GetValue("user"); configUserErr == nil && u.Name == "" {
u.Name = configUser.(string)
}
}
return LookupUIDString(u.Name)
}

View File

@ -13,6 +13,7 @@ import (
_ "os"
_ "strings"
"testing"
"decl/internal/data"
)
func TestNewUserResource(t *testing.T) {
@ -77,3 +78,22 @@ func TestCreateUser(t *testing.T) {
applyDeleteErr := u.Apply()
assert.Equal(t, nil, applyDeleteErr)
}
func TestSystemUser(t *testing.T) {
u := NewUser()
u.UseConfig(MockConfigValueGetter(func(key string) (any, error) {
switch key {
case "user":
return "bar", nil
case "group":
return "foo", nil
case "uid":
return "", nil
}
return nil, fmt.Errorf("%w: %s", data.ErrUnknownConfigurationKey, key)
}))
u.ResolveId(context.Background())
assert.Equal(t, "bar", u.Name)
}