зеркало из https://github.com/Azure/ARO-RP.git
update go-cosmosdb
This commit is contained in:
Родитель
ca261012fd
Коммит
2eefc6d8f0
|
@ -701,14 +701,14 @@
|
|||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:11a561b078819a1cd5d9d9c52031e8476e9ee7622f2b3b054850940a7d167971"
|
||||
digest = "1:98afffae13f349c0963814f73abbe86003bb1f8be44c4829a1e5e782b5aab9b0"
|
||||
name = "github.com/jim-minter/go-cosmosdb"
|
||||
packages = [
|
||||
"cmd/gencosmosdb",
|
||||
"pkg/gencosmosdb",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "0e3ac7c97cf21cf5fcd6315b6ed273db35b3c531"
|
||||
revision = "1528d2db09d65eb9a8a1df75f0ba1d5add4bcf44"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:bb81097a5b62634f3e9fec1014657855610c82d19b9a40c17612e32651e35dca"
|
||||
|
@ -2408,9 +2408,11 @@
|
|||
"sigs.k8s.io/controller-runtime",
|
||||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil",
|
||||
"sigs.k8s.io/controller-runtime/pkg/event",
|
||||
"sigs.k8s.io/controller-runtime/pkg/handler",
|
||||
"sigs.k8s.io/controller-runtime/pkg/predicate",
|
||||
"sigs.k8s.io/controller-runtime/pkg/reconcile",
|
||||
"sigs.k8s.io/controller-runtime/pkg/scheme",
|
||||
"sigs.k8s.io/controller-runtime/pkg/source",
|
||||
"sigs.k8s.io/controller-tools/cmd/controller-gen",
|
||||
]
|
||||
solver-name = "gps-cdcl"
|
||||
|
|
|
@ -553,7 +553,7 @@
|
|||
"component": {
|
||||
"type": "git",
|
||||
"git": {
|
||||
"commitHash": "0e3ac7c97cf21cf5fcd6315b6ed273db35b3c531",
|
||||
"commitHash": "1528d2db09d65eb9a8a1df75f0ba1d5add4bcf44",
|
||||
"repositoryUrl": "https://github.com/jim-minter/go-cosmosdb/"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ type asyncOperationDocumentClient struct {
|
|||
// AsyncOperationDocumentClient is a asyncOperationDocument client
|
||||
type AsyncOperationDocumentClient interface {
|
||||
Create(context.Context, string, *pkg.AsyncOperationDocument, *Options) (*pkg.AsyncOperationDocument, error)
|
||||
List(*Options) AsyncOperationDocumentRawIterator
|
||||
List(*Options) AsyncOperationDocumentIterator
|
||||
ListAll(context.Context, *Options) (*pkg.AsyncOperationDocuments, error)
|
||||
Get(context.Context, string, string, *Options) (*pkg.AsyncOperationDocument, error)
|
||||
Replace(context.Context, string, *pkg.AsyncOperationDocument, *Options) (*pkg.AsyncOperationDocument, error)
|
||||
|
@ -109,7 +109,7 @@ func (c *asyncOperationDocumentClient) Create(ctx context.Context, partitionkey
|
|||
return
|
||||
}
|
||||
|
||||
func (c *asyncOperationDocumentClient) List(options *Options) AsyncOperationDocumentRawIterator {
|
||||
func (c *asyncOperationDocumentClient) List(options *Options) AsyncOperationDocumentIterator {
|
||||
continuation := ""
|
||||
if options != nil {
|
||||
continuation = options.Continuation
|
||||
|
@ -239,11 +239,6 @@ func (i *asyncOperationDocumentChangeFeedIterator) Continuation() string {
|
|||
}
|
||||
|
||||
func (i *asyncOperationDocumentListIterator) Next(ctx context.Context, maxItemCount int) (asyncOperationDocuments *pkg.AsyncOperationDocuments, err error) {
|
||||
err = i.NextRaw(ctx, maxItemCount, &asyncOperationDocuments)
|
||||
return
|
||||
}
|
||||
|
||||
func (i *asyncOperationDocumentListIterator) NextRaw(ctx context.Context, maxItemCount int, raw interface{}) (err error) {
|
||||
if i.done {
|
||||
return
|
||||
}
|
||||
|
@ -259,7 +254,7 @@ func (i *asyncOperationDocumentListIterator) NextRaw(ctx context.Context, maxIte
|
|||
return
|
||||
}
|
||||
|
||||
err = i.do(ctx, http.MethodGet, i.path+"/docs", "docs", i.path, http.StatusOK, nil, &raw, headers)
|
||||
err = i.do(ctx, http.MethodGet, i.path+"/docs", "docs", i.path, http.StatusOK, nil, &asyncOperationDocuments, headers)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -0,0 +1,360 @@
|
|||
// Code generated by github.com/jim-minter/go-cosmosdb, DO NOT EDIT.
|
||||
|
||||
package cosmosdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"github.com/ugorji/go/codec"
|
||||
|
||||
pkg "github.com/Azure/ARO-RP/pkg/api"
|
||||
)
|
||||
|
||||
type fakeAsyncOperationDocumentTriggerHandler func(context.Context, *pkg.AsyncOperationDocument) error
|
||||
type fakeAsyncOperationDocumentQueryHandler func(AsyncOperationDocumentClient, *Query, *Options) AsyncOperationDocumentRawIterator
|
||||
|
||||
var _ AsyncOperationDocumentClient = &FakeAsyncOperationDocumentClient{}
|
||||
|
||||
// NewFakeAsyncOperationDocumentClient returns a FakeAsyncOperationDocumentClient
|
||||
func NewFakeAsyncOperationDocumentClient(h *codec.JsonHandle) *FakeAsyncOperationDocumentClient {
|
||||
return &FakeAsyncOperationDocumentClient{
|
||||
asyncOperationDocuments: make(map[string][]byte),
|
||||
triggerHandlers: make(map[string]fakeAsyncOperationDocumentTriggerHandler),
|
||||
queryHandlers: make(map[string]fakeAsyncOperationDocumentQueryHandler),
|
||||
jsonHandle: h,
|
||||
lock: &sync.RWMutex{},
|
||||
}
|
||||
}
|
||||
|
||||
// FakeAsyncOperationDocumentClient is a FakeAsyncOperationDocumentClient
|
||||
type FakeAsyncOperationDocumentClient struct {
|
||||
asyncOperationDocuments map[string][]byte
|
||||
jsonHandle *codec.JsonHandle
|
||||
lock *sync.RWMutex
|
||||
triggerHandlers map[string]fakeAsyncOperationDocumentTriggerHandler
|
||||
queryHandlers map[string]fakeAsyncOperationDocumentQueryHandler
|
||||
sorter func([]*pkg.AsyncOperationDocument)
|
||||
|
||||
// returns true if documents conflict
|
||||
conflictChecker func(*pkg.AsyncOperationDocument, *pkg.AsyncOperationDocument) bool
|
||||
|
||||
// err, if not nil, is an error to return when attempting to communicate
|
||||
// with this Client
|
||||
err error
|
||||
}
|
||||
|
||||
func (c *FakeAsyncOperationDocumentClient) decodeAsyncOperationDocument(s []byte) (asyncOperationDocument *pkg.AsyncOperationDocument, err error) {
|
||||
err = codec.NewDecoderBytes(s, c.jsonHandle).Decode(&asyncOperationDocument)
|
||||
return
|
||||
}
|
||||
|
||||
func (c *FakeAsyncOperationDocumentClient) encodeAsyncOperationDocument(asyncOperationDocument *pkg.AsyncOperationDocument) (b []byte, err error) {
|
||||
err = codec.NewEncoderBytes(&b, c.jsonHandle).Encode(asyncOperationDocument)
|
||||
return
|
||||
}
|
||||
|
||||
// SetError sets or unsets an error that will be returned on any
|
||||
// FakeAsyncOperationDocumentClient method invocation
|
||||
func (c *FakeAsyncOperationDocumentClient) SetError(err error) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
c.err = err
|
||||
}
|
||||
|
||||
// SetSorter sets or unsets a sorter function which will be used to sort values
|
||||
// returned by List() for test stability
|
||||
func (c *FakeAsyncOperationDocumentClient) SetSorter(sorter func([]*pkg.AsyncOperationDocument)) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
c.sorter = sorter
|
||||
}
|
||||
|
||||
// SetConflictChecker sets or unsets a function which can be used to validate
|
||||
// additional unique keys in a AsyncOperationDocument
|
||||
func (c *FakeAsyncOperationDocumentClient) SetConflictChecker(conflictChecker func(*pkg.AsyncOperationDocument, *pkg.AsyncOperationDocument) bool) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
c.conflictChecker = conflictChecker
|
||||
}
|
||||
|
||||
// SetTriggerHandler sets or unsets a trigger handler
|
||||
func (c *FakeAsyncOperationDocumentClient) SetTriggerHandler(triggerName string, trigger fakeAsyncOperationDocumentTriggerHandler) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
c.triggerHandlers[triggerName] = trigger
|
||||
}
|
||||
|
||||
// SetQueryHandler sets or unsets a query handler
|
||||
func (c *FakeAsyncOperationDocumentClient) SetQueryHandler(queryName string, query fakeAsyncOperationDocumentQueryHandler) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
c.queryHandlers[queryName] = query
|
||||
}
|
||||
|
||||
func (c *FakeAsyncOperationDocumentClient) deepCopy(asyncOperationDocument *pkg.AsyncOperationDocument) (*pkg.AsyncOperationDocument, error) {
|
||||
b, err := c.encodeAsyncOperationDocument(asyncOperationDocument)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return c.decodeAsyncOperationDocument(b)
|
||||
}
|
||||
|
||||
func (c *FakeAsyncOperationDocumentClient) apply(ctx context.Context, partitionkey string, asyncOperationDocument *pkg.AsyncOperationDocument, options *Options, isCreate bool) (*pkg.AsyncOperationDocument, error) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
if c.err != nil {
|
||||
return nil, c.err
|
||||
}
|
||||
|
||||
asyncOperationDocument, err := c.deepCopy(asyncOperationDocument) // copy now because pretriggers can mutate asyncOperationDocument
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if options != nil {
|
||||
err := c.processPreTriggers(ctx, asyncOperationDocument, options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
_, exists := c.asyncOperationDocuments[asyncOperationDocument.ID]
|
||||
if isCreate && exists {
|
||||
return nil, &Error{
|
||||
StatusCode: http.StatusConflict,
|
||||
Message: "Entity with the specified id already exists in the system",
|
||||
}
|
||||
}
|
||||
if !isCreate && !exists {
|
||||
return nil, &Error{StatusCode: http.StatusNotFound}
|
||||
}
|
||||
|
||||
if c.conflictChecker != nil {
|
||||
for id := range c.asyncOperationDocuments {
|
||||
asyncOperationDocumentToCheck, err := c.decodeAsyncOperationDocument(c.asyncOperationDocuments[id])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if c.conflictChecker(asyncOperationDocumentToCheck, asyncOperationDocument) {
|
||||
return nil, &Error{
|
||||
StatusCode: http.StatusConflict,
|
||||
Message: "Entity with the specified id already exists in the system",
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
b, err := c.encodeAsyncOperationDocument(asyncOperationDocument)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c.asyncOperationDocuments[asyncOperationDocument.ID] = b
|
||||
|
||||
return asyncOperationDocument, nil
|
||||
}
|
||||
|
||||
// Create creates a AsyncOperationDocument in the database
|
||||
func (c *FakeAsyncOperationDocumentClient) Create(ctx context.Context, partitionkey string, asyncOperationDocument *pkg.AsyncOperationDocument, options *Options) (*pkg.AsyncOperationDocument, error) {
|
||||
return c.apply(ctx, partitionkey, asyncOperationDocument, options, true)
|
||||
}
|
||||
|
||||
// Replace replaces a AsyncOperationDocument in the database
|
||||
func (c *FakeAsyncOperationDocumentClient) Replace(ctx context.Context, partitionkey string, asyncOperationDocument *pkg.AsyncOperationDocument, options *Options) (*pkg.AsyncOperationDocument, error) {
|
||||
return c.apply(ctx, partitionkey, asyncOperationDocument, options, false)
|
||||
}
|
||||
|
||||
// List returns a AsyncOperationDocumentIterator to list all AsyncOperationDocuments in the database
|
||||
func (c *FakeAsyncOperationDocumentClient) List(*Options) AsyncOperationDocumentIterator {
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
|
||||
if c.err != nil {
|
||||
return NewFakeAsyncOperationDocumentErroringRawIterator(c.err)
|
||||
}
|
||||
|
||||
asyncOperationDocuments := make([]*pkg.AsyncOperationDocument, 0, len(c.asyncOperationDocuments))
|
||||
for _, d := range c.asyncOperationDocuments {
|
||||
r, err := c.decodeAsyncOperationDocument(d)
|
||||
if err != nil {
|
||||
return NewFakeAsyncOperationDocumentErroringRawIterator(err)
|
||||
}
|
||||
asyncOperationDocuments = append(asyncOperationDocuments, r)
|
||||
}
|
||||
|
||||
if c.sorter != nil {
|
||||
c.sorter(asyncOperationDocuments)
|
||||
}
|
||||
|
||||
return NewFakeAsyncOperationDocumentIterator(asyncOperationDocuments, 0)
|
||||
}
|
||||
|
||||
// ListAll lists all AsyncOperationDocuments in the database
|
||||
func (c *FakeAsyncOperationDocumentClient) ListAll(ctx context.Context, options *Options) (*pkg.AsyncOperationDocuments, error) {
|
||||
iter := c.List(options)
|
||||
return iter.Next(ctx, -1)
|
||||
}
|
||||
|
||||
// Get gets a AsyncOperationDocument from the database
|
||||
func (c *FakeAsyncOperationDocumentClient) Get(ctx context.Context, partitionkey string, id string, options *Options) (*pkg.AsyncOperationDocument, error) {
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
|
||||
if c.err != nil {
|
||||
return nil, c.err
|
||||
}
|
||||
|
||||
asyncOperationDocument, exists := c.asyncOperationDocuments[id]
|
||||
if !exists {
|
||||
return nil, &Error{StatusCode: http.StatusNotFound}
|
||||
}
|
||||
|
||||
return c.decodeAsyncOperationDocument(asyncOperationDocument)
|
||||
}
|
||||
|
||||
// Delete deletes a AsyncOperationDocument from the database
|
||||
func (c *FakeAsyncOperationDocumentClient) Delete(ctx context.Context, partitionKey string, asyncOperationDocument *pkg.AsyncOperationDocument, options *Options) error {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
if c.err != nil {
|
||||
return c.err
|
||||
}
|
||||
|
||||
_, exists := c.asyncOperationDocuments[asyncOperationDocument.ID]
|
||||
if !exists {
|
||||
return &Error{StatusCode: http.StatusNotFound}
|
||||
}
|
||||
|
||||
delete(c.asyncOperationDocuments, asyncOperationDocument.ID)
|
||||
return nil
|
||||
}
|
||||
|
||||
// ChangeFeed is unimplemented
|
||||
func (c *FakeAsyncOperationDocumentClient) ChangeFeed(*Options) AsyncOperationDocumentIterator {
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
|
||||
if c.err != nil {
|
||||
return NewFakeAsyncOperationDocumentErroringRawIterator(c.err)
|
||||
}
|
||||
|
||||
return NewFakeAsyncOperationDocumentErroringRawIterator(ErrNotImplemented)
|
||||
}
|
||||
|
||||
func (c *FakeAsyncOperationDocumentClient) processPreTriggers(ctx context.Context, asyncOperationDocument *pkg.AsyncOperationDocument, options *Options) error {
|
||||
for _, triggerName := range options.PreTriggers {
|
||||
if triggerHandler := c.triggerHandlers[triggerName]; triggerHandler != nil {
|
||||
err := triggerHandler(ctx, asyncOperationDocument)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Query calls a query handler to implement database querying
|
||||
func (c *FakeAsyncOperationDocumentClient) Query(name string, query *Query, options *Options) AsyncOperationDocumentRawIterator {
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
|
||||
if c.err != nil {
|
||||
return NewFakeAsyncOperationDocumentErroringRawIterator(c.err)
|
||||
}
|
||||
|
||||
if queryHandler := c.queryHandlers[query.Query]; queryHandler != nil {
|
||||
return queryHandler(c, query, options)
|
||||
}
|
||||
|
||||
return NewFakeAsyncOperationDocumentErroringRawIterator(ErrNotImplemented)
|
||||
}
|
||||
|
||||
// QueryAll calls a query handler to implement database querying
|
||||
func (c *FakeAsyncOperationDocumentClient) QueryAll(ctx context.Context, partitionkey string, query *Query, options *Options) (*pkg.AsyncOperationDocuments, error) {
|
||||
iter := c.Query("", query, options)
|
||||
return iter.Next(ctx, -1)
|
||||
}
|
||||
|
||||
func NewFakeAsyncOperationDocumentIterator(asyncOperationDocuments []*pkg.AsyncOperationDocument, continuation int) AsyncOperationDocumentRawIterator {
|
||||
return &fakeAsyncOperationDocumentIterator{asyncOperationDocuments: asyncOperationDocuments, continuation: continuation}
|
||||
}
|
||||
|
||||
type fakeAsyncOperationDocumentIterator struct {
|
||||
asyncOperationDocuments []*pkg.AsyncOperationDocument
|
||||
continuation int
|
||||
done bool
|
||||
}
|
||||
|
||||
func (i *fakeAsyncOperationDocumentIterator) NextRaw(ctx context.Context, maxItemCount int, out interface{}) error {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
|
||||
func (i *fakeAsyncOperationDocumentIterator) Next(ctx context.Context, maxItemCount int) (*pkg.AsyncOperationDocuments, error) {
|
||||
if i.done {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var asyncOperationDocuments []*pkg.AsyncOperationDocument
|
||||
if maxItemCount == -1 {
|
||||
asyncOperationDocuments = i.asyncOperationDocuments[i.continuation:]
|
||||
i.continuation = len(i.asyncOperationDocuments)
|
||||
i.done = true
|
||||
} else {
|
||||
max := i.continuation + maxItemCount
|
||||
if max > len(i.asyncOperationDocuments) {
|
||||
max = len(i.asyncOperationDocuments)
|
||||
}
|
||||
asyncOperationDocuments = i.asyncOperationDocuments[i.continuation:max]
|
||||
i.continuation += max
|
||||
i.done = i.Continuation() == ""
|
||||
}
|
||||
|
||||
return &pkg.AsyncOperationDocuments{
|
||||
AsyncOperationDocuments: asyncOperationDocuments,
|
||||
Count: len(asyncOperationDocuments),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (i *fakeAsyncOperationDocumentIterator) Continuation() string {
|
||||
if i.continuation >= len(i.asyncOperationDocuments) {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf("%d", i.continuation)
|
||||
}
|
||||
|
||||
// NewFakeAsyncOperationDocumentErroringRawIterator returns a AsyncOperationDocumentRawIterator which
|
||||
// whose methods return the given error
|
||||
func NewFakeAsyncOperationDocumentErroringRawIterator(err error) AsyncOperationDocumentRawIterator {
|
||||
return &fakeAsyncOperationDocumentErroringRawIterator{err: err}
|
||||
}
|
||||
|
||||
type fakeAsyncOperationDocumentErroringRawIterator struct {
|
||||
err error
|
||||
}
|
||||
|
||||
func (i *fakeAsyncOperationDocumentErroringRawIterator) Next(ctx context.Context, maxItemCount int) (*pkg.AsyncOperationDocuments, error) {
|
||||
return nil, i.err
|
||||
}
|
||||
|
||||
func (i *fakeAsyncOperationDocumentErroringRawIterator) NextRaw(context.Context, int, interface{}) error {
|
||||
return i.err
|
||||
}
|
||||
|
||||
func (i *fakeAsyncOperationDocumentErroringRawIterator) Continuation() string {
|
||||
return ""
|
||||
}
|
|
@ -19,7 +19,7 @@ type billingDocumentClient struct {
|
|||
// BillingDocumentClient is a billingDocument client
|
||||
type BillingDocumentClient interface {
|
||||
Create(context.Context, string, *pkg.BillingDocument, *Options) (*pkg.BillingDocument, error)
|
||||
List(*Options) BillingDocumentRawIterator
|
||||
List(*Options) BillingDocumentIterator
|
||||
ListAll(context.Context, *Options) (*pkg.BillingDocuments, error)
|
||||
Get(context.Context, string, string, *Options) (*pkg.BillingDocument, error)
|
||||
Replace(context.Context, string, *pkg.BillingDocument, *Options) (*pkg.BillingDocument, error)
|
||||
|
@ -109,7 +109,7 @@ func (c *billingDocumentClient) Create(ctx context.Context, partitionkey string,
|
|||
return
|
||||
}
|
||||
|
||||
func (c *billingDocumentClient) List(options *Options) BillingDocumentRawIterator {
|
||||
func (c *billingDocumentClient) List(options *Options) BillingDocumentIterator {
|
||||
continuation := ""
|
||||
if options != nil {
|
||||
continuation = options.Continuation
|
||||
|
@ -239,11 +239,6 @@ func (i *billingDocumentChangeFeedIterator) Continuation() string {
|
|||
}
|
||||
|
||||
func (i *billingDocumentListIterator) Next(ctx context.Context, maxItemCount int) (billingDocuments *pkg.BillingDocuments, err error) {
|
||||
err = i.NextRaw(ctx, maxItemCount, &billingDocuments)
|
||||
return
|
||||
}
|
||||
|
||||
func (i *billingDocumentListIterator) NextRaw(ctx context.Context, maxItemCount int, raw interface{}) (err error) {
|
||||
if i.done {
|
||||
return
|
||||
}
|
||||
|
@ -259,7 +254,7 @@ func (i *billingDocumentListIterator) NextRaw(ctx context.Context, maxItemCount
|
|||
return
|
||||
}
|
||||
|
||||
err = i.do(ctx, http.MethodGet, i.path+"/docs", "docs", i.path, http.StatusOK, nil, &raw, headers)
|
||||
err = i.do(ctx, http.MethodGet, i.path+"/docs", "docs", i.path, http.StatusOK, nil, &billingDocuments, headers)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -0,0 +1,360 @@
|
|||
// Code generated by github.com/jim-minter/go-cosmosdb, DO NOT EDIT.
|
||||
|
||||
package cosmosdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"github.com/ugorji/go/codec"
|
||||
|
||||
pkg "github.com/Azure/ARO-RP/pkg/api"
|
||||
)
|
||||
|
||||
type fakeBillingDocumentTriggerHandler func(context.Context, *pkg.BillingDocument) error
|
||||
type fakeBillingDocumentQueryHandler func(BillingDocumentClient, *Query, *Options) BillingDocumentRawIterator
|
||||
|
||||
var _ BillingDocumentClient = &FakeBillingDocumentClient{}
|
||||
|
||||
// NewFakeBillingDocumentClient returns a FakeBillingDocumentClient
|
||||
func NewFakeBillingDocumentClient(h *codec.JsonHandle) *FakeBillingDocumentClient {
|
||||
return &FakeBillingDocumentClient{
|
||||
billingDocuments: make(map[string][]byte),
|
||||
triggerHandlers: make(map[string]fakeBillingDocumentTriggerHandler),
|
||||
queryHandlers: make(map[string]fakeBillingDocumentQueryHandler),
|
||||
jsonHandle: h,
|
||||
lock: &sync.RWMutex{},
|
||||
}
|
||||
}
|
||||
|
||||
// FakeBillingDocumentClient is a FakeBillingDocumentClient
|
||||
type FakeBillingDocumentClient struct {
|
||||
billingDocuments map[string][]byte
|
||||
jsonHandle *codec.JsonHandle
|
||||
lock *sync.RWMutex
|
||||
triggerHandlers map[string]fakeBillingDocumentTriggerHandler
|
||||
queryHandlers map[string]fakeBillingDocumentQueryHandler
|
||||
sorter func([]*pkg.BillingDocument)
|
||||
|
||||
// returns true if documents conflict
|
||||
conflictChecker func(*pkg.BillingDocument, *pkg.BillingDocument) bool
|
||||
|
||||
// err, if not nil, is an error to return when attempting to communicate
|
||||
// with this Client
|
||||
err error
|
||||
}
|
||||
|
||||
func (c *FakeBillingDocumentClient) decodeBillingDocument(s []byte) (billingDocument *pkg.BillingDocument, err error) {
|
||||
err = codec.NewDecoderBytes(s, c.jsonHandle).Decode(&billingDocument)
|
||||
return
|
||||
}
|
||||
|
||||
func (c *FakeBillingDocumentClient) encodeBillingDocument(billingDocument *pkg.BillingDocument) (b []byte, err error) {
|
||||
err = codec.NewEncoderBytes(&b, c.jsonHandle).Encode(billingDocument)
|
||||
return
|
||||
}
|
||||
|
||||
// SetError sets or unsets an error that will be returned on any
|
||||
// FakeBillingDocumentClient method invocation
|
||||
func (c *FakeBillingDocumentClient) SetError(err error) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
c.err = err
|
||||
}
|
||||
|
||||
// SetSorter sets or unsets a sorter function which will be used to sort values
|
||||
// returned by List() for test stability
|
||||
func (c *FakeBillingDocumentClient) SetSorter(sorter func([]*pkg.BillingDocument)) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
c.sorter = sorter
|
||||
}
|
||||
|
||||
// SetConflictChecker sets or unsets a function which can be used to validate
|
||||
// additional unique keys in a BillingDocument
|
||||
func (c *FakeBillingDocumentClient) SetConflictChecker(conflictChecker func(*pkg.BillingDocument, *pkg.BillingDocument) bool) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
c.conflictChecker = conflictChecker
|
||||
}
|
||||
|
||||
// SetTriggerHandler sets or unsets a trigger handler
|
||||
func (c *FakeBillingDocumentClient) SetTriggerHandler(triggerName string, trigger fakeBillingDocumentTriggerHandler) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
c.triggerHandlers[triggerName] = trigger
|
||||
}
|
||||
|
||||
// SetQueryHandler sets or unsets a query handler
|
||||
func (c *FakeBillingDocumentClient) SetQueryHandler(queryName string, query fakeBillingDocumentQueryHandler) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
c.queryHandlers[queryName] = query
|
||||
}
|
||||
|
||||
func (c *FakeBillingDocumentClient) deepCopy(billingDocument *pkg.BillingDocument) (*pkg.BillingDocument, error) {
|
||||
b, err := c.encodeBillingDocument(billingDocument)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return c.decodeBillingDocument(b)
|
||||
}
|
||||
|
||||
func (c *FakeBillingDocumentClient) apply(ctx context.Context, partitionkey string, billingDocument *pkg.BillingDocument, options *Options, isCreate bool) (*pkg.BillingDocument, error) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
if c.err != nil {
|
||||
return nil, c.err
|
||||
}
|
||||
|
||||
billingDocument, err := c.deepCopy(billingDocument) // copy now because pretriggers can mutate billingDocument
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if options != nil {
|
||||
err := c.processPreTriggers(ctx, billingDocument, options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
_, exists := c.billingDocuments[billingDocument.ID]
|
||||
if isCreate && exists {
|
||||
return nil, &Error{
|
||||
StatusCode: http.StatusConflict,
|
||||
Message: "Entity with the specified id already exists in the system",
|
||||
}
|
||||
}
|
||||
if !isCreate && !exists {
|
||||
return nil, &Error{StatusCode: http.StatusNotFound}
|
||||
}
|
||||
|
||||
if c.conflictChecker != nil {
|
||||
for id := range c.billingDocuments {
|
||||
billingDocumentToCheck, err := c.decodeBillingDocument(c.billingDocuments[id])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if c.conflictChecker(billingDocumentToCheck, billingDocument) {
|
||||
return nil, &Error{
|
||||
StatusCode: http.StatusConflict,
|
||||
Message: "Entity with the specified id already exists in the system",
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
b, err := c.encodeBillingDocument(billingDocument)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c.billingDocuments[billingDocument.ID] = b
|
||||
|
||||
return billingDocument, nil
|
||||
}
|
||||
|
||||
// Create creates a BillingDocument in the database
|
||||
func (c *FakeBillingDocumentClient) Create(ctx context.Context, partitionkey string, billingDocument *pkg.BillingDocument, options *Options) (*pkg.BillingDocument, error) {
|
||||
return c.apply(ctx, partitionkey, billingDocument, options, true)
|
||||
}
|
||||
|
||||
// Replace replaces a BillingDocument in the database
|
||||
func (c *FakeBillingDocumentClient) Replace(ctx context.Context, partitionkey string, billingDocument *pkg.BillingDocument, options *Options) (*pkg.BillingDocument, error) {
|
||||
return c.apply(ctx, partitionkey, billingDocument, options, false)
|
||||
}
|
||||
|
||||
// List returns a BillingDocumentIterator to list all BillingDocuments in the database
|
||||
func (c *FakeBillingDocumentClient) List(*Options) BillingDocumentIterator {
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
|
||||
if c.err != nil {
|
||||
return NewFakeBillingDocumentErroringRawIterator(c.err)
|
||||
}
|
||||
|
||||
billingDocuments := make([]*pkg.BillingDocument, 0, len(c.billingDocuments))
|
||||
for _, d := range c.billingDocuments {
|
||||
r, err := c.decodeBillingDocument(d)
|
||||
if err != nil {
|
||||
return NewFakeBillingDocumentErroringRawIterator(err)
|
||||
}
|
||||
billingDocuments = append(billingDocuments, r)
|
||||
}
|
||||
|
||||
if c.sorter != nil {
|
||||
c.sorter(billingDocuments)
|
||||
}
|
||||
|
||||
return NewFakeBillingDocumentIterator(billingDocuments, 0)
|
||||
}
|
||||
|
||||
// ListAll lists all BillingDocuments in the database
|
||||
func (c *FakeBillingDocumentClient) ListAll(ctx context.Context, options *Options) (*pkg.BillingDocuments, error) {
|
||||
iter := c.List(options)
|
||||
return iter.Next(ctx, -1)
|
||||
}
|
||||
|
||||
// Get gets a BillingDocument from the database
|
||||
func (c *FakeBillingDocumentClient) Get(ctx context.Context, partitionkey string, id string, options *Options) (*pkg.BillingDocument, error) {
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
|
||||
if c.err != nil {
|
||||
return nil, c.err
|
||||
}
|
||||
|
||||
billingDocument, exists := c.billingDocuments[id]
|
||||
if !exists {
|
||||
return nil, &Error{StatusCode: http.StatusNotFound}
|
||||
}
|
||||
|
||||
return c.decodeBillingDocument(billingDocument)
|
||||
}
|
||||
|
||||
// Delete deletes a BillingDocument from the database
|
||||
func (c *FakeBillingDocumentClient) Delete(ctx context.Context, partitionKey string, billingDocument *pkg.BillingDocument, options *Options) error {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
if c.err != nil {
|
||||
return c.err
|
||||
}
|
||||
|
||||
_, exists := c.billingDocuments[billingDocument.ID]
|
||||
if !exists {
|
||||
return &Error{StatusCode: http.StatusNotFound}
|
||||
}
|
||||
|
||||
delete(c.billingDocuments, billingDocument.ID)
|
||||
return nil
|
||||
}
|
||||
|
||||
// ChangeFeed is unimplemented
|
||||
func (c *FakeBillingDocumentClient) ChangeFeed(*Options) BillingDocumentIterator {
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
|
||||
if c.err != nil {
|
||||
return NewFakeBillingDocumentErroringRawIterator(c.err)
|
||||
}
|
||||
|
||||
return NewFakeBillingDocumentErroringRawIterator(ErrNotImplemented)
|
||||
}
|
||||
|
||||
func (c *FakeBillingDocumentClient) processPreTriggers(ctx context.Context, billingDocument *pkg.BillingDocument, options *Options) error {
|
||||
for _, triggerName := range options.PreTriggers {
|
||||
if triggerHandler := c.triggerHandlers[triggerName]; triggerHandler != nil {
|
||||
err := triggerHandler(ctx, billingDocument)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Query calls a query handler to implement database querying
|
||||
func (c *FakeBillingDocumentClient) Query(name string, query *Query, options *Options) BillingDocumentRawIterator {
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
|
||||
if c.err != nil {
|
||||
return NewFakeBillingDocumentErroringRawIterator(c.err)
|
||||
}
|
||||
|
||||
if queryHandler := c.queryHandlers[query.Query]; queryHandler != nil {
|
||||
return queryHandler(c, query, options)
|
||||
}
|
||||
|
||||
return NewFakeBillingDocumentErroringRawIterator(ErrNotImplemented)
|
||||
}
|
||||
|
||||
// QueryAll calls a query handler to implement database querying
|
||||
func (c *FakeBillingDocumentClient) QueryAll(ctx context.Context, partitionkey string, query *Query, options *Options) (*pkg.BillingDocuments, error) {
|
||||
iter := c.Query("", query, options)
|
||||
return iter.Next(ctx, -1)
|
||||
}
|
||||
|
||||
func NewFakeBillingDocumentIterator(billingDocuments []*pkg.BillingDocument, continuation int) BillingDocumentRawIterator {
|
||||
return &fakeBillingDocumentIterator{billingDocuments: billingDocuments, continuation: continuation}
|
||||
}
|
||||
|
||||
type fakeBillingDocumentIterator struct {
|
||||
billingDocuments []*pkg.BillingDocument
|
||||
continuation int
|
||||
done bool
|
||||
}
|
||||
|
||||
func (i *fakeBillingDocumentIterator) NextRaw(ctx context.Context, maxItemCount int, out interface{}) error {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
|
||||
func (i *fakeBillingDocumentIterator) Next(ctx context.Context, maxItemCount int) (*pkg.BillingDocuments, error) {
|
||||
if i.done {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var billingDocuments []*pkg.BillingDocument
|
||||
if maxItemCount == -1 {
|
||||
billingDocuments = i.billingDocuments[i.continuation:]
|
||||
i.continuation = len(i.billingDocuments)
|
||||
i.done = true
|
||||
} else {
|
||||
max := i.continuation + maxItemCount
|
||||
if max > len(i.billingDocuments) {
|
||||
max = len(i.billingDocuments)
|
||||
}
|
||||
billingDocuments = i.billingDocuments[i.continuation:max]
|
||||
i.continuation += max
|
||||
i.done = i.Continuation() == ""
|
||||
}
|
||||
|
||||
return &pkg.BillingDocuments{
|
||||
BillingDocuments: billingDocuments,
|
||||
Count: len(billingDocuments),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (i *fakeBillingDocumentIterator) Continuation() string {
|
||||
if i.continuation >= len(i.billingDocuments) {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf("%d", i.continuation)
|
||||
}
|
||||
|
||||
// NewFakeBillingDocumentErroringRawIterator returns a BillingDocumentRawIterator which
|
||||
// whose methods return the given error
|
||||
func NewFakeBillingDocumentErroringRawIterator(err error) BillingDocumentRawIterator {
|
||||
return &fakeBillingDocumentErroringRawIterator{err: err}
|
||||
}
|
||||
|
||||
type fakeBillingDocumentErroringRawIterator struct {
|
||||
err error
|
||||
}
|
||||
|
||||
func (i *fakeBillingDocumentErroringRawIterator) Next(ctx context.Context, maxItemCount int) (*pkg.BillingDocuments, error) {
|
||||
return nil, i.err
|
||||
}
|
||||
|
||||
func (i *fakeBillingDocumentErroringRawIterator) NextRaw(context.Context, int, interface{}) error {
|
||||
return i.err
|
||||
}
|
||||
|
||||
func (i *fakeBillingDocumentErroringRawIterator) Continuation() string {
|
||||
return ""
|
||||
}
|
|
@ -53,6 +53,9 @@ func IsErrorStatusCode(err error, statusCode int) bool {
|
|||
// PUT or DELETE operation
|
||||
var ErrETagRequired = fmt.Errorf("ETag is required")
|
||||
|
||||
// ErrNotImplemented is the error returned if a fake function is not implemented
|
||||
var ErrNotImplemented = fmt.Errorf("not implemented")
|
||||
|
||||
// RetryOnPreconditionFailed retries a function if it fails due to
|
||||
// PreconditionFailed
|
||||
func RetryOnPreconditionFailed(f func() error) (err error) {
|
||||
|
|
|
@ -19,7 +19,7 @@ type monitorDocumentClient struct {
|
|||
// MonitorDocumentClient is a monitorDocument client
|
||||
type MonitorDocumentClient interface {
|
||||
Create(context.Context, string, *pkg.MonitorDocument, *Options) (*pkg.MonitorDocument, error)
|
||||
List(*Options) MonitorDocumentRawIterator
|
||||
List(*Options) MonitorDocumentIterator
|
||||
ListAll(context.Context, *Options) (*pkg.MonitorDocuments, error)
|
||||
Get(context.Context, string, string, *Options) (*pkg.MonitorDocument, error)
|
||||
Replace(context.Context, string, *pkg.MonitorDocument, *Options) (*pkg.MonitorDocument, error)
|
||||
|
@ -109,7 +109,7 @@ func (c *monitorDocumentClient) Create(ctx context.Context, partitionkey string,
|
|||
return
|
||||
}
|
||||
|
||||
func (c *monitorDocumentClient) List(options *Options) MonitorDocumentRawIterator {
|
||||
func (c *monitorDocumentClient) List(options *Options) MonitorDocumentIterator {
|
||||
continuation := ""
|
||||
if options != nil {
|
||||
continuation = options.Continuation
|
||||
|
@ -239,11 +239,6 @@ func (i *monitorDocumentChangeFeedIterator) Continuation() string {
|
|||
}
|
||||
|
||||
func (i *monitorDocumentListIterator) Next(ctx context.Context, maxItemCount int) (monitorDocuments *pkg.MonitorDocuments, err error) {
|
||||
err = i.NextRaw(ctx, maxItemCount, &monitorDocuments)
|
||||
return
|
||||
}
|
||||
|
||||
func (i *monitorDocumentListIterator) NextRaw(ctx context.Context, maxItemCount int, raw interface{}) (err error) {
|
||||
if i.done {
|
||||
return
|
||||
}
|
||||
|
@ -259,7 +254,7 @@ func (i *monitorDocumentListIterator) NextRaw(ctx context.Context, maxItemCount
|
|||
return
|
||||
}
|
||||
|
||||
err = i.do(ctx, http.MethodGet, i.path+"/docs", "docs", i.path, http.StatusOK, nil, &raw, headers)
|
||||
err = i.do(ctx, http.MethodGet, i.path+"/docs", "docs", i.path, http.StatusOK, nil, &monitorDocuments, headers)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -0,0 +1,360 @@
|
|||
// Code generated by github.com/jim-minter/go-cosmosdb, DO NOT EDIT.
|
||||
|
||||
package cosmosdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"github.com/ugorji/go/codec"
|
||||
|
||||
pkg "github.com/Azure/ARO-RP/pkg/api"
|
||||
)
|
||||
|
||||
type fakeMonitorDocumentTriggerHandler func(context.Context, *pkg.MonitorDocument) error
|
||||
type fakeMonitorDocumentQueryHandler func(MonitorDocumentClient, *Query, *Options) MonitorDocumentRawIterator
|
||||
|
||||
var _ MonitorDocumentClient = &FakeMonitorDocumentClient{}
|
||||
|
||||
// NewFakeMonitorDocumentClient returns a FakeMonitorDocumentClient
|
||||
func NewFakeMonitorDocumentClient(h *codec.JsonHandle) *FakeMonitorDocumentClient {
|
||||
return &FakeMonitorDocumentClient{
|
||||
monitorDocuments: make(map[string][]byte),
|
||||
triggerHandlers: make(map[string]fakeMonitorDocumentTriggerHandler),
|
||||
queryHandlers: make(map[string]fakeMonitorDocumentQueryHandler),
|
||||
jsonHandle: h,
|
||||
lock: &sync.RWMutex{},
|
||||
}
|
||||
}
|
||||
|
||||
// FakeMonitorDocumentClient is a FakeMonitorDocumentClient
|
||||
type FakeMonitorDocumentClient struct {
|
||||
monitorDocuments map[string][]byte
|
||||
jsonHandle *codec.JsonHandle
|
||||
lock *sync.RWMutex
|
||||
triggerHandlers map[string]fakeMonitorDocumentTriggerHandler
|
||||
queryHandlers map[string]fakeMonitorDocumentQueryHandler
|
||||
sorter func([]*pkg.MonitorDocument)
|
||||
|
||||
// returns true if documents conflict
|
||||
conflictChecker func(*pkg.MonitorDocument, *pkg.MonitorDocument) bool
|
||||
|
||||
// err, if not nil, is an error to return when attempting to communicate
|
||||
// with this Client
|
||||
err error
|
||||
}
|
||||
|
||||
func (c *FakeMonitorDocumentClient) decodeMonitorDocument(s []byte) (monitorDocument *pkg.MonitorDocument, err error) {
|
||||
err = codec.NewDecoderBytes(s, c.jsonHandle).Decode(&monitorDocument)
|
||||
return
|
||||
}
|
||||
|
||||
func (c *FakeMonitorDocumentClient) encodeMonitorDocument(monitorDocument *pkg.MonitorDocument) (b []byte, err error) {
|
||||
err = codec.NewEncoderBytes(&b, c.jsonHandle).Encode(monitorDocument)
|
||||
return
|
||||
}
|
||||
|
||||
// SetError sets or unsets an error that will be returned on any
|
||||
// FakeMonitorDocumentClient method invocation
|
||||
func (c *FakeMonitorDocumentClient) SetError(err error) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
c.err = err
|
||||
}
|
||||
|
||||
// SetSorter sets or unsets a sorter function which will be used to sort values
|
||||
// returned by List() for test stability
|
||||
func (c *FakeMonitorDocumentClient) SetSorter(sorter func([]*pkg.MonitorDocument)) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
c.sorter = sorter
|
||||
}
|
||||
|
||||
// SetConflictChecker sets or unsets a function which can be used to validate
|
||||
// additional unique keys in a MonitorDocument
|
||||
func (c *FakeMonitorDocumentClient) SetConflictChecker(conflictChecker func(*pkg.MonitorDocument, *pkg.MonitorDocument) bool) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
c.conflictChecker = conflictChecker
|
||||
}
|
||||
|
||||
// SetTriggerHandler sets or unsets a trigger handler
|
||||
func (c *FakeMonitorDocumentClient) SetTriggerHandler(triggerName string, trigger fakeMonitorDocumentTriggerHandler) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
c.triggerHandlers[triggerName] = trigger
|
||||
}
|
||||
|
||||
// SetQueryHandler sets or unsets a query handler
|
||||
func (c *FakeMonitorDocumentClient) SetQueryHandler(queryName string, query fakeMonitorDocumentQueryHandler) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
c.queryHandlers[queryName] = query
|
||||
}
|
||||
|
||||
func (c *FakeMonitorDocumentClient) deepCopy(monitorDocument *pkg.MonitorDocument) (*pkg.MonitorDocument, error) {
|
||||
b, err := c.encodeMonitorDocument(monitorDocument)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return c.decodeMonitorDocument(b)
|
||||
}
|
||||
|
||||
func (c *FakeMonitorDocumentClient) apply(ctx context.Context, partitionkey string, monitorDocument *pkg.MonitorDocument, options *Options, isCreate bool) (*pkg.MonitorDocument, error) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
if c.err != nil {
|
||||
return nil, c.err
|
||||
}
|
||||
|
||||
monitorDocument, err := c.deepCopy(monitorDocument) // copy now because pretriggers can mutate monitorDocument
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if options != nil {
|
||||
err := c.processPreTriggers(ctx, monitorDocument, options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
_, exists := c.monitorDocuments[monitorDocument.ID]
|
||||
if isCreate && exists {
|
||||
return nil, &Error{
|
||||
StatusCode: http.StatusConflict,
|
||||
Message: "Entity with the specified id already exists in the system",
|
||||
}
|
||||
}
|
||||
if !isCreate && !exists {
|
||||
return nil, &Error{StatusCode: http.StatusNotFound}
|
||||
}
|
||||
|
||||
if c.conflictChecker != nil {
|
||||
for id := range c.monitorDocuments {
|
||||
monitorDocumentToCheck, err := c.decodeMonitorDocument(c.monitorDocuments[id])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if c.conflictChecker(monitorDocumentToCheck, monitorDocument) {
|
||||
return nil, &Error{
|
||||
StatusCode: http.StatusConflict,
|
||||
Message: "Entity with the specified id already exists in the system",
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
b, err := c.encodeMonitorDocument(monitorDocument)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c.monitorDocuments[monitorDocument.ID] = b
|
||||
|
||||
return monitorDocument, nil
|
||||
}
|
||||
|
||||
// Create creates a MonitorDocument in the database
|
||||
func (c *FakeMonitorDocumentClient) Create(ctx context.Context, partitionkey string, monitorDocument *pkg.MonitorDocument, options *Options) (*pkg.MonitorDocument, error) {
|
||||
return c.apply(ctx, partitionkey, monitorDocument, options, true)
|
||||
}
|
||||
|
||||
// Replace replaces a MonitorDocument in the database
|
||||
func (c *FakeMonitorDocumentClient) Replace(ctx context.Context, partitionkey string, monitorDocument *pkg.MonitorDocument, options *Options) (*pkg.MonitorDocument, error) {
|
||||
return c.apply(ctx, partitionkey, monitorDocument, options, false)
|
||||
}
|
||||
|
||||
// List returns a MonitorDocumentIterator to list all MonitorDocuments in the database
|
||||
func (c *FakeMonitorDocumentClient) List(*Options) MonitorDocumentIterator {
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
|
||||
if c.err != nil {
|
||||
return NewFakeMonitorDocumentErroringRawIterator(c.err)
|
||||
}
|
||||
|
||||
monitorDocuments := make([]*pkg.MonitorDocument, 0, len(c.monitorDocuments))
|
||||
for _, d := range c.monitorDocuments {
|
||||
r, err := c.decodeMonitorDocument(d)
|
||||
if err != nil {
|
||||
return NewFakeMonitorDocumentErroringRawIterator(err)
|
||||
}
|
||||
monitorDocuments = append(monitorDocuments, r)
|
||||
}
|
||||
|
||||
if c.sorter != nil {
|
||||
c.sorter(monitorDocuments)
|
||||
}
|
||||
|
||||
return NewFakeMonitorDocumentIterator(monitorDocuments, 0)
|
||||
}
|
||||
|
||||
// ListAll lists all MonitorDocuments in the database
|
||||
func (c *FakeMonitorDocumentClient) ListAll(ctx context.Context, options *Options) (*pkg.MonitorDocuments, error) {
|
||||
iter := c.List(options)
|
||||
return iter.Next(ctx, -1)
|
||||
}
|
||||
|
||||
// Get gets a MonitorDocument from the database
|
||||
func (c *FakeMonitorDocumentClient) Get(ctx context.Context, partitionkey string, id string, options *Options) (*pkg.MonitorDocument, error) {
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
|
||||
if c.err != nil {
|
||||
return nil, c.err
|
||||
}
|
||||
|
||||
monitorDocument, exists := c.monitorDocuments[id]
|
||||
if !exists {
|
||||
return nil, &Error{StatusCode: http.StatusNotFound}
|
||||
}
|
||||
|
||||
return c.decodeMonitorDocument(monitorDocument)
|
||||
}
|
||||
|
||||
// Delete deletes a MonitorDocument from the database
|
||||
func (c *FakeMonitorDocumentClient) Delete(ctx context.Context, partitionKey string, monitorDocument *pkg.MonitorDocument, options *Options) error {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
if c.err != nil {
|
||||
return c.err
|
||||
}
|
||||
|
||||
_, exists := c.monitorDocuments[monitorDocument.ID]
|
||||
if !exists {
|
||||
return &Error{StatusCode: http.StatusNotFound}
|
||||
}
|
||||
|
||||
delete(c.monitorDocuments, monitorDocument.ID)
|
||||
return nil
|
||||
}
|
||||
|
||||
// ChangeFeed is unimplemented
|
||||
func (c *FakeMonitorDocumentClient) ChangeFeed(*Options) MonitorDocumentIterator {
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
|
||||
if c.err != nil {
|
||||
return NewFakeMonitorDocumentErroringRawIterator(c.err)
|
||||
}
|
||||
|
||||
return NewFakeMonitorDocumentErroringRawIterator(ErrNotImplemented)
|
||||
}
|
||||
|
||||
func (c *FakeMonitorDocumentClient) processPreTriggers(ctx context.Context, monitorDocument *pkg.MonitorDocument, options *Options) error {
|
||||
for _, triggerName := range options.PreTriggers {
|
||||
if triggerHandler := c.triggerHandlers[triggerName]; triggerHandler != nil {
|
||||
err := triggerHandler(ctx, monitorDocument)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Query calls a query handler to implement database querying
|
||||
func (c *FakeMonitorDocumentClient) Query(name string, query *Query, options *Options) MonitorDocumentRawIterator {
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
|
||||
if c.err != nil {
|
||||
return NewFakeMonitorDocumentErroringRawIterator(c.err)
|
||||
}
|
||||
|
||||
if queryHandler := c.queryHandlers[query.Query]; queryHandler != nil {
|
||||
return queryHandler(c, query, options)
|
||||
}
|
||||
|
||||
return NewFakeMonitorDocumentErroringRawIterator(ErrNotImplemented)
|
||||
}
|
||||
|
||||
// QueryAll calls a query handler to implement database querying
|
||||
func (c *FakeMonitorDocumentClient) QueryAll(ctx context.Context, partitionkey string, query *Query, options *Options) (*pkg.MonitorDocuments, error) {
|
||||
iter := c.Query("", query, options)
|
||||
return iter.Next(ctx, -1)
|
||||
}
|
||||
|
||||
func NewFakeMonitorDocumentIterator(monitorDocuments []*pkg.MonitorDocument, continuation int) MonitorDocumentRawIterator {
|
||||
return &fakeMonitorDocumentIterator{monitorDocuments: monitorDocuments, continuation: continuation}
|
||||
}
|
||||
|
||||
type fakeMonitorDocumentIterator struct {
|
||||
monitorDocuments []*pkg.MonitorDocument
|
||||
continuation int
|
||||
done bool
|
||||
}
|
||||
|
||||
func (i *fakeMonitorDocumentIterator) NextRaw(ctx context.Context, maxItemCount int, out interface{}) error {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
|
||||
func (i *fakeMonitorDocumentIterator) Next(ctx context.Context, maxItemCount int) (*pkg.MonitorDocuments, error) {
|
||||
if i.done {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var monitorDocuments []*pkg.MonitorDocument
|
||||
if maxItemCount == -1 {
|
||||
monitorDocuments = i.monitorDocuments[i.continuation:]
|
||||
i.continuation = len(i.monitorDocuments)
|
||||
i.done = true
|
||||
} else {
|
||||
max := i.continuation + maxItemCount
|
||||
if max > len(i.monitorDocuments) {
|
||||
max = len(i.monitorDocuments)
|
||||
}
|
||||
monitorDocuments = i.monitorDocuments[i.continuation:max]
|
||||
i.continuation += max
|
||||
i.done = i.Continuation() == ""
|
||||
}
|
||||
|
||||
return &pkg.MonitorDocuments{
|
||||
MonitorDocuments: monitorDocuments,
|
||||
Count: len(monitorDocuments),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (i *fakeMonitorDocumentIterator) Continuation() string {
|
||||
if i.continuation >= len(i.monitorDocuments) {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf("%d", i.continuation)
|
||||
}
|
||||
|
||||
// NewFakeMonitorDocumentErroringRawIterator returns a MonitorDocumentRawIterator which
|
||||
// whose methods return the given error
|
||||
func NewFakeMonitorDocumentErroringRawIterator(err error) MonitorDocumentRawIterator {
|
||||
return &fakeMonitorDocumentErroringRawIterator{err: err}
|
||||
}
|
||||
|
||||
type fakeMonitorDocumentErroringRawIterator struct {
|
||||
err error
|
||||
}
|
||||
|
||||
func (i *fakeMonitorDocumentErroringRawIterator) Next(ctx context.Context, maxItemCount int) (*pkg.MonitorDocuments, error) {
|
||||
return nil, i.err
|
||||
}
|
||||
|
||||
func (i *fakeMonitorDocumentErroringRawIterator) NextRaw(context.Context, int, interface{}) error {
|
||||
return i.err
|
||||
}
|
||||
|
||||
func (i *fakeMonitorDocumentErroringRawIterator) Continuation() string {
|
||||
return ""
|
||||
}
|
|
@ -19,7 +19,7 @@ type openShiftClusterDocumentClient struct {
|
|||
// OpenShiftClusterDocumentClient is a openShiftClusterDocument client
|
||||
type OpenShiftClusterDocumentClient interface {
|
||||
Create(context.Context, string, *pkg.OpenShiftClusterDocument, *Options) (*pkg.OpenShiftClusterDocument, error)
|
||||
List(*Options) OpenShiftClusterDocumentRawIterator
|
||||
List(*Options) OpenShiftClusterDocumentIterator
|
||||
ListAll(context.Context, *Options) (*pkg.OpenShiftClusterDocuments, error)
|
||||
Get(context.Context, string, string, *Options) (*pkg.OpenShiftClusterDocument, error)
|
||||
Replace(context.Context, string, *pkg.OpenShiftClusterDocument, *Options) (*pkg.OpenShiftClusterDocument, error)
|
||||
|
@ -109,7 +109,7 @@ func (c *openShiftClusterDocumentClient) Create(ctx context.Context, partitionke
|
|||
return
|
||||
}
|
||||
|
||||
func (c *openShiftClusterDocumentClient) List(options *Options) OpenShiftClusterDocumentRawIterator {
|
||||
func (c *openShiftClusterDocumentClient) List(options *Options) OpenShiftClusterDocumentIterator {
|
||||
continuation := ""
|
||||
if options != nil {
|
||||
continuation = options.Continuation
|
||||
|
@ -239,11 +239,6 @@ func (i *openShiftClusterDocumentChangeFeedIterator) Continuation() string {
|
|||
}
|
||||
|
||||
func (i *openShiftClusterDocumentListIterator) Next(ctx context.Context, maxItemCount int) (openShiftClusterDocuments *pkg.OpenShiftClusterDocuments, err error) {
|
||||
err = i.NextRaw(ctx, maxItemCount, &openShiftClusterDocuments)
|
||||
return
|
||||
}
|
||||
|
||||
func (i *openShiftClusterDocumentListIterator) NextRaw(ctx context.Context, maxItemCount int, raw interface{}) (err error) {
|
||||
if i.done {
|
||||
return
|
||||
}
|
||||
|
@ -259,7 +254,7 @@ func (i *openShiftClusterDocumentListIterator) NextRaw(ctx context.Context, maxI
|
|||
return
|
||||
}
|
||||
|
||||
err = i.do(ctx, http.MethodGet, i.path+"/docs", "docs", i.path, http.StatusOK, nil, &raw, headers)
|
||||
err = i.do(ctx, http.MethodGet, i.path+"/docs", "docs", i.path, http.StatusOK, nil, &openShiftClusterDocuments, headers)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -0,0 +1,360 @@
|
|||
// Code generated by github.com/jim-minter/go-cosmosdb, DO NOT EDIT.
|
||||
|
||||
package cosmosdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"github.com/ugorji/go/codec"
|
||||
|
||||
pkg "github.com/Azure/ARO-RP/pkg/api"
|
||||
)
|
||||
|
||||
type fakeOpenShiftClusterDocumentTriggerHandler func(context.Context, *pkg.OpenShiftClusterDocument) error
|
||||
type fakeOpenShiftClusterDocumentQueryHandler func(OpenShiftClusterDocumentClient, *Query, *Options) OpenShiftClusterDocumentRawIterator
|
||||
|
||||
var _ OpenShiftClusterDocumentClient = &FakeOpenShiftClusterDocumentClient{}
|
||||
|
||||
// NewFakeOpenShiftClusterDocumentClient returns a FakeOpenShiftClusterDocumentClient
|
||||
func NewFakeOpenShiftClusterDocumentClient(h *codec.JsonHandle) *FakeOpenShiftClusterDocumentClient {
|
||||
return &FakeOpenShiftClusterDocumentClient{
|
||||
openShiftClusterDocuments: make(map[string][]byte),
|
||||
triggerHandlers: make(map[string]fakeOpenShiftClusterDocumentTriggerHandler),
|
||||
queryHandlers: make(map[string]fakeOpenShiftClusterDocumentQueryHandler),
|
||||
jsonHandle: h,
|
||||
lock: &sync.RWMutex{},
|
||||
}
|
||||
}
|
||||
|
||||
// FakeOpenShiftClusterDocumentClient is a FakeOpenShiftClusterDocumentClient
|
||||
type FakeOpenShiftClusterDocumentClient struct {
|
||||
openShiftClusterDocuments map[string][]byte
|
||||
jsonHandle *codec.JsonHandle
|
||||
lock *sync.RWMutex
|
||||
triggerHandlers map[string]fakeOpenShiftClusterDocumentTriggerHandler
|
||||
queryHandlers map[string]fakeOpenShiftClusterDocumentQueryHandler
|
||||
sorter func([]*pkg.OpenShiftClusterDocument)
|
||||
|
||||
// returns true if documents conflict
|
||||
conflictChecker func(*pkg.OpenShiftClusterDocument, *pkg.OpenShiftClusterDocument) bool
|
||||
|
||||
// err, if not nil, is an error to return when attempting to communicate
|
||||
// with this Client
|
||||
err error
|
||||
}
|
||||
|
||||
func (c *FakeOpenShiftClusterDocumentClient) decodeOpenShiftClusterDocument(s []byte) (openShiftClusterDocument *pkg.OpenShiftClusterDocument, err error) {
|
||||
err = codec.NewDecoderBytes(s, c.jsonHandle).Decode(&openShiftClusterDocument)
|
||||
return
|
||||
}
|
||||
|
||||
func (c *FakeOpenShiftClusterDocumentClient) encodeOpenShiftClusterDocument(openShiftClusterDocument *pkg.OpenShiftClusterDocument) (b []byte, err error) {
|
||||
err = codec.NewEncoderBytes(&b, c.jsonHandle).Encode(openShiftClusterDocument)
|
||||
return
|
||||
}
|
||||
|
||||
// SetError sets or unsets an error that will be returned on any
|
||||
// FakeOpenShiftClusterDocumentClient method invocation
|
||||
func (c *FakeOpenShiftClusterDocumentClient) SetError(err error) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
c.err = err
|
||||
}
|
||||
|
||||
// SetSorter sets or unsets a sorter function which will be used to sort values
|
||||
// returned by List() for test stability
|
||||
func (c *FakeOpenShiftClusterDocumentClient) SetSorter(sorter func([]*pkg.OpenShiftClusterDocument)) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
c.sorter = sorter
|
||||
}
|
||||
|
||||
// SetConflictChecker sets or unsets a function which can be used to validate
|
||||
// additional unique keys in a OpenShiftClusterDocument
|
||||
func (c *FakeOpenShiftClusterDocumentClient) SetConflictChecker(conflictChecker func(*pkg.OpenShiftClusterDocument, *pkg.OpenShiftClusterDocument) bool) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
c.conflictChecker = conflictChecker
|
||||
}
|
||||
|
||||
// SetTriggerHandler sets or unsets a trigger handler
|
||||
func (c *FakeOpenShiftClusterDocumentClient) SetTriggerHandler(triggerName string, trigger fakeOpenShiftClusterDocumentTriggerHandler) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
c.triggerHandlers[triggerName] = trigger
|
||||
}
|
||||
|
||||
// SetQueryHandler sets or unsets a query handler
|
||||
func (c *FakeOpenShiftClusterDocumentClient) SetQueryHandler(queryName string, query fakeOpenShiftClusterDocumentQueryHandler) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
c.queryHandlers[queryName] = query
|
||||
}
|
||||
|
||||
func (c *FakeOpenShiftClusterDocumentClient) deepCopy(openShiftClusterDocument *pkg.OpenShiftClusterDocument) (*pkg.OpenShiftClusterDocument, error) {
|
||||
b, err := c.encodeOpenShiftClusterDocument(openShiftClusterDocument)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return c.decodeOpenShiftClusterDocument(b)
|
||||
}
|
||||
|
||||
func (c *FakeOpenShiftClusterDocumentClient) apply(ctx context.Context, partitionkey string, openShiftClusterDocument *pkg.OpenShiftClusterDocument, options *Options, isCreate bool) (*pkg.OpenShiftClusterDocument, error) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
if c.err != nil {
|
||||
return nil, c.err
|
||||
}
|
||||
|
||||
openShiftClusterDocument, err := c.deepCopy(openShiftClusterDocument) // copy now because pretriggers can mutate openShiftClusterDocument
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if options != nil {
|
||||
err := c.processPreTriggers(ctx, openShiftClusterDocument, options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
_, exists := c.openShiftClusterDocuments[openShiftClusterDocument.ID]
|
||||
if isCreate && exists {
|
||||
return nil, &Error{
|
||||
StatusCode: http.StatusConflict,
|
||||
Message: "Entity with the specified id already exists in the system",
|
||||
}
|
||||
}
|
||||
if !isCreate && !exists {
|
||||
return nil, &Error{StatusCode: http.StatusNotFound}
|
||||
}
|
||||
|
||||
if c.conflictChecker != nil {
|
||||
for id := range c.openShiftClusterDocuments {
|
||||
openShiftClusterDocumentToCheck, err := c.decodeOpenShiftClusterDocument(c.openShiftClusterDocuments[id])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if c.conflictChecker(openShiftClusterDocumentToCheck, openShiftClusterDocument) {
|
||||
return nil, &Error{
|
||||
StatusCode: http.StatusConflict,
|
||||
Message: "Entity with the specified id already exists in the system",
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
b, err := c.encodeOpenShiftClusterDocument(openShiftClusterDocument)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c.openShiftClusterDocuments[openShiftClusterDocument.ID] = b
|
||||
|
||||
return openShiftClusterDocument, nil
|
||||
}
|
||||
|
||||
// Create creates a OpenShiftClusterDocument in the database
|
||||
func (c *FakeOpenShiftClusterDocumentClient) Create(ctx context.Context, partitionkey string, openShiftClusterDocument *pkg.OpenShiftClusterDocument, options *Options) (*pkg.OpenShiftClusterDocument, error) {
|
||||
return c.apply(ctx, partitionkey, openShiftClusterDocument, options, true)
|
||||
}
|
||||
|
||||
// Replace replaces a OpenShiftClusterDocument in the database
|
||||
func (c *FakeOpenShiftClusterDocumentClient) Replace(ctx context.Context, partitionkey string, openShiftClusterDocument *pkg.OpenShiftClusterDocument, options *Options) (*pkg.OpenShiftClusterDocument, error) {
|
||||
return c.apply(ctx, partitionkey, openShiftClusterDocument, options, false)
|
||||
}
|
||||
|
||||
// List returns a OpenShiftClusterDocumentIterator to list all OpenShiftClusterDocuments in the database
|
||||
func (c *FakeOpenShiftClusterDocumentClient) List(*Options) OpenShiftClusterDocumentIterator {
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
|
||||
if c.err != nil {
|
||||
return NewFakeOpenShiftClusterDocumentErroringRawIterator(c.err)
|
||||
}
|
||||
|
||||
openShiftClusterDocuments := make([]*pkg.OpenShiftClusterDocument, 0, len(c.openShiftClusterDocuments))
|
||||
for _, d := range c.openShiftClusterDocuments {
|
||||
r, err := c.decodeOpenShiftClusterDocument(d)
|
||||
if err != nil {
|
||||
return NewFakeOpenShiftClusterDocumentErroringRawIterator(err)
|
||||
}
|
||||
openShiftClusterDocuments = append(openShiftClusterDocuments, r)
|
||||
}
|
||||
|
||||
if c.sorter != nil {
|
||||
c.sorter(openShiftClusterDocuments)
|
||||
}
|
||||
|
||||
return NewFakeOpenShiftClusterDocumentIterator(openShiftClusterDocuments, 0)
|
||||
}
|
||||
|
||||
// ListAll lists all OpenShiftClusterDocuments in the database
|
||||
func (c *FakeOpenShiftClusterDocumentClient) ListAll(ctx context.Context, options *Options) (*pkg.OpenShiftClusterDocuments, error) {
|
||||
iter := c.List(options)
|
||||
return iter.Next(ctx, -1)
|
||||
}
|
||||
|
||||
// Get gets a OpenShiftClusterDocument from the database
|
||||
func (c *FakeOpenShiftClusterDocumentClient) Get(ctx context.Context, partitionkey string, id string, options *Options) (*pkg.OpenShiftClusterDocument, error) {
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
|
||||
if c.err != nil {
|
||||
return nil, c.err
|
||||
}
|
||||
|
||||
openShiftClusterDocument, exists := c.openShiftClusterDocuments[id]
|
||||
if !exists {
|
||||
return nil, &Error{StatusCode: http.StatusNotFound}
|
||||
}
|
||||
|
||||
return c.decodeOpenShiftClusterDocument(openShiftClusterDocument)
|
||||
}
|
||||
|
||||
// Delete deletes a OpenShiftClusterDocument from the database
|
||||
func (c *FakeOpenShiftClusterDocumentClient) Delete(ctx context.Context, partitionKey string, openShiftClusterDocument *pkg.OpenShiftClusterDocument, options *Options) error {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
if c.err != nil {
|
||||
return c.err
|
||||
}
|
||||
|
||||
_, exists := c.openShiftClusterDocuments[openShiftClusterDocument.ID]
|
||||
if !exists {
|
||||
return &Error{StatusCode: http.StatusNotFound}
|
||||
}
|
||||
|
||||
delete(c.openShiftClusterDocuments, openShiftClusterDocument.ID)
|
||||
return nil
|
||||
}
|
||||
|
||||
// ChangeFeed is unimplemented
|
||||
func (c *FakeOpenShiftClusterDocumentClient) ChangeFeed(*Options) OpenShiftClusterDocumentIterator {
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
|
||||
if c.err != nil {
|
||||
return NewFakeOpenShiftClusterDocumentErroringRawIterator(c.err)
|
||||
}
|
||||
|
||||
return NewFakeOpenShiftClusterDocumentErroringRawIterator(ErrNotImplemented)
|
||||
}
|
||||
|
||||
func (c *FakeOpenShiftClusterDocumentClient) processPreTriggers(ctx context.Context, openShiftClusterDocument *pkg.OpenShiftClusterDocument, options *Options) error {
|
||||
for _, triggerName := range options.PreTriggers {
|
||||
if triggerHandler := c.triggerHandlers[triggerName]; triggerHandler != nil {
|
||||
err := triggerHandler(ctx, openShiftClusterDocument)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Query calls a query handler to implement database querying
|
||||
func (c *FakeOpenShiftClusterDocumentClient) Query(name string, query *Query, options *Options) OpenShiftClusterDocumentRawIterator {
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
|
||||
if c.err != nil {
|
||||
return NewFakeOpenShiftClusterDocumentErroringRawIterator(c.err)
|
||||
}
|
||||
|
||||
if queryHandler := c.queryHandlers[query.Query]; queryHandler != nil {
|
||||
return queryHandler(c, query, options)
|
||||
}
|
||||
|
||||
return NewFakeOpenShiftClusterDocumentErroringRawIterator(ErrNotImplemented)
|
||||
}
|
||||
|
||||
// QueryAll calls a query handler to implement database querying
|
||||
func (c *FakeOpenShiftClusterDocumentClient) QueryAll(ctx context.Context, partitionkey string, query *Query, options *Options) (*pkg.OpenShiftClusterDocuments, error) {
|
||||
iter := c.Query("", query, options)
|
||||
return iter.Next(ctx, -1)
|
||||
}
|
||||
|
||||
func NewFakeOpenShiftClusterDocumentIterator(openShiftClusterDocuments []*pkg.OpenShiftClusterDocument, continuation int) OpenShiftClusterDocumentRawIterator {
|
||||
return &fakeOpenShiftClusterDocumentIterator{openShiftClusterDocuments: openShiftClusterDocuments, continuation: continuation}
|
||||
}
|
||||
|
||||
type fakeOpenShiftClusterDocumentIterator struct {
|
||||
openShiftClusterDocuments []*pkg.OpenShiftClusterDocument
|
||||
continuation int
|
||||
done bool
|
||||
}
|
||||
|
||||
func (i *fakeOpenShiftClusterDocumentIterator) NextRaw(ctx context.Context, maxItemCount int, out interface{}) error {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
|
||||
func (i *fakeOpenShiftClusterDocumentIterator) Next(ctx context.Context, maxItemCount int) (*pkg.OpenShiftClusterDocuments, error) {
|
||||
if i.done {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var openShiftClusterDocuments []*pkg.OpenShiftClusterDocument
|
||||
if maxItemCount == -1 {
|
||||
openShiftClusterDocuments = i.openShiftClusterDocuments[i.continuation:]
|
||||
i.continuation = len(i.openShiftClusterDocuments)
|
||||
i.done = true
|
||||
} else {
|
||||
max := i.continuation + maxItemCount
|
||||
if max > len(i.openShiftClusterDocuments) {
|
||||
max = len(i.openShiftClusterDocuments)
|
||||
}
|
||||
openShiftClusterDocuments = i.openShiftClusterDocuments[i.continuation:max]
|
||||
i.continuation += max
|
||||
i.done = i.Continuation() == ""
|
||||
}
|
||||
|
||||
return &pkg.OpenShiftClusterDocuments{
|
||||
OpenShiftClusterDocuments: openShiftClusterDocuments,
|
||||
Count: len(openShiftClusterDocuments),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (i *fakeOpenShiftClusterDocumentIterator) Continuation() string {
|
||||
if i.continuation >= len(i.openShiftClusterDocuments) {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf("%d", i.continuation)
|
||||
}
|
||||
|
||||
// NewFakeOpenShiftClusterDocumentErroringRawIterator returns a OpenShiftClusterDocumentRawIterator which
|
||||
// whose methods return the given error
|
||||
func NewFakeOpenShiftClusterDocumentErroringRawIterator(err error) OpenShiftClusterDocumentRawIterator {
|
||||
return &fakeOpenShiftClusterDocumentErroringRawIterator{err: err}
|
||||
}
|
||||
|
||||
type fakeOpenShiftClusterDocumentErroringRawIterator struct {
|
||||
err error
|
||||
}
|
||||
|
||||
func (i *fakeOpenShiftClusterDocumentErroringRawIterator) Next(ctx context.Context, maxItemCount int) (*pkg.OpenShiftClusterDocuments, error) {
|
||||
return nil, i.err
|
||||
}
|
||||
|
||||
func (i *fakeOpenShiftClusterDocumentErroringRawIterator) NextRaw(context.Context, int, interface{}) error {
|
||||
return i.err
|
||||
}
|
||||
|
||||
func (i *fakeOpenShiftClusterDocumentErroringRawIterator) Continuation() string {
|
||||
return ""
|
||||
}
|
|
@ -19,7 +19,7 @@ type subscriptionDocumentClient struct {
|
|||
// SubscriptionDocumentClient is a subscriptionDocument client
|
||||
type SubscriptionDocumentClient interface {
|
||||
Create(context.Context, string, *pkg.SubscriptionDocument, *Options) (*pkg.SubscriptionDocument, error)
|
||||
List(*Options) SubscriptionDocumentRawIterator
|
||||
List(*Options) SubscriptionDocumentIterator
|
||||
ListAll(context.Context, *Options) (*pkg.SubscriptionDocuments, error)
|
||||
Get(context.Context, string, string, *Options) (*pkg.SubscriptionDocument, error)
|
||||
Replace(context.Context, string, *pkg.SubscriptionDocument, *Options) (*pkg.SubscriptionDocument, error)
|
||||
|
@ -109,7 +109,7 @@ func (c *subscriptionDocumentClient) Create(ctx context.Context, partitionkey st
|
|||
return
|
||||
}
|
||||
|
||||
func (c *subscriptionDocumentClient) List(options *Options) SubscriptionDocumentRawIterator {
|
||||
func (c *subscriptionDocumentClient) List(options *Options) SubscriptionDocumentIterator {
|
||||
continuation := ""
|
||||
if options != nil {
|
||||
continuation = options.Continuation
|
||||
|
@ -239,11 +239,6 @@ func (i *subscriptionDocumentChangeFeedIterator) Continuation() string {
|
|||
}
|
||||
|
||||
func (i *subscriptionDocumentListIterator) Next(ctx context.Context, maxItemCount int) (subscriptionDocuments *pkg.SubscriptionDocuments, err error) {
|
||||
err = i.NextRaw(ctx, maxItemCount, &subscriptionDocuments)
|
||||
return
|
||||
}
|
||||
|
||||
func (i *subscriptionDocumentListIterator) NextRaw(ctx context.Context, maxItemCount int, raw interface{}) (err error) {
|
||||
if i.done {
|
||||
return
|
||||
}
|
||||
|
@ -259,7 +254,7 @@ func (i *subscriptionDocumentListIterator) NextRaw(ctx context.Context, maxItemC
|
|||
return
|
||||
}
|
||||
|
||||
err = i.do(ctx, http.MethodGet, i.path+"/docs", "docs", i.path, http.StatusOK, nil, &raw, headers)
|
||||
err = i.do(ctx, http.MethodGet, i.path+"/docs", "docs", i.path, http.StatusOK, nil, &subscriptionDocuments, headers)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -0,0 +1,360 @@
|
|||
// Code generated by github.com/jim-minter/go-cosmosdb, DO NOT EDIT.
|
||||
|
||||
package cosmosdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"github.com/ugorji/go/codec"
|
||||
|
||||
pkg "github.com/Azure/ARO-RP/pkg/api"
|
||||
)
|
||||
|
||||
type fakeSubscriptionDocumentTriggerHandler func(context.Context, *pkg.SubscriptionDocument) error
|
||||
type fakeSubscriptionDocumentQueryHandler func(SubscriptionDocumentClient, *Query, *Options) SubscriptionDocumentRawIterator
|
||||
|
||||
var _ SubscriptionDocumentClient = &FakeSubscriptionDocumentClient{}
|
||||
|
||||
// NewFakeSubscriptionDocumentClient returns a FakeSubscriptionDocumentClient
|
||||
func NewFakeSubscriptionDocumentClient(h *codec.JsonHandle) *FakeSubscriptionDocumentClient {
|
||||
return &FakeSubscriptionDocumentClient{
|
||||
subscriptionDocuments: make(map[string][]byte),
|
||||
triggerHandlers: make(map[string]fakeSubscriptionDocumentTriggerHandler),
|
||||
queryHandlers: make(map[string]fakeSubscriptionDocumentQueryHandler),
|
||||
jsonHandle: h,
|
||||
lock: &sync.RWMutex{},
|
||||
}
|
||||
}
|
||||
|
||||
// FakeSubscriptionDocumentClient is a FakeSubscriptionDocumentClient
|
||||
type FakeSubscriptionDocumentClient struct {
|
||||
subscriptionDocuments map[string][]byte
|
||||
jsonHandle *codec.JsonHandle
|
||||
lock *sync.RWMutex
|
||||
triggerHandlers map[string]fakeSubscriptionDocumentTriggerHandler
|
||||
queryHandlers map[string]fakeSubscriptionDocumentQueryHandler
|
||||
sorter func([]*pkg.SubscriptionDocument)
|
||||
|
||||
// returns true if documents conflict
|
||||
conflictChecker func(*pkg.SubscriptionDocument, *pkg.SubscriptionDocument) bool
|
||||
|
||||
// err, if not nil, is an error to return when attempting to communicate
|
||||
// with this Client
|
||||
err error
|
||||
}
|
||||
|
||||
func (c *FakeSubscriptionDocumentClient) decodeSubscriptionDocument(s []byte) (subscriptionDocument *pkg.SubscriptionDocument, err error) {
|
||||
err = codec.NewDecoderBytes(s, c.jsonHandle).Decode(&subscriptionDocument)
|
||||
return
|
||||
}
|
||||
|
||||
func (c *FakeSubscriptionDocumentClient) encodeSubscriptionDocument(subscriptionDocument *pkg.SubscriptionDocument) (b []byte, err error) {
|
||||
err = codec.NewEncoderBytes(&b, c.jsonHandle).Encode(subscriptionDocument)
|
||||
return
|
||||
}
|
||||
|
||||
// SetError sets or unsets an error that will be returned on any
|
||||
// FakeSubscriptionDocumentClient method invocation
|
||||
func (c *FakeSubscriptionDocumentClient) SetError(err error) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
c.err = err
|
||||
}
|
||||
|
||||
// SetSorter sets or unsets a sorter function which will be used to sort values
|
||||
// returned by List() for test stability
|
||||
func (c *FakeSubscriptionDocumentClient) SetSorter(sorter func([]*pkg.SubscriptionDocument)) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
c.sorter = sorter
|
||||
}
|
||||
|
||||
// SetConflictChecker sets or unsets a function which can be used to validate
|
||||
// additional unique keys in a SubscriptionDocument
|
||||
func (c *FakeSubscriptionDocumentClient) SetConflictChecker(conflictChecker func(*pkg.SubscriptionDocument, *pkg.SubscriptionDocument) bool) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
c.conflictChecker = conflictChecker
|
||||
}
|
||||
|
||||
// SetTriggerHandler sets or unsets a trigger handler
|
||||
func (c *FakeSubscriptionDocumentClient) SetTriggerHandler(triggerName string, trigger fakeSubscriptionDocumentTriggerHandler) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
c.triggerHandlers[triggerName] = trigger
|
||||
}
|
||||
|
||||
// SetQueryHandler sets or unsets a query handler
|
||||
func (c *FakeSubscriptionDocumentClient) SetQueryHandler(queryName string, query fakeSubscriptionDocumentQueryHandler) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
c.queryHandlers[queryName] = query
|
||||
}
|
||||
|
||||
func (c *FakeSubscriptionDocumentClient) deepCopy(subscriptionDocument *pkg.SubscriptionDocument) (*pkg.SubscriptionDocument, error) {
|
||||
b, err := c.encodeSubscriptionDocument(subscriptionDocument)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return c.decodeSubscriptionDocument(b)
|
||||
}
|
||||
|
||||
func (c *FakeSubscriptionDocumentClient) apply(ctx context.Context, partitionkey string, subscriptionDocument *pkg.SubscriptionDocument, options *Options, isCreate bool) (*pkg.SubscriptionDocument, error) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
if c.err != nil {
|
||||
return nil, c.err
|
||||
}
|
||||
|
||||
subscriptionDocument, err := c.deepCopy(subscriptionDocument) // copy now because pretriggers can mutate subscriptionDocument
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if options != nil {
|
||||
err := c.processPreTriggers(ctx, subscriptionDocument, options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
_, exists := c.subscriptionDocuments[subscriptionDocument.ID]
|
||||
if isCreate && exists {
|
||||
return nil, &Error{
|
||||
StatusCode: http.StatusConflict,
|
||||
Message: "Entity with the specified id already exists in the system",
|
||||
}
|
||||
}
|
||||
if !isCreate && !exists {
|
||||
return nil, &Error{StatusCode: http.StatusNotFound}
|
||||
}
|
||||
|
||||
if c.conflictChecker != nil {
|
||||
for id := range c.subscriptionDocuments {
|
||||
subscriptionDocumentToCheck, err := c.decodeSubscriptionDocument(c.subscriptionDocuments[id])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if c.conflictChecker(subscriptionDocumentToCheck, subscriptionDocument) {
|
||||
return nil, &Error{
|
||||
StatusCode: http.StatusConflict,
|
||||
Message: "Entity with the specified id already exists in the system",
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
b, err := c.encodeSubscriptionDocument(subscriptionDocument)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c.subscriptionDocuments[subscriptionDocument.ID] = b
|
||||
|
||||
return subscriptionDocument, nil
|
||||
}
|
||||
|
||||
// Create creates a SubscriptionDocument in the database
|
||||
func (c *FakeSubscriptionDocumentClient) Create(ctx context.Context, partitionkey string, subscriptionDocument *pkg.SubscriptionDocument, options *Options) (*pkg.SubscriptionDocument, error) {
|
||||
return c.apply(ctx, partitionkey, subscriptionDocument, options, true)
|
||||
}
|
||||
|
||||
// Replace replaces a SubscriptionDocument in the database
|
||||
func (c *FakeSubscriptionDocumentClient) Replace(ctx context.Context, partitionkey string, subscriptionDocument *pkg.SubscriptionDocument, options *Options) (*pkg.SubscriptionDocument, error) {
|
||||
return c.apply(ctx, partitionkey, subscriptionDocument, options, false)
|
||||
}
|
||||
|
||||
// List returns a SubscriptionDocumentIterator to list all SubscriptionDocuments in the database
|
||||
func (c *FakeSubscriptionDocumentClient) List(*Options) SubscriptionDocumentIterator {
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
|
||||
if c.err != nil {
|
||||
return NewFakeSubscriptionDocumentErroringRawIterator(c.err)
|
||||
}
|
||||
|
||||
subscriptionDocuments := make([]*pkg.SubscriptionDocument, 0, len(c.subscriptionDocuments))
|
||||
for _, d := range c.subscriptionDocuments {
|
||||
r, err := c.decodeSubscriptionDocument(d)
|
||||
if err != nil {
|
||||
return NewFakeSubscriptionDocumentErroringRawIterator(err)
|
||||
}
|
||||
subscriptionDocuments = append(subscriptionDocuments, r)
|
||||
}
|
||||
|
||||
if c.sorter != nil {
|
||||
c.sorter(subscriptionDocuments)
|
||||
}
|
||||
|
||||
return NewFakeSubscriptionDocumentIterator(subscriptionDocuments, 0)
|
||||
}
|
||||
|
||||
// ListAll lists all SubscriptionDocuments in the database
|
||||
func (c *FakeSubscriptionDocumentClient) ListAll(ctx context.Context, options *Options) (*pkg.SubscriptionDocuments, error) {
|
||||
iter := c.List(options)
|
||||
return iter.Next(ctx, -1)
|
||||
}
|
||||
|
||||
// Get gets a SubscriptionDocument from the database
|
||||
func (c *FakeSubscriptionDocumentClient) Get(ctx context.Context, partitionkey string, id string, options *Options) (*pkg.SubscriptionDocument, error) {
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
|
||||
if c.err != nil {
|
||||
return nil, c.err
|
||||
}
|
||||
|
||||
subscriptionDocument, exists := c.subscriptionDocuments[id]
|
||||
if !exists {
|
||||
return nil, &Error{StatusCode: http.StatusNotFound}
|
||||
}
|
||||
|
||||
return c.decodeSubscriptionDocument(subscriptionDocument)
|
||||
}
|
||||
|
||||
// Delete deletes a SubscriptionDocument from the database
|
||||
func (c *FakeSubscriptionDocumentClient) Delete(ctx context.Context, partitionKey string, subscriptionDocument *pkg.SubscriptionDocument, options *Options) error {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
if c.err != nil {
|
||||
return c.err
|
||||
}
|
||||
|
||||
_, exists := c.subscriptionDocuments[subscriptionDocument.ID]
|
||||
if !exists {
|
||||
return &Error{StatusCode: http.StatusNotFound}
|
||||
}
|
||||
|
||||
delete(c.subscriptionDocuments, subscriptionDocument.ID)
|
||||
return nil
|
||||
}
|
||||
|
||||
// ChangeFeed is unimplemented
|
||||
func (c *FakeSubscriptionDocumentClient) ChangeFeed(*Options) SubscriptionDocumentIterator {
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
|
||||
if c.err != nil {
|
||||
return NewFakeSubscriptionDocumentErroringRawIterator(c.err)
|
||||
}
|
||||
|
||||
return NewFakeSubscriptionDocumentErroringRawIterator(ErrNotImplemented)
|
||||
}
|
||||
|
||||
func (c *FakeSubscriptionDocumentClient) processPreTriggers(ctx context.Context, subscriptionDocument *pkg.SubscriptionDocument, options *Options) error {
|
||||
for _, triggerName := range options.PreTriggers {
|
||||
if triggerHandler := c.triggerHandlers[triggerName]; triggerHandler != nil {
|
||||
err := triggerHandler(ctx, subscriptionDocument)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Query calls a query handler to implement database querying
|
||||
func (c *FakeSubscriptionDocumentClient) Query(name string, query *Query, options *Options) SubscriptionDocumentRawIterator {
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
|
||||
if c.err != nil {
|
||||
return NewFakeSubscriptionDocumentErroringRawIterator(c.err)
|
||||
}
|
||||
|
||||
if queryHandler := c.queryHandlers[query.Query]; queryHandler != nil {
|
||||
return queryHandler(c, query, options)
|
||||
}
|
||||
|
||||
return NewFakeSubscriptionDocumentErroringRawIterator(ErrNotImplemented)
|
||||
}
|
||||
|
||||
// QueryAll calls a query handler to implement database querying
|
||||
func (c *FakeSubscriptionDocumentClient) QueryAll(ctx context.Context, partitionkey string, query *Query, options *Options) (*pkg.SubscriptionDocuments, error) {
|
||||
iter := c.Query("", query, options)
|
||||
return iter.Next(ctx, -1)
|
||||
}
|
||||
|
||||
func NewFakeSubscriptionDocumentIterator(subscriptionDocuments []*pkg.SubscriptionDocument, continuation int) SubscriptionDocumentRawIterator {
|
||||
return &fakeSubscriptionDocumentIterator{subscriptionDocuments: subscriptionDocuments, continuation: continuation}
|
||||
}
|
||||
|
||||
type fakeSubscriptionDocumentIterator struct {
|
||||
subscriptionDocuments []*pkg.SubscriptionDocument
|
||||
continuation int
|
||||
done bool
|
||||
}
|
||||
|
||||
func (i *fakeSubscriptionDocumentIterator) NextRaw(ctx context.Context, maxItemCount int, out interface{}) error {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
|
||||
func (i *fakeSubscriptionDocumentIterator) Next(ctx context.Context, maxItemCount int) (*pkg.SubscriptionDocuments, error) {
|
||||
if i.done {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var subscriptionDocuments []*pkg.SubscriptionDocument
|
||||
if maxItemCount == -1 {
|
||||
subscriptionDocuments = i.subscriptionDocuments[i.continuation:]
|
||||
i.continuation = len(i.subscriptionDocuments)
|
||||
i.done = true
|
||||
} else {
|
||||
max := i.continuation + maxItemCount
|
||||
if max > len(i.subscriptionDocuments) {
|
||||
max = len(i.subscriptionDocuments)
|
||||
}
|
||||
subscriptionDocuments = i.subscriptionDocuments[i.continuation:max]
|
||||
i.continuation += max
|
||||
i.done = i.Continuation() == ""
|
||||
}
|
||||
|
||||
return &pkg.SubscriptionDocuments{
|
||||
SubscriptionDocuments: subscriptionDocuments,
|
||||
Count: len(subscriptionDocuments),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (i *fakeSubscriptionDocumentIterator) Continuation() string {
|
||||
if i.continuation >= len(i.subscriptionDocuments) {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf("%d", i.continuation)
|
||||
}
|
||||
|
||||
// NewFakeSubscriptionDocumentErroringRawIterator returns a SubscriptionDocumentRawIterator which
|
||||
// whose methods return the given error
|
||||
func NewFakeSubscriptionDocumentErroringRawIterator(err error) SubscriptionDocumentRawIterator {
|
||||
return &fakeSubscriptionDocumentErroringRawIterator{err: err}
|
||||
}
|
||||
|
||||
type fakeSubscriptionDocumentErroringRawIterator struct {
|
||||
err error
|
||||
}
|
||||
|
||||
func (i *fakeSubscriptionDocumentErroringRawIterator) Next(ctx context.Context, maxItemCount int) (*pkg.SubscriptionDocuments, error) {
|
||||
return nil, i.err
|
||||
}
|
||||
|
||||
func (i *fakeSubscriptionDocumentErroringRawIterator) NextRaw(context.Context, int, interface{}) error {
|
||||
return i.err
|
||||
}
|
||||
|
||||
func (i *fakeSubscriptionDocumentErroringRawIterator) Continuation() string {
|
||||
return ""
|
||||
}
|
27
vendor/github.com/jim-minter/go-cosmosdb/cmd/gencosmosdb/gencosmosdb.go
сгенерированный
поставляемый
27
vendor/github.com/jim-minter/go-cosmosdb/cmd/gencosmosdb/gencosmosdb.go
сгенерированный
поставляемый
|
@ -43,7 +43,7 @@ func unexport(s string) string {
|
|||
|
||||
func run() error {
|
||||
for _, name := range gencosmosdb.AssetNames() {
|
||||
if name == "template.go" {
|
||||
if name == "template.go" || name == "template_fake.go" {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -54,6 +54,7 @@ func run() error {
|
|||
}
|
||||
|
||||
for _, arg := range flag.Args() {
|
||||
filesToGenerate := []string{"template.go", "template_fake.go"}
|
||||
args := strings.Split(arg, ",")
|
||||
|
||||
importpkg := args[0]
|
||||
|
@ -65,19 +66,21 @@ func run() error {
|
|||
singular := unexport(singularExported)
|
||||
plural := unexport(pluralExported)
|
||||
|
||||
data := gencosmosdb.MustAsset("template.go")
|
||||
for _, filename := range filesToGenerate {
|
||||
data := gencosmosdb.MustAsset(filename)
|
||||
data = importRegexp.ReplaceAll(data, []byte("\tpkg \""+importpkg+"\""))
|
||||
|
||||
data = importRegexp.ReplaceAll(data, []byte("\tpkg \""+importpkg+"\""))
|
||||
// plural must be done before singular ("template" is a sub-string of "templates")
|
||||
data = pluralRegexp.ReplaceAll(data, []byte(plural))
|
||||
data = pluralExportedRegexp.ReplaceAll(data, []byte(pluralExported))
|
||||
data = singularRegexp.ReplaceAll(data, []byte(singular))
|
||||
data = singularExportedRegexp.ReplaceAll(data, []byte(singularExported))
|
||||
|
||||
// plural must be done before singular ("template" is a sub-string of "templates")
|
||||
data = pluralRegexp.ReplaceAll(data, []byte(plural))
|
||||
data = pluralExportedRegexp.ReplaceAll(data, []byte(pluralExported))
|
||||
data = singularRegexp.ReplaceAll(data, []byte(singular))
|
||||
data = singularExportedRegexp.ReplaceAll(data, []byte(singularExported))
|
||||
|
||||
err := writeFile("zz_generated_"+strings.ToLower(singularExported)+".go", data)
|
||||
if err != nil {
|
||||
return err
|
||||
generatedFilename := strings.Replace(filename, "template", strings.ToLower(singularExported), 1)
|
||||
err := writeFile("zz_generated_"+generatedFilename, data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
Загрузка…
Ссылка в новой задаче