jx/internal/folio/mock_converter_test.go
Matthew Rich 55fd39f09d
Some checks are pending
Lint / golangci-lint (push) Waiting to run
Declarative Tests / test (push) Waiting to run
Declarative Tests / build-fedora (push) Waiting to run
Declarative Tests / build-ubuntu-focal (push) Waiting to run
add document imports
2024-09-24 19:22:49 +00:00

39 lines
1.1 KiB
Go

// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package folio
import (
"encoding/json"
"decl/internal/data"
)
type MockConverter struct {
InjectType func() data.TypeName `json:"-" yaml:"-"`
InjectEmit func(data.Document, data.ElementSelector) (data.Resource, error) `json:"-" yaml:"-"`
InjectExtract func(data.Resource, data.ElementSelector) (data.Document, error) `json:"-" yaml:"-"`
InjectClose func() (error) `json:"-" yaml:"-"`
}
func (m *MockConverter) Type() data.TypeName {
return m.InjectType()
}
func (m *MockConverter) Emit(document data.Document, filter data.ElementSelector) (data.Resource, error) {
return m.InjectEmit(document, filter)
}
func (m *MockConverter) Extract(sourceResource data.Resource, filter data.ElementSelector) (data.Document, error) {
return m.InjectExtract(sourceResource, filter)
}
func (m *MockConverter) Close() error {
return m.InjectClose()
}
func (m *MockConverter) UnmarshalJSON(data []byte) error {
if err := json.Unmarshal(data, m); err != nil {
return err
}
return nil
}