jx/internal/resource/group_test.go

76 lines
1.2 KiB
Go
Raw Normal View History

2024-07-17 08:34:57 +00:00
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package resource
import (
"context"
_ "encoding/json"
"github.com/stretchr/testify/assert"
_ "io"
_ "net/http"
_ "net/http/httptest"
_ "net/url"
_ "os"
_ "strings"
"testing"
)
func TestNewGroupResource(t *testing.T) {
g := NewGroup()
assert.NotNil(t, g)
}
func TestReadGroup(t *testing.T) {
ctx := context.Background()
decl := `
name: "sys"
2024-07-17 08:34:57 +00:00
`
g := NewGroup()
e := g.LoadDecl(decl)
assert.Nil(t, e)
assert.Equal(t, "sys", g.Name)
2024-07-17 08:34:57 +00:00
_, readErr := g.Read(ctx)
assert.Nil(t, readErr)
assert.Equal(t, "3", g.GID)
2024-07-17 08:34:57 +00:00
}
func TestCreateGroup(t *testing.T) {
decl := `
name: "testgroup"
gid: 12001
state: present
`
g := NewGroup()
e := g.LoadDecl(decl)
assert.Equal(t, nil, e)
assert.Equal(t, "testgroup", g.Name)
g.CreateCommand.Executor = func(value any) ([]byte, error) {
return []byte(``), nil
}
g.ReadCommand.Extractor = func(out []byte, target any) error {
return nil
}
g.DeleteCommand.Executor = func(value any) ([]byte, error) {
return nil, nil
}
applyErr := g.Apply()
assert.Nil(t, applyErr)
assert.Equal(t, "12001", g.GID)
g.State = "absent"
applyDeleteErr := g.Apply()
assert.Nil(t, applyDeleteErr)
}