From bd19543f59bd65d964d0a60699c019e48e54c47f Mon Sep 17 00:00:00 2001 From: Manik2708 Date: Sat, 25 Jan 2025 14:09:04 +0530 Subject: [PATCH] initial unit test Signed-off-by: Manik2708 --- plugin/storage/es/ilm/createpolicy_test.go | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 plugin/storage/es/ilm/createpolicy_test.go diff --git a/plugin/storage/es/ilm/createpolicy_test.go b/plugin/storage/es/ilm/createpolicy_test.go new file mode 100644 index 00000000000..4a1ee6b2a7d --- /dev/null +++ b/plugin/storage/es/ilm/createpolicy_test.go @@ -0,0 +1,34 @@ +// Copyright (c) 2025 The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 + +package ilm + +import ( + "testing" + + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" + + "github.com/jaegertracing/jaeger/pkg/es" + "github.com/jaegertracing/jaeger/pkg/es/mocks" +) + +func mockTestingClient(mockFxn func(cl *mocks.Client)) es.Client { + c := &mocks.Client{} + mockFxn(c) + return c +} + +func mockIlmPolicyExists(exists bool) es.Client { + return mockTestingClient(func(cl *mocks.Client) { + cl.On("IlmPolicyExists", mock.Anything, DefaultIlmPolicy).Return(exists, nil) + }) +} + +func TestCreatePolicyIfNotExists(t *testing.T) { + t.Run("IlmPolicyExists", func(t *testing.T) { + cl := mockIlmPolicyExists(true) + err := CreatePolicyIfNotExists(cl, false, 7) + require.NoError(t, err) + }) +}