52 lines
1.0 KiB
Go
52 lines
1.0 KiB
Go
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
|
|
|
package resource
|
|
|
|
import (
|
|
"context"
|
|
"decl/internal/command"
|
|
"github.com/stretchr/testify/assert"
|
|
"testing"
|
|
"decl/internal/folio"
|
|
)
|
|
|
|
func TestNewServiceResource(t *testing.T) {
|
|
c := NewService()
|
|
assert.NotNil(t, c)
|
|
}
|
|
|
|
func TestUriServiceResource(t *testing.T) {
|
|
c := NewService()
|
|
uri := folio.URI("service://ssh").Parse()
|
|
|
|
assert.Nil(t, c.Init(uri))
|
|
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))
|
|
}
|