jx/internal/resource/group_test.go
Matthew Rich 8094d1c063
Some checks are pending
Lint / golangci-lint (push) Waiting to run
Declarative Tests / test (push) Waiting to run
Declarative Tests / build-fedora (push) Waiting to run
Declarative Tests / build-ubuntu-focal (push) Waiting to run
add build support to container_image resource; add more testing
2024-09-19 08:11:57 +00:00

76 lines
1.2 KiB
Go

// 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"
`
g := NewGroup()
e := g.LoadDecl(decl)
assert.Nil(t, e)
assert.Equal(t, "sys", g.Name)
_, readErr := g.Read(ctx)
assert.Nil(t, readErr)
assert.Equal(t, "3", g.GID)
}
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)
}