jx/internal/resource/service_test.go
Matthew Rich 8feb7b8d56
Some checks failed
Lint / golangci-lint (push) Failing after 10m1s
Declarative Tests / test (push) Failing after 14s
add support of import search paths [doublejynx/jx#7]
2024-10-16 10:26:42 -07:00

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))
}