From 7888e52b966c19cf5027d3970face053eee0fa40 Mon Sep 17 00:00:00 2001 From: Iain Lane Date: Tue, 29 Mar 2022 18:21:56 +0100 Subject: [PATCH] Fix server delete tests Now we pass a collector to `ServerDelete()`, more metrics are in the registry and the ones we want are at the end. --- metrics/server_delete_test.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/metrics/server_delete_test.go b/metrics/server_delete_test.go index 8aee546e..c0e02c00 100644 --- a/metrics/server_delete_test.go +++ b/metrics/server_delete_test.go @@ -35,7 +35,8 @@ func TestServerDelete(t *testing.T) { provider.EXPECT().Destroy(noContext, instance).Times(3).Return(nil) provider.EXPECT().Destroy(noContext, instance).Return(errors.New("error")) - providerInst := ServerDelete(provider) + collector := New() + providerInst := ServerDelete(provider, collector) for i := 0; i < 3; i++ { err := providerInst.Destroy(noContext, instance) if err != nil { @@ -52,20 +53,20 @@ func TestServerDelete(t *testing.T) { t.Error(err) return } - if want, got := len(metrics), 2; want != got { - t.Errorf("Expect registered metric") + if want, got := len(metrics), 8; want != got { + t.Errorf("Expect registered metric %d, got %d", want, got) return } - if got, want := metrics[0].GetName(), "drone_servers_deleted"; want != got { + if got, want := metrics[6].GetName(), "drone_servers_deleted"; want != got { t.Errorf("Expect metric name %s, got %s", want, got) } - if got, want := metrics[0].Metric[0].Counter.GetValue(), float64(3); want != got { + if got, want := metrics[6].Metric[0].Counter.GetValue(), float64(3); want != got { t.Errorf("Expect metric value %f, got %f", want, got) } - if got, want := metrics[1].GetName(), "drone_servers_deleted_err"; want != got { + if got, want := metrics[7].GetName(), "drone_servers_deleted_err"; want != got { t.Errorf("Expect metric name %s, got %s", want, got) } - if got, want := metrics[1].Metric[0].Counter.GetValue(), float64(1); want != got { + if got, want := metrics[7].Metric[0].Counter.GetValue(), float64(1); want != got { t.Errorf("Expect metric value %f, got %f", want, got) } }