jx/tests/mocks/resource.go
Matthew Rich 33dd463180
Some checks failed
Lint / golangci-lint (push) Failing after 9m53s
Declarative Tests / test (push) Failing after 58s
update resource schemas
2024-04-09 12:30:05 -07:00

55 lines
1.1 KiB
Go

// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package mocks
import (
"context"
_ "gopkg.in/yaml.v3"
"encoding/json"
_ "fmt"
)
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)
}
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
}