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