github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/internal/testserver/datastore/config/config.go (about)

     1  //go:build docker
     2  // +build docker
     3  
     4  package config
     5  
     6  import (
     7  	"context"
     8  	"testing"
     9  
    10  	"github.com/stretchr/testify/require"
    11  
    12  	testdatastore "github.com/authzed/spicedb/internal/testserver/datastore"
    13  	dsconfig "github.com/authzed/spicedb/pkg/cmd/datastore"
    14  	"github.com/authzed/spicedb/pkg/datastore"
    15  )
    16  
    17  // DatastoreConfigInitFunc returns a InitFunc that constructs a ds
    18  // with the top-level cmd/datastore machinery.
    19  // It can't be used everywhere due to import cycles, but makes it easy to write
    20  // an independent test with CLI-like config where possible.
    21  func DatastoreConfigInitFunc(t testing.TB, options ...dsconfig.ConfigOption) testdatastore.InitFunc {
    22  	return func(engine, uri string) datastore.Datastore {
    23  		ds, err := dsconfig.NewDatastore(context.Background(),
    24  			append(options,
    25  				dsconfig.WithEngine(engine),
    26  				dsconfig.WithEnableDatastoreMetrics(false),
    27  				dsconfig.WithURI(uri),
    28  			)...)
    29  		require.NoError(t, err)
    30  		return ds
    31  	}
    32  }