143 lines
3.7 KiB
Go
143 lines
3.7 KiB
Go
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
|
|
|
package folio
|
|
|
|
import (
|
|
"context"
|
|
_ "gopkg.in/yaml.v3"
|
|
"encoding/json"
|
|
_ "fmt"
|
|
"gitea.rosskeen.house/rosskeen.house/machine"
|
|
"decl/internal/data"
|
|
"decl/internal/codec"
|
|
"io"
|
|
"net/url"
|
|
)
|
|
|
|
type MockResource struct {
|
|
InjectURI func() string `json:"-" yaml:"-"`
|
|
InjectType func() string `json:"-" yaml:"-"`
|
|
InjectResolveId func(ctx context.Context) string `json:"-" yaml:"-"`
|
|
InjectLoadDecl func(string) error `json:"-" yaml:"-"`
|
|
InjectValidate func() error `json:"-" yaml:"-"`
|
|
InjectApply func() error `json:"-" yaml:"-"`
|
|
InjectJSON func() ([]byte, error) `json:"-" yaml:"-"`
|
|
InjectYAML func() ([]byte, error) `json:"-" yaml:"-"`
|
|
InjectPB func() ([]byte, error) `json:"-" yaml:"-"`
|
|
InjectGenerate func(w io.Writer) (error) `json:"-" yaml:"-"`
|
|
InjectLoadString func(string, codec.Format) (error) `json:"-" yaml:"-"`
|
|
InjectLoad func([]byte, codec.Format) (error) `json:"-" yaml:"-"`
|
|
InjectLoadReader func(io.ReadCloser, codec.Format) (error) `json:"-" yaml:"-"`
|
|
InjectCreate func(context.Context) error `json:"-" yaml:"-"`
|
|
InjectRead func(context.Context) ([]byte, error) `json:"-" yaml:"-"`
|
|
InjectUpdate func(context.Context) error `json:"-" yaml:"-"`
|
|
InjectDelete func(context.Context) error `json:"-" yaml:"-"`
|
|
InjectStateMachine func() machine.Stater `json:"-" yaml:"-"`
|
|
InjectSetResourceMapper func(data.ResourceMapper) `json:"-" yaml:"-"`
|
|
InjectUseConfig func(data.ConfigurationValueGetter) `json:"-" yaml:"-"`
|
|
InjectNotify func(*machine.EventMessage) `json:"-" yaml:"-"`
|
|
}
|
|
|
|
func (m *MockResource) Clone() data.Resource {
|
|
return nil
|
|
}
|
|
|
|
func (m *MockResource) StateMachine() machine.Stater {
|
|
return nil
|
|
}
|
|
|
|
func (m *MockResource) UseConfig(config data.ConfigurationValueGetter) {
|
|
m.InjectUseConfig(config)
|
|
}
|
|
|
|
func (m *MockResource) SetURI(uri string) error {
|
|
return nil
|
|
}
|
|
|
|
func (m *MockResource) SetParsedURI(uri *url.URL) 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) SetResourceMapper(rm data.ResourceMapper) {
|
|
m.InjectSetResourceMapper(rm)
|
|
}
|
|
|
|
func (m *MockResource) LoadDecl(yamlResourceDeclaration string) error {
|
|
return m.InjectLoadDecl(yamlResourceDeclaration)
|
|
}
|
|
|
|
func (m *MockResource) JSON() ([]byte, error) {
|
|
return m.InjectJSON()
|
|
}
|
|
|
|
func (m *MockResource) YAML() ([]byte, error) {
|
|
return m.InjectYAML()
|
|
}
|
|
|
|
func (m *MockResource) PB() ([]byte, error) {
|
|
return m.InjectPB()
|
|
}
|
|
|
|
func (m *MockResource) Generate(w io.Writer) (error) {
|
|
return m.InjectGenerate(w)
|
|
}
|
|
|
|
func (m *MockResource) LoadString(docData string, format codec.Format) (error) {
|
|
return m.InjectLoadString(docData, format)
|
|
}
|
|
|
|
func (m *MockResource) Load(docData []byte, format codec.Format) (error) {
|
|
return m.InjectLoad(docData, format)
|
|
}
|
|
|
|
func (m *MockResource) LoadReader(r io.ReadCloser, format codec.Format) (error) {
|
|
return m.InjectLoadReader(r, format)
|
|
}
|
|
|
|
func (m *MockResource) Create(ctx context.Context) error {
|
|
return m.InjectCreate(ctx)
|
|
}
|
|
|
|
func (m *MockResource) Read(ctx context.Context) ([]byte, error) {
|
|
return m.InjectRead(ctx)
|
|
}
|
|
|
|
func (m *MockResource) Update(ctx context.Context) error {
|
|
return m.InjectUpdate(ctx)
|
|
}
|
|
|
|
func (m *MockResource) Delete(ctx context.Context) error {
|
|
return m.InjectDelete(ctx)
|
|
}
|
|
|
|
func (m *MockResource) Validate() error {
|
|
return m.InjectValidate()
|
|
}
|
|
|
|
func (m *MockResource) Apply() error {
|
|
return m.InjectApply()
|
|
}
|
|
|
|
func (m *MockResource) Type() string {
|
|
return m.InjectType()
|
|
}
|
|
|
|
func (m *MockResource) Notify(em *machine.EventMessage) {
|
|
m.InjectNotify(em)
|
|
}
|
|
|
|
func (m *MockResource) UnmarshalJSON(data []byte) error {
|
|
if err := json.Unmarshal(data, m); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|