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 := `
|
2024-09-19 08:11:57 +00:00
|
|
|
name: "sys"
|
2024-07-17 08:34:57 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
g := NewGroup()
|
|
|
|
e := g.LoadDecl(decl)
|
|
|
|
assert.Nil(t, e)
|
2024-09-19 08:11:57 +00:00
|
|
|
assert.Equal(t, "sys", g.Name)
|
2024-07-17 08:34:57 +00:00
|
|
|
|
|
|
|
_, readErr := g.Read(ctx)
|
|
|
|
assert.Nil(t, readErr)
|
|
|
|
|
2024-09-19 08:11:57 +00:00
|
|
|
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)
|
|
|
|
}
|