You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
prometheus/util/testutil/storage.go

36 lines
731 B

package testutil
import (
"io/ioutil"
"os"
"github.com/prometheus/prometheus/storage"
"github.com/prometheus/prometheus/storage/tsdb"
)
// NewStorage returns a new storage for testing purposes
// that removes all associated files on closing.
func NewStorage(t T) storage.Storage {
dir, err := ioutil.TempDir("", "test_storage")
if err != nil {
t.Fatalf("Opening test dir failed: %s", err)
}
db, err := tsdb.Open(dir)
if err != nil {
t.Fatalf("Opening test storage failed: %s", err)
}
return testStorage{Storage: db, dir: dir}
}
type testStorage struct {
storage.Storage
dir string
}
func (s testStorage) Close() error {
if err := s.Storage.Close(); err != nil {
return err
}
return os.RemoveAll(s.dir)
}