jx/internal/resource/service_test.go
Matthew Rich 1117882ced
Some checks are pending
Lint / golangci-lint (push) Waiting to run
Declarative Tests / test (push) Waiting to run
update resources to common uri handling
2024-10-09 22:26:39 +00:00

51 lines
1014 B
Go

// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package resource
import (
"context"
_ "decl/tests/mocks"
"decl/internal/command"
_ "fmt"
"github.com/stretchr/testify/assert"
"testing"
)
func TestNewServiceResource(t *testing.T) {
c := NewService()
assert.NotNil(t, c)
}
func TestUriServiceResource(t *testing.T) {
c := NewService()
assert.Nil(t, c.SetURI("service://ssh"))
assert.Equal(t, "ssh", c.Name)
}
func TestReadServiceResource(t *testing.T) {
s := NewService()
s.Name = "ssh"
yamlResult := `
name: "ssh"
servicemanager: "systemd"
state: "present"
`
m := &MockCommand{
CommandExists: func() error { return nil },
Executor: func(value any) ([]byte, error) {
return nil, nil
},
Extractor: func(output []byte, target any) error {
s.Common.State = "present"
return nil
},
}
s.ReadCommand = (*command.Command)(m)
yamlData, err := s.Read(context.Background())
assert.Nil(t, err)
assert.YAMLEq(t, yamlResult, string(yamlData))
}