Debian Codegraph @

docstore/mongodocstore/cosmos_test.go

raw
1 // Copyright 2019 The Go Cloud Development Kit Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package mongodocstore
16
17 import (
18 "context"
19 "os"
20 "testing"
21
22 "gocloud.dev/docstore/drivertest"
23 "gocloud.dev/internal/testing/setup"
24 )
25
26 // Run conformance tests on Azure Cosmos.
27
28 // See https://docs.microsoft.com/en-us/azure/cosmos-db/connect-mongodb-account
29 // on how to get a MongoDB connection string for Azure Cosmos.
30 var cosmosConnString = os.Getenv("COSMOS_CONNECTION_STRING")
31
32 func TestConformanceCosmos(t *testing.T) {
33 if !*setup.Record {
34 t.Skip("replaying is not yet supported for Azure Cosmos")
35 }
36 if cosmosConnString == "" {
37 t.Fatal("test harness requires COSMOS_CONNECTION_STRING environment variable to run")
38 }
39
40 ctx := context.Background()
41 client, err := Dial(ctx, cosmosConnString)
42 if err != nil {
43 t.Fatalf("dialing to %s: %v", cosmosConnString, err)
44 }
45 if err := client.Ping(ctx, nil); err != nil {
46 t.Fatalf("connecting to %s: %v", cosmosConnString, err)
47 }
48 defer func() {
49 // Cleanup any resource to avoid wastes.
50 client.Database(dbName).Drop(ctx)
51 client.Disconnect(ctx)
52 }()
53
54 newHarness := func(context.Context, *testing.T) (drivertest.Harness, error) {
55 return &harness{client.Database(dbName), true}, nil
56 }
57 drivertest.RunConformanceTests(t, newHarness, codecTester{}, []drivertest.AsTest{verifyAs{}})
58 }