107 lines
2.7 KiB
Go
107 lines
2.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"
|
|
"decl/internal/data"
|
|
"decl/internal/codec"
|
|
"io"
|
|
"net/url"
|
|
)
|
|
|
|
type MockConfiguration struct {
|
|
InjectURI func() string `json:"-" yaml:"-"`
|
|
InjectType func() string `json:"-" yaml:"-"`
|
|
InjectResolveId func(ctx context.Context) string `json:"-" yaml:"-"`
|
|
InjectValidate 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:"-"`
|
|
InjectRead func(context.Context) ([]byte, error) `json:"-" yaml:"-"`
|
|
InjectGetValue func(key string) (any, error) `json:"-" yaml:"-"`
|
|
InjectHas func(key string) (bool) `json:"-" yaml:"-"`
|
|
}
|
|
|
|
func (m *MockConfiguration) Clone() data.Configuration {
|
|
return nil
|
|
}
|
|
|
|
func (m *MockConfiguration) SetURI(uri string) error {
|
|
return nil
|
|
}
|
|
|
|
func (m *MockConfiguration) SetParsedURI(uri *url.URL) error {
|
|
return nil
|
|
}
|
|
|
|
func (m *MockConfiguration) URI() string {
|
|
return m.InjectURI()
|
|
}
|
|
|
|
func (m *MockConfiguration) ResolveId(ctx context.Context) string {
|
|
return m.InjectResolveId(ctx)
|
|
}
|
|
|
|
func (m *MockConfiguration) JSON() ([]byte, error) {
|
|
return m.InjectJSON()
|
|
}
|
|
|
|
func (m *MockConfiguration) YAML() ([]byte, error) {
|
|
return m.InjectYAML()
|
|
}
|
|
|
|
func (m *MockConfiguration) PB() ([]byte, error) {
|
|
return m.InjectPB()
|
|
}
|
|
|
|
func (m *MockConfiguration) Generate(w io.Writer) (error) {
|
|
return m.InjectGenerate(w)
|
|
}
|
|
|
|
func (m *MockConfiguration) LoadString(docData string, format codec.Format) (error) {
|
|
return m.InjectLoadString(docData, format)
|
|
}
|
|
|
|
func (m *MockConfiguration) Load(docData []byte, format codec.Format) (error) {
|
|
return m.InjectLoad(docData, format)
|
|
}
|
|
|
|
func (m *MockConfiguration) LoadReader(r io.ReadCloser, format codec.Format) (error) {
|
|
return m.InjectLoadReader(r, format)
|
|
}
|
|
|
|
func (m *MockConfiguration) Read(ctx context.Context) ([]byte, error) {
|
|
return m.InjectRead(ctx)
|
|
}
|
|
|
|
func (m *MockConfiguration) Validate() error {
|
|
return m.InjectValidate()
|
|
}
|
|
|
|
func (m *MockConfiguration) Type() string {
|
|
return m.InjectType()
|
|
}
|
|
|
|
func (m *MockConfiguration) UnmarshalJSON(data []byte) error {
|
|
if err := json.Unmarshal(data, m); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (m *MockConfiguration) GetValue(key string) (any, error) {
|
|
return m.InjectGetValue(key)
|
|
}
|
|
|
|
func (m *MockConfiguration) Has(key string) (bool) {
|
|
return m.InjectHas(key)
|
|
}
|