mirror of https://github.com/prometheus/prometheus
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.
58 lines
1.6 KiB
58 lines
1.6 KiB
8 years ago
|
// Copyright 2017 The Prometheus Authors
|
||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
// you may not use this file except in compliance with the License.
|
||
|
// You may obtain a copy of the License at
|
||
|
//
|
||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||
|
//
|
||
|
// Unless required by applicable law or agreed to in writing, software
|
||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
// See the License for the specific language governing permissions and
|
||
|
// limitations under the License.
|
||
|
|
||
5 years ago
|
package teststorage
|
||
8 years ago
|
|
||
|
import (
|
||
|
"io/ioutil"
|
||
|
"os"
|
||
8 years ago
|
"time"
|
||
8 years ago
|
|
||
8 years ago
|
"github.com/prometheus/common/model"
|
||
8 years ago
|
"github.com/prometheus/prometheus/storage"
|
||
8 years ago
|
"github.com/prometheus/prometheus/storage/tsdb"
|
||
5 years ago
|
"github.com/prometheus/prometheus/util/testutil"
|
||
8 years ago
|
)
|
||
|
|
||
5 years ago
|
// New returns a new storage for testing purposes
|
||
8 years ago
|
// that removes all associated files on closing.
|
||
5 years ago
|
func New(t testutil.T) storage.Storage {
|
||
8 years ago
|
dir, err := ioutil.TempDir("", "test_storage")
|
||
|
if err != nil {
|
||
8 years ago
|
t.Fatalf("Opening test dir failed: %s", err)
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
// Tests just load data for a series sequentially. Thus we
|
||
|
// need a long appendable window.
|
||
7 years ago
|
db, err := tsdb.Open(dir, nil, nil, &tsdb.Options{
|
||
8 years ago
|
MinBlockDuration: model.Duration(24 * time.Hour),
|
||
|
MaxBlockDuration: model.Duration(24 * time.Hour),
|
||
8 years ago
|
})
|
||
8 years ago
|
if err != nil {
|
||
|
t.Fatalf("Opening test storage failed: %s", err)
|
||
|
}
|
||
7 years ago
|
return testStorage{Storage: tsdb.Adapter(db, int64(0)), dir: dir}
|
||
8 years ago
|
}
|
||
|
|
||
|
type testStorage struct {
|
||
8 years ago
|
storage.Storage
|
||
8 years ago
|
dir string
|
||
|
}
|
||
|
|
||
|
func (s testStorage) Close() error {
|
||
8 years ago
|
if err := s.Storage.Close(); err != nil {
|
||
8 years ago
|
return err
|
||
|
}
|
||
|
return os.RemoveAll(s.dir)
|
||
|
}
|