139 lines
2.9 KiB
Go
139 lines
2.9 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"
|
|
"decl/internal/codec"
|
|
"decl/internal/transport"
|
|
"io"
|
|
)
|
|
|
|
type MockResource struct {
|
|
*Common `json:",inline" yaml:",inline"`
|
|
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
|
|
InjectContentType func() string
|
|
InjectContentReaderStream func() (*transport.Reader, error)
|
|
InjectContentWriterStream func() (*transport.Writer, error)
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
/*
|
|
func (m *MockResource) SetParsedURI(URIParser) error {
|
|
return nil
|
|
}
|
|
*/
|
|
|
|
func (m *MockResource) UseConfig(config data.ConfigurationValueGetter) {
|
|
|
|
}
|
|
|
|
func (m *MockResource) LoadString(string, codec.Format) (error) {
|
|
return nil
|
|
}
|
|
|
|
func (m *MockResource) Load([]byte, codec.Format) (error) {
|
|
return nil
|
|
}
|
|
|
|
func (m *MockResource) LoadReader(io.ReadCloser, codec.Format) (error) {
|
|
return nil
|
|
}
|
|
|
|
func (m *MockResource) Create(context.Context) error {
|
|
return nil
|
|
}
|
|
|
|
func (m *MockResource) Update(context.Context) error {
|
|
return nil
|
|
}
|
|
|
|
func (m *MockResource) Delete(context.Context) error {
|
|
return nil
|
|
}
|
|
|
|
func (m *MockResource) ReadStat() error {
|
|
return nil
|
|
}
|
|
|
|
func (m *MockResource) ContentType() string {
|
|
if m.InjectContentType == nil {
|
|
return ""
|
|
}
|
|
return m.InjectContentType()
|
|
}
|
|
|
|
func (m *MockResource) ContentReaderStream() (*transport.Reader, error) {
|
|
return m.InjectContentReaderStream()
|
|
}
|
|
|
|
func (m *MockResource) ContentWriterStream() (*transport.Writer, error) {
|
|
return m.InjectContentWriterStream()
|
|
}
|
|
|
|
func (m *MockResource) GetContent(w io.Writer) (contentReader io.ReadCloser, err error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func (m *MockResource) SetContent(r io.Reader) error {
|
|
return nil
|
|
}
|