...
1
16
17 package volume_test
18
19 import (
20 "os"
21 "testing"
22
23 utiltesting "k8s.io/client-go/util/testing"
24 . "k8s.io/kubernetes/pkg/volume"
25 volumetest "k8s.io/kubernetes/pkg/volume/testing"
26 )
27
28 func TestGetMetricsStatFS(t *testing.T) {
29 metrics := NewMetricsStatFS("")
30 actual, err := metrics.GetMetrics()
31 expected := &Metrics{}
32 if !volumetest.MetricsEqualIgnoreTimestamp(actual, expected) {
33 t.Errorf("Expected empty Metrics from uninitialized MetricsStatFS, actual %v", *actual)
34 }
35 if err == nil {
36 t.Errorf("Expected error when calling GetMetrics on uninitialized MetricsStatFS, actual nil")
37 }
38
39 metrics = NewMetricsStatFS("/not/a/real/directory")
40 actual, err = metrics.GetMetrics()
41 if !volumetest.MetricsEqualIgnoreTimestamp(actual, expected) {
42 t.Errorf("Expected empty Metrics from incorrectly initialized MetricsStatFS, actual %v", *actual)
43 }
44 if err == nil {
45 t.Errorf("Expected error when calling GetMetrics on incorrectly initialized MetricsStatFS, actual nil")
46 }
47
48 tmpDir, err := utiltesting.MkTmpdir("metric_statfs_test")
49 if err != nil {
50 t.Fatalf("Can't make a tmp dir: %v", err)
51 }
52 defer os.RemoveAll(tmpDir)
53
54 metrics = NewMetricsStatFS(tmpDir)
55 actual, err = metrics.GetMetrics()
56 if err != nil {
57 t.Errorf("Unexpected error when calling GetMetrics %v", err)
58 }
59
60 if a := actual.Capacity.Value(); a <= 0 {
61 t.Errorf("Expected Capacity %d to be greater than 0.", a)
62 }
63 if a := actual.Available.Value(); a <= 0 {
64 t.Errorf("Expected Available %d to be greater than 0.", a)
65 }
66
67 }
68
View as plain text