aboutsummaryrefslogtreecommitdiff
path: root/collector/paths_test.go
diff options
context:
space:
mode:
authorMatthias Rampke <matthias@rampke.de>2015-09-26 19:38:31 +0200
committerMatthias Rampke <mr@soundcloud.com>2015-09-28 13:56:22 +0000
commit85eb47197fb7fda72d5ae333125883cf21c81f67 (patch)
tree6dc4b7aeb146ea374a49fdb5af20d1903a3ff5fd /collector/paths_test.go
parent24c9db9600adeb390f6c1b669d2fe6c7d8f78573 (diff)
downloadprometheus_node_collector-85eb47197fb7fda72d5ae333125883cf21c81f67.tar.bz2
prometheus_node_collector-85eb47197fb7fda72d5ae333125883cf21c81f67.tar.xz
prometheus_node_collector-85eb47197fb7fda72d5ae333125883cf21c81f67.zip
Add a flag for the sysfs location.
Analogous to `collector.procfs`, but for `/sys`. Add tests for both.
Diffstat (limited to 'collector/paths_test.go')
-rw-r--r--collector/paths_test.go77
1 files changed, 77 insertions, 0 deletions
diff --git a/collector/paths_test.go b/collector/paths_test.go
new file mode 100644
index 0000000..a4f4166
--- /dev/null
+++ b/collector/paths_test.go
@@ -0,0 +1,77 @@
1// Copyright 2015 The Prometheus Authors
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14package collector
15
16import (
17 "flag"
18 "testing"
19
20 "github.com/prometheus/procfs"
21)
22
23func TestDefaultProcPath(t *testing.T) {
24 if err := flag.Set("collector.procfs", procfs.DefaultMountPoint); err != nil {
25 t.Fatal(err)
26 }
27
28 if got, want := procFilePath("somefile"), "/proc/somefile"; got != want {
29 t.Errorf("Expected: %s, Got: %s", want, got)
30 }
31
32 if got, want := procFilePath("some/file"), "/proc/some/file"; got != want {
33 t.Errorf("Expected: %s, Got: %s", want, got)
34 }
35}
36
37func TestCustomProcPath(t *testing.T) {
38 if err := flag.Set("collector.procfs", "./../some/./place/"); err != nil {
39 t.Fatal(err)
40 }
41
42 if got, want := procFilePath("somefile"), "../some/place/somefile"; got != want {
43 t.Errorf("Expected: %s, Got: %s", want, got)
44 }
45
46 if got, want := procFilePath("some/file"), "../some/place/some/file"; got != want {
47 t.Errorf("Expected: %s, Got: %s", want, got)
48 }
49}
50
51func TestDefaultSysPath(t *testing.T) {
52 if err := flag.Set("collector.sysfs", "/sys"); err != nil {
53 t.Fatal(err)
54 }
55
56 if got, want := sysFilePath("somefile"), "/sys/somefile"; got != want {
57 t.Errorf("Expected: %s, Got: %s", want, got)
58 }
59
60 if got, want := sysFilePath("some/file"), "/sys/some/file"; got != want {
61 t.Errorf("Expected: %s, Got: %s", want, got)
62 }
63}
64
65func TestCustomSysPath(t *testing.T) {
66 if err := flag.Set("collector.sysfs", "./../some/./place/"); err != nil {
67 t.Fatal(err)
68 }
69
70 if got, want := sysFilePath("somefile"), "../some/place/somefile"; got != want {
71 t.Errorf("Expected: %s, Got: %s", want, got)
72 }
73
74 if got, want := sysFilePath("some/file"), "../some/place/some/file"; got != want {
75 t.Errorf("Expected: %s, Got: %s", want, got)
76 }
77}