51 lines
1014 B
Go
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))
|
|
}
|