github.com/willyham/dosa@v2.3.1-0.20171024181418-1e446d37ee71+incompatible/connectors/cassandra/datastore_common_test.go (about) 1 // Copyright (c) 2017 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package cassandra_test 22 23 import ( 24 "context" 25 26 "testing" 27 28 "github.com/pkg/errors" 29 "github.com/uber-go/dosa" 30 . "github.com/uber-go/dosa/connectors/cassandra" 31 ) 32 33 const ( 34 keyspace = "datastore_test" 35 tableName = "testentity" 36 uuidKeyField = "uuidkeyfield" 37 uuidField = "uuidfield" 38 stringKeyField = "stringkeyfield" 39 stringField = "stringfield" 40 int32Field = "int32field" 41 int64KeyField = "int64keyfield" 42 int64Field = "int64field" 43 doubleField = "doublefield" 44 blobField = "blobfield" 45 timestampField = "timestampfield" 46 boolField = "boolfield" 47 ) 48 49 var testStore *Connector 50 51 func initTestStore(t *testing.T) { 52 ts := GetTestConnector(t) 53 testStore = ts.(*Connector) 54 } 55 56 func initTestSchema(ks string, entityInfo *dosa.EntityInfo) error { 57 ctx := context.Background() 58 err := testStore.CreateScope(ctx, ks) 59 if err != nil { 60 return errors.Wrapf(err, "Could not create keyspace %q", ks) 61 } 62 _, err = testStore.UpsertSchema( 63 ctx, entityInfo.Ref.Scope, entityInfo.Ref.NamePrefix, []*dosa.EntityDefinition{entityInfo.Def}, 64 ) 65 return err 66 } 67 68 func removeTestSchema(ks string) { 69 ctx := context.Background() 70 testStore.DropScope(ctx, ks) 71 } 72 73 var testEntityInfo = newTestEntityInfo(keyspace) 74 75 func newTestEntityInfo(sp string) *dosa.EntityInfo { 76 return &dosa.EntityInfo{ 77 Ref: &dosa.SchemaRef{ 78 Scope: sp, 79 NamePrefix: "test.datastore", 80 EntityName: "testentity", 81 }, 82 Def: &dosa.EntityDefinition{ 83 Name: tableName, 84 Key: &dosa.PrimaryKey{ 85 PartitionKeys: []string{uuidKeyField}, 86 ClusteringKeys: []*dosa.ClusteringKey{ 87 { 88 Name: stringKeyField, 89 Descending: false, 90 }, 91 { 92 Name: int64KeyField, 93 Descending: true, 94 }, 95 }, 96 }, 97 Columns: []*dosa.ColumnDefinition{ 98 { 99 Name: uuidKeyField, 100 Type: dosa.TUUID, 101 }, 102 { 103 Name: stringKeyField, 104 Type: dosa.String, 105 }, 106 { 107 Name: int32Field, 108 Type: dosa.Int32, 109 }, 110 { 111 Name: int64KeyField, 112 Type: dosa.Int64, 113 }, 114 { 115 Name: doubleField, 116 Type: dosa.Double, 117 }, 118 { 119 Name: blobField, 120 Type: dosa.Blob, 121 }, 122 { 123 Name: timestampField, 124 Type: dosa.Timestamp, 125 }, 126 { 127 Name: boolField, 128 Type: dosa.Bool, 129 }, 130 { 131 Name: uuidField, 132 Type: dosa.TUUID, 133 }, 134 { 135 Name: stringField, 136 Type: dosa.String, 137 }, 138 { 139 Name: int64Field, 140 Type: dosa.Int64, 141 }, 142 }, 143 }, 144 } 145 }