github.com/treeverse/lakefs@v1.24.1-0.20240520134607-95648127bfb0/pkg/kv/cosmosdb/main_test.go (about)

     1  package cosmosdb_test
     2  
     3  import (
     4  	"context"
     5  	"os"
     6  	"testing"
     7  
     8  	"github.com/treeverse/lakefs/pkg/kv"
     9  	"github.com/treeverse/lakefs/pkg/kv/cosmosdb"
    10  	"github.com/treeverse/lakefs/pkg/kv/kvparams"
    11  	"github.com/treeverse/lakefs/pkg/kv/kvtest"
    12  )
    13  
    14  var testParams *kvparams.CosmosDB
    15  
    16  func TestCosmosDB(t *testing.T) {
    17  	t.Skip("CosmosDB tests are flaky due to the emulator. If you plan on running those, make sure to assign at least 3CPUs and" +
    18  		" 4GB of memory to the container running the emulator.")
    19  	kvtest.DriverTest(t, func(t testing.TB, ctx context.Context) kv.Store {
    20  		t.Helper()
    21  		store, err := kv.Open(ctx, kvparams.Config{CosmosDB: testParams, Type: cosmosdb.DriverName})
    22  		if err != nil {
    23  			t.Fatalf("failed to open kv '%s' store: %s", cosmosdb.DriverName, err)
    24  		}
    25  		t.Cleanup(store.Close)
    26  		return store
    27  	})
    28  }
    29  
    30  func TestMain(m *testing.M) {
    31  	code := m.Run()
    32  	os.Exit(code)
    33  
    34  	//uncomment the below to run the tests against a CosmosDB emulator
    35  
    36  	//databaseURI, cleanupFunc, err := testutil.GetCosmosDBInstance()
    37  	//if err != nil {
    38  	//	log.Fatalf("Could not connect to Docker: %s", err)
    39  	//}
    40  	//
    41  	//testParams = &kvparams.CosmosDB{
    42  	//	Endpoint:     databaseURI,
    43  	//	Key: "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
    44  	//	Database:     "test-db",
    45  	//	Container:    "test-container",
    46  	//	Client: &http.Client{Timeout: 30 * time.Second, Transport: &http.Transport{
    47  	//		TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, //nolint:gosec // ignore self-signed cert for local testing using the emulator
    48  	//	}},
    49  	//	StrongConsistency: false,
    50  	//}
    51  	//
    52  	//cred, err := azcosmos.NewKeyCredential(testParams.Key)
    53  	//if err != nil {
    54  	//	log.Fatalf("creating key: %v", err)
    55  	//}
    56  	//// Create a CosmosDB client
    57  	//client, err := azcosmos.NewClientWithKey(testParams.Endpoint, cred, &azcosmos.ClientOptions{
    58  	//	ClientOptions: azcore.ClientOptions{
    59  	//		Transport: &http.Client{Transport: &http.Transport{
    60  	//			TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
    61  	//		}},
    62  	//	},
    63  	//})
    64  	//if err != nil {
    65  	//	log.Fatalf("creating client using access key: %v", err)
    66  	//}
    67  	//
    68  	//log.Printf("Creating database %s", testParams.Database)
    69  	//
    70  	//ctx := context.Background()
    71  	//throughput := azcosmos.NewManualThroughputProperties(4000)
    72  	//resp, err := client.CreateDatabase(ctx, azcosmos.DatabaseProperties{ID: testParams.Database},
    73  	//	&azcosmos.CreateDatabaseOptions{ThroughputProperties: &throughput})
    74  	//if err != nil {
    75  	//	print(resp.RawResponse)
    76  	//	log.Fatalf("creating database: %v", err)
    77  	//}
    78  	//
    79  	//databaseClient, err := client.NewDatabase(testParams.Database)
    80  	//if err != nil {
    81  	//	log.Fatalf("creating database client: %v", err)
    82  	//}
    83  	//
    84  	//log.Printf("Creating container %s", testParams.Container)
    85  	//resp2, err := databaseClient.CreateContainer(ctx, azcosmos.ContainerProperties{
    86  	//	ID: testParams.Container,
    87  	//	PartitionKeyDefinition: azcosmos.PartitionKeyDefinition{
    88  	//		Paths: []string{"/partitionKey"},
    89  	//	},
    90  	//}, &azcosmos.CreateContainerOptions{ThroughputProperties: &throughput})
    91  	//if err != nil {
    92  	//	print(resp2.RawResponse)
    93  	//	log.Fatalf("creating container: %v", err)
    94  	//}
    95  	//
    96  	//code := m.Run()
    97  	//cleanupFunc()
    98  	//os.Exit(code)
    99  }