jx/internal/resource/user_test.go

47 lines
846 B
Go
Raw Normal View History

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