jx/internal/resource/mock_buffer_resource_test.go

35 lines
1.0 KiB
Go

// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package resource
import (
"context"
_ "gopkg.in/yaml.v3"
"gitea.rosskeen.house/rosskeen.house/machine"
"decl/internal/transport"
"decl/internal/ext"
"strings"
"io"
)
func NewMockBufferResource(id string, target *strings.Builder) *MockResource {
return &MockResource {
InjectType: func() string { return "buffer" },
InjectResolveId: func(ctx context.Context) string { return id },
InjectRead: func(ctx context.Context) ([]byte, error) { return nil,nil },
InjectLoadDecl: func(string) error { return nil },
InjectApply: func() error { return nil },
InjectStateMachine: func() machine.Stater { return nil },
InjectContentWriterStream: func() (*transport.Writer, error) {
w := &transport.Writer{}
w.SetStream(ext.WriteNopCloser(target))
return w, nil
},
InjectContentReaderStream: func() (*transport.Reader, error) {
r := &transport.Reader{}
r.SetStream(io.NopCloser(strings.NewReader(target.String())))
return r, nil
},
}
}