metrics_statfs_test.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. Copyright 2016 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package volume_test
  14. import (
  15. "os"
  16. "testing"
  17. utiltesting "k8s.io/client-go/util/testing"
  18. . "k8s.io/kubernetes/pkg/volume"
  19. volumetest "k8s.io/kubernetes/pkg/volume/testing"
  20. )
  21. func TestGetMetricsStatFS(t *testing.T) {
  22. metrics := NewMetricsStatFS("")
  23. actual, err := metrics.GetMetrics()
  24. expected := &Metrics{}
  25. if !volumetest.MetricsEqualIgnoreTimestamp(actual, expected) {
  26. t.Errorf("Expected empty Metrics from uninitialized MetricsStatFS, actual %v", *actual)
  27. }
  28. if err == nil {
  29. t.Errorf("Expected error when calling GetMetrics on uninitialized MetricsStatFS, actual nil")
  30. }
  31. metrics = NewMetricsStatFS("/not/a/real/directory")
  32. actual, err = metrics.GetMetrics()
  33. if !volumetest.MetricsEqualIgnoreTimestamp(actual, expected) {
  34. t.Errorf("Expected empty Metrics from incorrectly initialized MetricsStatFS, actual %v", *actual)
  35. }
  36. if err == nil {
  37. t.Errorf("Expected error when calling GetMetrics on incorrectly initialized MetricsStatFS, actual nil")
  38. }
  39. tmpDir, err := utiltesting.MkTmpdir("metric_statfs_test")
  40. if err != nil {
  41. t.Fatalf("Can't make a tmp dir: %v", err)
  42. }
  43. defer os.RemoveAll(tmpDir)
  44. metrics = NewMetricsStatFS(tmpDir)
  45. actual, err = metrics.GetMetrics()
  46. if err != nil {
  47. t.Errorf("Unexpected error when calling GetMetrics %v", err)
  48. }
  49. if a := actual.Capacity.Value(); a <= 0 {
  50. t.Errorf("Expected Capacity %d to be greater than 0.", a)
  51. }
  52. if a := actual.Available.Value(); a <= 0 {
  53. t.Errorf("Expected Available %d to be greater than 0.", a)
  54. }
  55. }