mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Avoid test flags in normal binary.
Change-Id: If1fba813a73bf93ea5918dcda326e3ffa81a797d
This commit is contained in:
parent
ea86f7e8f8
commit
49683c0c20
|
@ -11,10 +11,14 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
// NOTE ON FILENAME: Do not rename this file helpers_test.go (which might appear
|
||||||
|
// an obvious choice). We need NewTestStorage in tests outside of the local
|
||||||
|
// package, too. On the other hand, moving NewTestStorage in its own package
|
||||||
|
// would cause circular dependencies in the tests in packages local.
|
||||||
|
|
||||||
package local
|
package local
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/prometheus/prometheus/utility/test"
|
"github.com/prometheus/prometheus/utility/test"
|
||||||
|
@ -33,7 +37,7 @@ func (t *testStorageCloser) Close() {
|
||||||
// NewTestStorage creates a storage instance backed by files in a temporary
|
// NewTestStorage creates a storage instance backed by files in a temporary
|
||||||
// directory. The returned storage is already in serving state. Upon closing the
|
// directory. The returned storage is already in serving state. Upon closing the
|
||||||
// returned test.Closer, the temporary directory is cleaned up.
|
// returned test.Closer, the temporary directory is cleaned up.
|
||||||
func NewTestStorage(t testing.TB) (Storage, test.Closer) {
|
func NewTestStorage(t test.T) (Storage, test.Closer) {
|
||||||
directory := test.NewTemporaryDirectory("test_storage", t)
|
directory := test.NewTemporaryDirectory("test_storage", t)
|
||||||
o := &MemorySeriesStorageOptions{
|
o := &MemorySeriesStorageOptions{
|
||||||
MemoryChunks: 1000000,
|
MemoryChunks: 1000000,
|
||||||
|
|
|
@ -16,7 +16,6 @@ package test
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -51,12 +50,21 @@ type (
|
||||||
// their interactions.
|
// their interactions.
|
||||||
temporaryDirectory struct {
|
temporaryDirectory struct {
|
||||||
path string
|
path string
|
||||||
tester testing.TB
|
tester T
|
||||||
}
|
}
|
||||||
|
|
||||||
callbackCloser struct {
|
callbackCloser struct {
|
||||||
fn func()
|
fn func()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// T implements the needed methods of testing.TB so that we do not need
|
||||||
|
// to actually import testing (which has the side affect of adding all
|
||||||
|
// the test flags, which we do not want in non-test binaries even if
|
||||||
|
// they make use of these utilities for some reason).
|
||||||
|
T interface {
|
||||||
|
Fatal(args ...interface{})
|
||||||
|
Fatalf(format string, args ...interface{})
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c nilCloser) Close() {
|
func (c nilCloser) Close() {
|
||||||
|
@ -90,7 +98,7 @@ func (t temporaryDirectory) Path() string {
|
||||||
|
|
||||||
// NewTemporaryDirectory creates a new temporary directory for transient POSIX
|
// NewTemporaryDirectory creates a new temporary directory for transient POSIX
|
||||||
// activities.
|
// activities.
|
||||||
func NewTemporaryDirectory(name string, t testing.TB) (handler TemporaryDirectory) {
|
func NewTemporaryDirectory(name string, t T) (handler TemporaryDirectory) {
|
||||||
var (
|
var (
|
||||||
directory string
|
directory string
|
||||||
err error
|
err error
|
||||||
|
|
Loading…
Reference in a new issue