// Copyright 2024 Matthew Rich . 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) }