2024-03-20 19:23:31 +00:00
|
|
|
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
2024-04-21 18:06:53 +00:00
|
|
|
|
|
|
|
package resource
|
2024-03-20 16:15:27 +00:00
|
|
|
|
2024-03-20 19:23:31 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
_ "gopkg.in/yaml.v3"
|
2024-04-03 16:54:50 +00:00
|
|
|
"encoding/json"
|
2024-04-03 23:14:48 +00:00
|
|
|
_ "fmt"
|
2024-05-06 00:48:54 +00:00
|
|
|
"gitea.rosskeen.house/rosskeen.house/machine"
|
2024-09-19 08:11:57 +00:00
|
|
|
"decl/internal/data"
|
2024-03-20 19:23:31 +00:00
|
|
|
)
|
|
|
|
|
2024-03-20 16:15:27 +00:00
|
|
|
type MockResource struct {
|
2024-03-20 19:23:31 +00:00
|
|
|
InjectURI func() string
|
|
|
|
InjectType func() string
|
2024-03-22 04:35:17 +00:00
|
|
|
InjectResolveId func(ctx context.Context) string
|
2024-03-20 16:15:27 +00:00
|
|
|
InjectLoadDecl func(string) error
|
2024-04-09 19:30:05 +00:00
|
|
|
InjectValidate func() error
|
2024-03-20 16:15:27 +00:00
|
|
|
InjectApply func() error
|
2024-03-20 19:23:31 +00:00
|
|
|
InjectRead func(context.Context) ([]byte, error)
|
2024-05-06 00:48:54 +00:00
|
|
|
InjectStateMachine func() machine.Stater
|
2024-03-20 19:23:31 +00:00
|
|
|
}
|
|
|
|
|
2024-09-19 08:11:57 +00:00
|
|
|
func (m *MockResource) Clone() data.Resource {
|
2024-04-21 18:06:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-05-06 00:48:54 +00:00
|
|
|
func (m *MockResource) StateMachine() machine.Stater {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-04-21 18:06:53 +00:00
|
|
|
func (m *MockResource) SetURI(uri string) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-03-20 19:23:31 +00:00
|
|
|
func (m *MockResource) URI() string {
|
|
|
|
return m.InjectURI()
|
2024-03-20 16:15:27 +00:00
|
|
|
}
|
|
|
|
|
2024-03-22 04:35:17 +00:00
|
|
|
func (m *MockResource) ResolveId(ctx context.Context) string {
|
2024-04-03 21:23:57 +00:00
|
|
|
return m.InjectResolveId(ctx)
|
2024-03-22 04:35:17 +00:00
|
|
|
}
|
|
|
|
|
2024-03-20 16:15:27 +00:00
|
|
|
func (m *MockResource) LoadDecl(yamlResourceDeclaration string) error {
|
|
|
|
return m.InjectLoadDecl(yamlResourceDeclaration)
|
|
|
|
}
|
|
|
|
|
2024-04-09 19:30:05 +00:00
|
|
|
func (m *MockResource) Validate() error {
|
|
|
|
return m.InjectValidate()
|
|
|
|
}
|
|
|
|
|
2024-03-20 16:15:27 +00:00
|
|
|
func (m *MockResource) Apply() error {
|
|
|
|
return m.InjectApply()
|
|
|
|
}
|
2024-03-20 19:23:31 +00:00
|
|
|
|
|
|
|
func (m *MockResource) Read(ctx context.Context) ([]byte, error) {
|
|
|
|
return m.InjectRead(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockResource) Type() string {
|
|
|
|
return m.InjectType()
|
|
|
|
}
|
2024-04-03 16:54:50 +00:00
|
|
|
|
|
|
|
func (m *MockResource) UnmarshalJSON(data []byte) error {
|
|
|
|
if err := json.Unmarshal(data, m); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|