jx/internal/resource/user_test.go
Matthew Rich e695278d0c
All checks were successful
Declarative Tests / test (push) Successful in 48s
go fmt
2024-03-25 13:31:06 -07:00

47 lines
846 B
Go

// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package resource
import (
_ "context"
_ "encoding/json"
_ "fmt"
"github.com/stretchr/testify/assert"
_ "io"
_ "net/http"
_ "net/http/httptest"
_ "net/url"
_ "os"
_ "strings"
"testing"
)
func TestNewUserResource(t *testing.T) {
u := NewUser()
assert.NotEqual(t, nil, u)
}
func TestCreateUser(t *testing.T) {
decl := `
name: "testuser"
uid: 12001
gid: 12001
home: "/home/testuser"
state: present
`
u := NewUser()
e := u.LoadDecl(decl)
assert.Equal(t, nil, e)
assert.Equal(t, "testuser", u.Name)
applyErr := u.Apply()
assert.Equal(t, nil, applyErr)
uid, uidErr := LookupUID(u.Name)
assert.Equal(t, nil, uidErr)
assert.Equal(t, 12001, uid)
u.State = "absent"
applyDeleteErr := u.Apply()
assert.Equal(t, nil, applyDeleteErr)
}