зеркало из https://github.com/Azure/ARO-RP.git
deep copy items when adding them to database checkers/fixtures
This commit is contained in:
Родитель
dd7e79213b
Коммит
22e0cc5b91
|
@ -29,23 +29,58 @@ func NewChecker() *Checker {
|
|||
}
|
||||
|
||||
func (f *Checker) AddOpenShiftClusterDocuments(docs ...*api.OpenShiftClusterDocument) {
|
||||
f.openshiftClusterDocuments = append(f.openshiftClusterDocuments, docs...)
|
||||
for _, doc := range docs {
|
||||
docCopy, err := deepCopy(doc)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
f.openshiftClusterDocuments = append(f.openshiftClusterDocuments, docCopy.(*api.OpenShiftClusterDocument))
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Checker) AddSubscriptionDocuments(docs ...*api.SubscriptionDocument) {
|
||||
f.subscriptionDocuments = append(f.subscriptionDocuments, docs...)
|
||||
for _, doc := range docs {
|
||||
docCopy, err := deepCopy(doc)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
f.subscriptionDocuments = append(f.subscriptionDocuments, docCopy.(*api.SubscriptionDocument))
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Checker) AddBillingDocuments(docs ...*api.BillingDocument) {
|
||||
f.billingDocuments = append(f.billingDocuments, docs...)
|
||||
for _, doc := range docs {
|
||||
docCopy, err := deepCopy(doc)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
f.billingDocuments = append(f.billingDocuments, docCopy.(*api.BillingDocument))
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Checker) AddAsyncOperationDocuments(docs ...*api.AsyncOperationDocument) {
|
||||
f.asyncOperationDocuments = append(f.asyncOperationDocuments, docs...)
|
||||
for _, doc := range docs {
|
||||
docCopy, err := deepCopy(doc)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
f.asyncOperationDocuments = append(f.asyncOperationDocuments, docCopy.(*api.AsyncOperationDocument))
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Checker) AddPortalDocuments(docs ...*api.PortalDocument) {
|
||||
f.portalDocuments = append(f.portalDocuments, docs...)
|
||||
for _, doc := range docs {
|
||||
docCopy, err := deepCopy(doc)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
f.portalDocuments = append(f.portalDocuments, docCopy.(*api.PortalDocument))
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Checker) CheckOpenShiftClusters(openShiftClusters *cosmosdb.FakeOpenShiftClusterDocumentClient) (errs []error) {
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package database
|
||||
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the Apache License 2.0.
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/ugorji/go/codec"
|
||||
)
|
||||
|
||||
var h = &codec.JsonHandle{}
|
||||
|
||||
func deepCopy(i interface{}) (interface{}, error) {
|
||||
var b []byte
|
||||
err := codec.NewEncoderBytes(&b, h).Encode(i)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
i = reflect.New(reflect.ValueOf(i).Elem().Type()).Interface()
|
||||
err = codec.NewDecoderBytes(b, h).Decode(&i)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return i, nil
|
||||
}
|
|
@ -56,23 +56,58 @@ func (f *Fixture) WithPortal(db database.Portal) *Fixture {
|
|||
}
|
||||
|
||||
func (f *Fixture) AddOpenShiftClusterDocuments(docs ...*api.OpenShiftClusterDocument) {
|
||||
f.openshiftClusterDocuments = append(f.openshiftClusterDocuments, docs...)
|
||||
for _, doc := range docs {
|
||||
docCopy, err := deepCopy(doc)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
f.openshiftClusterDocuments = append(f.openshiftClusterDocuments, docCopy.(*api.OpenShiftClusterDocument))
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Fixture) AddSubscriptionDocuments(docs ...*api.SubscriptionDocument) {
|
||||
f.subscriptionDocuments = append(f.subscriptionDocuments, docs...)
|
||||
for _, doc := range docs {
|
||||
docCopy, err := deepCopy(doc)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
f.subscriptionDocuments = append(f.subscriptionDocuments, docCopy.(*api.SubscriptionDocument))
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Fixture) AddBillingDocuments(docs ...*api.BillingDocument) {
|
||||
f.billingDocuments = append(f.billingDocuments, docs...)
|
||||
for _, doc := range docs {
|
||||
docCopy, err := deepCopy(doc)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
f.billingDocuments = append(f.billingDocuments, docCopy.(*api.BillingDocument))
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Fixture) AddAsyncOperationDocuments(docs ...*api.AsyncOperationDocument) {
|
||||
f.asyncOperationDocuments = append(f.asyncOperationDocuments, docs...)
|
||||
for _, doc := range docs {
|
||||
docCopy, err := deepCopy(doc)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
f.asyncOperationDocuments = append(f.asyncOperationDocuments, docCopy.(*api.AsyncOperationDocument))
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Fixture) AddPortalDocuments(docs ...*api.PortalDocument) {
|
||||
f.portalDocuments = append(f.portalDocuments, docs...)
|
||||
for _, doc := range docs {
|
||||
docCopy, err := deepCopy(doc)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
f.portalDocuments = append(f.portalDocuments, docCopy.(*api.PortalDocument))
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Fixture) Create() error {
|
||||
|
|
Загрузка…
Ссылка в новой задаче