jx/tests/mocks/resource.go

50 lines
1.0 KiB
Go
Raw Permalink Normal View History

2024-03-20 19:23:31 +00:00
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
2024-03-20 16:15:27 +00:00
package mocks
2024-03-20 19:23:31 +00:00
import (
"context"
_ "gopkg.in/yaml.v3"
"encoding/json"
2024-04-03 23:14:48 +00:00
_ "fmt"
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
InjectApply func() error
2024-03-20 19:23:31 +00:00
InjectRead func(context.Context) ([]byte, error)
}
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)
}
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()
}
func (m *MockResource) UnmarshalJSON(data []byte) error {
if err := json.Unmarshal(data, m); err != nil {
return err
}
return nil
}