From 79126376f02997be3b125555e1fdccda0f63a5f4 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Mon, 2 Nov 2020 17:02:57 +0100 Subject: [PATCH] Add test for counting inodes correct with hardlinks --- pkg/volume/metrics_du_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkg/volume/metrics_du_test.go b/pkg/volume/metrics_du_test.go index 3bee08bf1ed..55570f2b321 100644 --- a/pkg/volume/metrics_du_test.go +++ b/pkg/volume/metrics_du_test.go @@ -81,6 +81,21 @@ func TestMetricsDuGetCapacity(t *testing.T) { if e, a := (expectedEmptyDirUsage.Value() + getExpectedBlockSize(filepath.Join(tmpDir, "f1"))), actual.Used.Value(); e != a { t.Errorf("Unexpected Used for directory with file. Expected %v, got %d.", e, a) } + + // create a hardlink and expect inodes count to stay the same + previousInodes := actual.InodesUsed.Value() + err = os.Link(filepath.Join(tmpDir, "f1"), filepath.Join(tmpDir, "f2")) + if err != nil { + t.Errorf("Unexpected error when creating hard link %v", err) + } + actual, err = metrics.GetMetrics() + if err != nil { + t.Errorf("Unexpected error when calling GetMetrics %v", err) + } + if e, a := previousInodes, actual.InodesUsed.Value(); e != a { + t.Errorf("Unexpected Used for directory with file. Expected %v, got %d.", e, a) + } + } // TestMetricsDuRequireInit tests that if MetricsDu is not initialized with a path, GetMetrics