jx/internal/resource/mock_resource_test.go
Matthew Rich 8094d1c063
Some checks are pending
Lint / golangci-lint (push) Waiting to run
Declarative Tests / test (push) Waiting to run
Declarative Tests / build-fedora (push) Waiting to run
Declarative Tests / build-ubuntu-focal (push) Waiting to run
add build support to container_image resource; add more testing
2024-09-19 08:11:57 +00:00

71 lines
1.5 KiB
Go

// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package resource
import (
"context"
_ "gopkg.in/yaml.v3"
"encoding/json"
_ "fmt"
"gitea.rosskeen.house/rosskeen.house/machine"
"decl/internal/data"
)
type MockResource struct {
InjectURI func() string
InjectType func() string
InjectResolveId func(ctx context.Context) string
InjectLoadDecl func(string) error
InjectValidate func() error
InjectApply func() error
InjectRead func(context.Context) ([]byte, error)
InjectStateMachine func() machine.Stater
}
func (m *MockResource) Clone() data.Resource {
return nil
}
func (m *MockResource) StateMachine() machine.Stater {
return nil
}
func (m *MockResource) SetURI(uri string) error {
return nil
}
func (m *MockResource) URI() string {
return m.InjectURI()
}
func (m *MockResource) ResolveId(ctx context.Context) string {
return m.InjectResolveId(ctx)
}
func (m *MockResource) LoadDecl(yamlResourceDeclaration string) error {
return m.InjectLoadDecl(yamlResourceDeclaration)
}
func (m *MockResource) Validate() error {
return m.InjectValidate()
}
func (m *MockResource) Apply() error {
return m.InjectApply()
}
func (m *MockResource) Read(ctx context.Context) ([]byte, error) {
return m.InjectRead(ctx)
}
func (m *MockResource) Type() string {
return m.InjectType()
}
func (m *MockResource) UnmarshalJSON(data []byte) error {
if err := json.Unmarshal(data, m); err != nil {
return err
}
return nil
}