go.mercari.io/datastore@v1.8.2/testsuite/suite.go (about)

     1  package testsuite
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"go.mercari.io/datastore"
     8  )
     9  
    10  // Test represents a test function for Datastore testing.
    11  type Test func(ctx context.Context, t *testing.T, client datastore.Client)
    12  
    13  // TestSuite contains all the test cases that this package provides.
    14  var TestSuite = map[string]Test{
    15  	"Batch_Put":                                   batchPut,
    16  	"Batch_PutWithCustomErrHandler":               batchPutWithCustomErrHandler,
    17  	"Batch_Get":                                   batchGet,
    18  	"Batch_GetWithCustomErrHandler":               batchGetWithCustomErrHandler,
    19  	"Batch_Delete":                                batchDelete,
    20  	"Batch_DeleteWithCustomErrHandler":            batchDeleteWithCustomErrHandler,
    21  	"PutAndGet":                                   putAndGet,
    22  	"PutAndGet_TimeTime":                          putAndGetTimeTime,
    23  	"PutAndDelete":                                putAndDelete,
    24  	"PutAndGet_ObjectHasObjectSlice":              putAndGetObjectHasObjectSlice,
    25  	"PutAndGet_ObjectHasObjectSliceWithFlatten":   putAndGetObjectHasObjectSliceWithFlatten,
    26  	"PutEntityType":                               putEntityType,
    27  	"PutAndGet_NilKey":                            putAndGetNilKey,
    28  	"PutAndGet_NilKeySlice":                       putAndGetNilKeySlice,
    29  	"PutInterface":                                putInterface,
    30  	"PutAndGet_PropertyList":                      putAndGetPropertyList,
    31  	"PutAndGet_MultiPropertyListSlice":            putAndGetMultiPropertyListSlice,
    32  	"PutAndGet_BareStruct":                        putAndGetBareStruct,
    33  	"PutAndGet_MultiBareStruct":                   putAndGetMultiBareStruct,
    34  	"GeoPoint_PutAndGet":                          geoPointPutAndGet,
    35  	"GobDecode":                                   gobDecode,
    36  	"Key_Equal":                                   keyEqual,
    37  	"Key_Incomplete":                              keyIncomplete,
    38  	"Key_PutAndGet":                               keyPutAndGet,
    39  	"Namespace_PutAndGet":                         namespacePutAndGet,
    40  	"Namespace_PutAndGetWithTx":                   namespacePutAndGetWithTx,
    41  	"Namespace_Query":                             namespaceQuery,
    42  	"PLS_Basic":                                   plsBasic,
    43  	"KL_Basic":                                    klBasic,
    44  	"PropertyTranslater_PutAndGet":                propertyTranslaterPutAndGet,
    45  	"Filter_PropertyTranslaterMustError":          filterPropertyTranslaterMustError,
    46  	"Query_Count":                                 queryCount,
    47  	"Query_GetAll":                                queryGetAll,
    48  	"Query_Cursor":                                queryCursor,
    49  	"Query_NextByPropertyList":                    queryNextByPropertyList,
    50  	"Query_GetAllByPropertyListSlice":             queryGetAllByPropertyListSlice,
    51  	"Filter_Basic":                                filterBasic,
    52  	"Filter_PropertyTranslater":                   filterPropertyTranslater,
    53  	"Filter_PropertyTranslaterWithOriginalTypes":  filterPropertyTranslaterWithOriginalTypes,
    54  	"Transaction_Commit":                          transactionCommit,
    55  	"Transaction_Rollback":                        transactionRollback,
    56  	"Transaction_CommitAndRollback":               transactionCommitAndRollback,
    57  	"Transaction_JoinAncesterQuery":               transactionJoinAncesterQuery,
    58  	"RunInTransaction_Commit":                     runInTransactionCommit,
    59  	"RunInTransaction_Rollback":                   runInTransactionRollback,
    60  	"TransactionBatch_Put":                        transactionBatchPut,
    61  	"TransactionBatch_PutWithCustomErrHandler":    transactionBatchPutWithCustomErrHandler,
    62  	"TransactionBatch_PutAndAllocateIDs":          transactionBatchPutAndAllocateIDs,
    63  	"TransactionBatch_Get":                        transactionBatchGet,
    64  	"TransactionBatch_GetWithCustomErrHandler":    transactionBatchGetWithCustomErrHandler,
    65  	"TransactionBatch_Delete":                     transactionBatchDelete,
    66  	"TransactionBatch_DeleteWithCustomErrHandler": transactionBatchDeleteWithCustomErrHandler,
    67  
    68  	"CheckIssue59": checkIssue59,
    69  }
    70  
    71  // MergeTestSuite into this package's TestSuite.
    72  func MergeTestSuite(suite map[string]Test) {
    73  	for key, spec := range suite {
    74  		_, ok := TestSuite[key]
    75  		if ok {
    76  			panic("duplicate spec name")
    77  		}
    78  		TestSuite[key] = spec
    79  	}
    80  }
    81  
    82  type contextAE struct{}
    83  
    84  // WrapAEFlag add AEDatastore marker into context. use with IsAEDatastoreClient function.
    85  func WrapAEFlag(ctx context.Context) context.Context {
    86  	return context.WithValue(ctx, contextAE{}, true)
    87  }
    88  
    89  // IsAEDatastoreClient returns whether the context is used for AEDatastore.
    90  func IsAEDatastoreClient(ctx context.Context) bool {
    91  	return ctx.Value(contextAE{}) != nil
    92  }
    93  
    94  type contextCloud struct{}
    95  
    96  // WrapCloudFlag add CloudDatastore marker into context. use with IsCloudDatastoreClient function.
    97  func WrapCloudFlag(ctx context.Context) context.Context {
    98  	return context.WithValue(ctx, contextCloud{}, true)
    99  }
   100  
   101  // IsCloudDatastoreClient returns whether the context is used for CloudDatastore.
   102  func IsCloudDatastoreClient(ctx context.Context) bool {
   103  	return ctx.Value(contextCloud{}) != nil
   104  }