mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-10 07:34:04 -08:00
Merge pull request #2927 from pafuent/fix-test-short-for-windows
Fixing tests for Windows
This commit is contained in:
commit
f0f2ec7854
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -13,6 +13,7 @@
|
||||||
.*.swo
|
.*.swo
|
||||||
*.iml
|
*.iml
|
||||||
.idea
|
.idea
|
||||||
|
tags
|
||||||
|
|
||||||
/prometheus
|
/prometheus
|
||||||
/promtool
|
/promtool
|
||||||
|
|
28
config/config_default_test.go
Normal file
28
config/config_default_test.go
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package config
|
||||||
|
|
||||||
|
const ruleFilesConfigFile = "testdata/rules_abs_path.good.yml"
|
||||||
|
|
||||||
|
var ruleFilesExpectedConf = &Config{
|
||||||
|
GlobalConfig: DefaultGlobalConfig,
|
||||||
|
RuleFiles: []string{
|
||||||
|
"testdata/first.rules",
|
||||||
|
"testdata/rules/second.rules",
|
||||||
|
"/absolute/third.rules",
|
||||||
|
},
|
||||||
|
original: "",
|
||||||
|
}
|
|
@ -17,6 +17,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -48,9 +49,8 @@ var expectedConf = &Config{
|
||||||
},
|
},
|
||||||
|
|
||||||
RuleFiles: []string{
|
RuleFiles: []string{
|
||||||
"testdata/first.rules",
|
filepath.FromSlash("testdata/first.rules"),
|
||||||
"/absolute/second.rules",
|
filepath.FromSlash("testdata/my/*.rules"),
|
||||||
"testdata/my/*.rules",
|
|
||||||
},
|
},
|
||||||
|
|
||||||
RemoteWriteConfigs: []*RemoteWriteConfig{
|
RemoteWriteConfigs: []*RemoteWriteConfig{
|
||||||
|
@ -85,7 +85,7 @@ var expectedConf = &Config{
|
||||||
Scheme: DefaultScrapeConfig.Scheme,
|
Scheme: DefaultScrapeConfig.Scheme,
|
||||||
|
|
||||||
HTTPClientConfig: HTTPClientConfig{
|
HTTPClientConfig: HTTPClientConfig{
|
||||||
BearerTokenFile: "testdata/valid_token_file",
|
BearerTokenFile: filepath.FromSlash("testdata/valid_token_file"),
|
||||||
},
|
},
|
||||||
|
|
||||||
ServiceDiscoveryConfig: ServiceDiscoveryConfig{
|
ServiceDiscoveryConfig: ServiceDiscoveryConfig{
|
||||||
|
@ -252,9 +252,9 @@ var expectedConf = &Config{
|
||||||
TagSeparator: DefaultConsulSDConfig.TagSeparator,
|
TagSeparator: DefaultConsulSDConfig.TagSeparator,
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
TLSConfig: TLSConfig{
|
TLSConfig: TLSConfig{
|
||||||
CertFile: "testdata/valid_cert_file",
|
CertFile: filepath.FromSlash("testdata/valid_cert_file"),
|
||||||
KeyFile: "testdata/valid_key_file",
|
KeyFile: filepath.FromSlash("testdata/valid_key_file"),
|
||||||
CAFile: "testdata/valid_ca_file",
|
CAFile: filepath.FromSlash("testdata/valid_ca_file"),
|
||||||
InsecureSkipVerify: false,
|
InsecureSkipVerify: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -283,8 +283,8 @@ var expectedConf = &Config{
|
||||||
|
|
||||||
HTTPClientConfig: HTTPClientConfig{
|
HTTPClientConfig: HTTPClientConfig{
|
||||||
TLSConfig: TLSConfig{
|
TLSConfig: TLSConfig{
|
||||||
CertFile: "testdata/valid_cert_file",
|
CertFile: filepath.FromSlash("testdata/valid_cert_file"),
|
||||||
KeyFile: "testdata/valid_key_file",
|
KeyFile: filepath.FromSlash("testdata/valid_key_file"),
|
||||||
},
|
},
|
||||||
|
|
||||||
BearerToken: "mysecret",
|
BearerToken: "mysecret",
|
||||||
|
@ -354,8 +354,8 @@ var expectedConf = &Config{
|
||||||
Timeout: model.Duration(30 * time.Second),
|
Timeout: model.Duration(30 * time.Second),
|
||||||
RefreshInterval: model.Duration(30 * time.Second),
|
RefreshInterval: model.Duration(30 * time.Second),
|
||||||
TLSConfig: TLSConfig{
|
TLSConfig: TLSConfig{
|
||||||
CertFile: "testdata/valid_cert_file",
|
CertFile: filepath.FromSlash("testdata/valid_cert_file"),
|
||||||
KeyFile: "testdata/valid_key_file",
|
KeyFile: filepath.FromSlash("testdata/valid_key_file"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -549,6 +549,29 @@ func TestLoadConfig(t *testing.T) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLoadConfigRuleFilesAbsolutePath(t *testing.T) {
|
||||||
|
// Parse a valid file that sets a rule files with an absolute path
|
||||||
|
c, err := LoadFile(ruleFilesConfigFile)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error parsing %s: %s", ruleFilesConfigFile, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
bgot, err := yaml.Marshal(c)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
bexp, err := yaml.Marshal(ruleFilesExpectedConf)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s", err)
|
||||||
|
}
|
||||||
|
ruleFilesExpectedConf.original = c.original
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(c, ruleFilesExpectedConf) {
|
||||||
|
t.Fatalf("%s: unexpected config result: \n\n%s\n expected\n\n%s", ruleFilesConfigFile, bgot, bexp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var expectedErrors = []struct {
|
var expectedErrors = []struct {
|
||||||
filename string
|
filename string
|
||||||
errMsg string
|
errMsg string
|
||||||
|
|
26
config/config_windows_test.go
Normal file
26
config/config_windows_test.go
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
package config
|
||||||
|
|
||||||
|
const ruleFilesConfigFile = "testdata/rules_abs_path_windows.good.yml"
|
||||||
|
|
||||||
|
var ruleFilesExpectedConf = &Config{
|
||||||
|
GlobalConfig: DefaultGlobalConfig,
|
||||||
|
RuleFiles: []string{
|
||||||
|
"testdata\\first.rules",
|
||||||
|
"testdata\\rules\\second.rules",
|
||||||
|
"c:\\absolute\\third.rules",
|
||||||
|
},
|
||||||
|
original: "",
|
||||||
|
}
|
1
config/testdata/conf.good.yml
vendored
1
config/testdata/conf.good.yml
vendored
|
@ -10,7 +10,6 @@ global:
|
||||||
|
|
||||||
rule_files:
|
rule_files:
|
||||||
- "first.rules"
|
- "first.rules"
|
||||||
- "/absolute/second.rules"
|
|
||||||
- "my/*.rules"
|
- "my/*.rules"
|
||||||
|
|
||||||
remote_write:
|
remote_write:
|
||||||
|
|
4
config/testdata/rules_abs_path.good.yml
vendored
Normal file
4
config/testdata/rules_abs_path.good.yml
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
rule_files:
|
||||||
|
- 'first.rules'
|
||||||
|
- 'rules/second.rules'
|
||||||
|
- '/absolute/third.rules'
|
4
config/testdata/rules_abs_path_windows.good.yml
vendored
Normal file
4
config/testdata/rules_abs_path_windows.good.yml
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
rule_files:
|
||||||
|
- 'first.rules'
|
||||||
|
- 'rules\second.rules'
|
||||||
|
- 'c:\absolute\third.rules'
|
|
@ -17,6 +17,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -89,12 +90,12 @@ retry:
|
||||||
if _, ok := tg.Labels["foo"]; !ok {
|
if _, ok := tg.Labels["foo"]; !ok {
|
||||||
t.Fatalf("Label not parsed")
|
t.Fatalf("Label not parsed")
|
||||||
}
|
}
|
||||||
if tg.String() != fmt.Sprintf("fixtures/_test%s:0", ext) {
|
if tg.String() != filepath.FromSlash(fmt.Sprintf("fixtures/_test%s:0", ext)) {
|
||||||
t.Fatalf("Unexpected target group %s", tg)
|
t.Fatalf("Unexpected target group %s", tg)
|
||||||
}
|
}
|
||||||
|
|
||||||
tg = tgs[1]
|
tg = tgs[1]
|
||||||
if tg.String() != fmt.Sprintf("fixtures/_test%s:1", ext) {
|
if tg.String() != filepath.FromSlash(fmt.Sprintf("fixtures/_test%s:1", ext)) {
|
||||||
t.Fatalf("Unexpected target groups %s", tg)
|
t.Fatalf("Unexpected target groups %s", tg)
|
||||||
}
|
}
|
||||||
break retry
|
break retry
|
||||||
|
|
|
@ -26,6 +26,9 @@ const (
|
||||||
|
|
||||||
// NilCloser is a no-op Closer.
|
// NilCloser is a no-op Closer.
|
||||||
NilCloser = nilCloser(true)
|
NilCloser = nilCloser(true)
|
||||||
|
|
||||||
|
// The number of times that a TemporaryDirectory will retry its removal
|
||||||
|
temporaryDirectoryRemoveRetries = 2
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
@ -84,15 +87,20 @@ func NewCallbackCloser(fn func()) Closer {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t temporaryDirectory) Close() {
|
func (t temporaryDirectory) Close() {
|
||||||
|
retries := temporaryDirectoryRemoveRetries
|
||||||
err := os.RemoveAll(t.path)
|
err := os.RemoveAll(t.path)
|
||||||
if err != nil {
|
for err != nil && retries > 0 {
|
||||||
switch {
|
switch {
|
||||||
case os.IsNotExist(err):
|
case os.IsNotExist(err):
|
||||||
return
|
err = nil
|
||||||
default:
|
default:
|
||||||
t.tester.Fatal(err)
|
retries--
|
||||||
|
err = os.RemoveAll(t.path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err != nil {
|
||||||
|
t.tester.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t temporaryDirectory) Path() string {
|
func (t temporaryDirectory) Path() string {
|
||||||
|
|
Loading…
Reference in a new issue