- Use filepaths with /tmp for tests instead - Only mock functions where filepath can't be specified such as user.Lookup
29 lines
717 B
Go
29 lines
717 B
Go
// Package alpine defines a configurator to interact with the Alpine operating system.
|
|
package alpine
|
|
|
|
import (
|
|
"context"
|
|
"os/user"
|
|
)
|
|
|
|
type Configurator interface {
|
|
CreateUser(username string, uid int) (createdUsername string, err error)
|
|
Version(ctx context.Context) (version string, err error)
|
|
}
|
|
|
|
type configurator struct {
|
|
alpineReleasePath string
|
|
passwdPath string
|
|
lookupID func(uid string) (*user.User, error)
|
|
lookup func(username string) (*user.User, error)
|
|
}
|
|
|
|
func NewConfigurator() Configurator {
|
|
return &configurator{
|
|
alpineReleasePath: "/etc/alpine-release",
|
|
passwdPath: "/etc/passwd",
|
|
lookupID: user.LookupId,
|
|
lookup: user.Lookup,
|
|
}
|
|
}
|