log_metrics_provider_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. Copyright 2018 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 stats
  14. import (
  15. "fmt"
  16. "k8s.io/kubernetes/pkg/volume"
  17. )
  18. type fakeLogMetrics struct {
  19. fakeStats map[string]*volume.Metrics
  20. }
  21. func NewFakeLogMetricsService(stats map[string]*volume.Metrics) LogMetricsService {
  22. return &fakeLogMetrics{fakeStats: stats}
  23. }
  24. func (l *fakeLogMetrics) createLogMetricsProvider(path string) volume.MetricsProvider {
  25. return NewFakeMetricsDu(path, l.fakeStats[path])
  26. }
  27. type fakeMetricsDu struct {
  28. fakeStats *volume.Metrics
  29. }
  30. func NewFakeMetricsDu(path string, stats *volume.Metrics) volume.MetricsProvider {
  31. return &fakeMetricsDu{fakeStats: stats}
  32. }
  33. func (f *fakeMetricsDu) GetMetrics() (*volume.Metrics, error) {
  34. if f.fakeStats == nil {
  35. return nil, fmt.Errorf("no stats provided")
  36. }
  37. return f.fakeStats, nil
  38. }