github.com/muhammadn/cortex@v1.9.1-0.20220510110439-46bb7000d03d/pkg/chunk/local/fixtures.go (about)

     1  package local
     2  
     3  import (
     4  	"io"
     5  	"io/ioutil"
     6  	"os"
     7  	"time"
     8  
     9  	"github.com/prometheus/common/model"
    10  
    11  	"github.com/cortexproject/cortex/pkg/chunk"
    12  	"github.com/cortexproject/cortex/pkg/chunk/objectclient"
    13  	"github.com/cortexproject/cortex/pkg/chunk/testutils"
    14  )
    15  
    16  type fixture struct {
    17  	name    string
    18  	dirname string
    19  }
    20  
    21  func (f *fixture) Name() string {
    22  	return f.name
    23  }
    24  
    25  func (f *fixture) Clients() (
    26  	indexClient chunk.IndexClient, chunkClient chunk.Client, tableClient chunk.TableClient,
    27  	schemaConfig chunk.SchemaConfig, closer io.Closer, err error,
    28  ) {
    29  	f.dirname, err = ioutil.TempDir(os.TempDir(), "boltdb")
    30  	if err != nil {
    31  		return
    32  	}
    33  
    34  	indexClient, err = NewBoltDBIndexClient(BoltDBConfig{
    35  		Directory: f.dirname,
    36  	})
    37  	if err != nil {
    38  		return
    39  	}
    40  
    41  	oClient, err := NewFSObjectClient(FSConfig{Directory: f.dirname})
    42  	if err != nil {
    43  		return
    44  	}
    45  
    46  	chunkClient = objectclient.NewClient(oClient, objectclient.Base64Encoder)
    47  
    48  	tableClient, err = NewTableClient(f.dirname)
    49  	if err != nil {
    50  		return
    51  	}
    52  
    53  	schemaConfig = chunk.SchemaConfig{
    54  		Configs: []chunk.PeriodConfig{{
    55  			IndexType: "boltdb",
    56  			From:      chunk.DayTime{Time: model.Now()},
    57  			ChunkTables: chunk.PeriodicTableConfig{
    58  				Prefix: "chunks",
    59  				Period: 10 * time.Minute,
    60  			},
    61  			IndexTables: chunk.PeriodicTableConfig{
    62  				Prefix: "index",
    63  				Period: 10 * time.Minute,
    64  			},
    65  		}},
    66  	}
    67  
    68  	closer = testutils.CloserFunc(func() error {
    69  		return os.RemoveAll(f.dirname)
    70  	})
    71  
    72  	return
    73  }
    74  
    75  // Fixtures for unit testing GCP storage.
    76  var Fixtures = []testutils.Fixture{
    77  	&fixture{
    78  		name: "boltdb",
    79  	},
    80  }