github.com/pachyderm/pachyderm@v1.13.4/src/server/pkg/storage/chunk/util.go (about) 1 package chunk 2 3 import ( 4 "math/rand" 5 "testing" 6 7 "github.com/jmoiron/sqlx" 8 "github.com/pachyderm/pachyderm/src/server/pkg/obj" 9 "github.com/pachyderm/pachyderm/src/server/pkg/storage/track" 10 ) 11 12 // NewTestStorage creates a local storage instance for testing during the lifetime of 13 // the callback. 14 func NewTestStorage(t testing.TB, db *sqlx.DB, tr track.Tracker, opts ...StorageOption) (obj.Client, *Storage) { 15 mdstore := NewTestStore(t, db) 16 objC := obj.NewTestClient(t) 17 return objC, NewStorage(objC, mdstore, tr, opts...) 18 } 19 20 // NewTestStore creates a store for testing. 21 func NewTestStore(t testing.TB, db *sqlx.DB) MetadataStore { 22 db.MustExec(schema) 23 return NewPostgresStore(db) 24 } 25 26 var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") 27 28 // RandSeq generates a random sequence of data (n is number of bytes) 29 func RandSeq(n int) []byte { 30 b := make([]rune, n) 31 for i := range b { 32 b[i] = letters[rand.Intn(len(letters))] 33 } 34 return []byte(string(b)) 35 } 36 37 // Reference creates a data reference for the full chunk referenced by a data reference. 38 func Reference(dataRef *DataRef) *DataRef { 39 chunkDataRef := &DataRef{} 40 chunkDataRef.Ref = dataRef.Ref 41 chunkDataRef.SizeBytes = dataRef.Ref.SizeBytes 42 return chunkDataRef 43 }