From 337a5a3606235ae9e45a141d8357f29659db2dac Mon Sep 17 00:00:00 2001 From: Xabier Arbulu Insausti Date: Wed, 21 Sep 2022 09:36:12 +0200 Subject: [PATCH] Extract command executor to utils package (#102) --- .../gatherers => utils}/commandexecutor.go | 2 +- .../mocks/CommandExecutor.go | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) rename internal/{factsengine/gatherers => utils}/commandexecutor.go (94%) rename internal/{factsengine/gatherers => utils}/mocks/CommandExecutor.go (63%) diff --git a/internal/factsengine/gatherers/commandexecutor.go b/internal/utils/commandexecutor.go similarity index 94% rename from internal/factsengine/gatherers/commandexecutor.go rename to internal/utils/commandexecutor.go index 8b31dd78..d23cee36 100644 --- a/internal/factsengine/gatherers/commandexecutor.go +++ b/internal/utils/commandexecutor.go @@ -1,4 +1,4 @@ -package gatherers +package utils import ( "os/exec" diff --git a/internal/factsengine/gatherers/mocks/CommandExecutor.go b/internal/utils/mocks/CommandExecutor.go similarity index 63% rename from internal/factsengine/gatherers/mocks/CommandExecutor.go rename to internal/utils/mocks/CommandExecutor.go index c79c7d21..cb4b4e16 100644 --- a/internal/factsengine/gatherers/mocks/CommandExecutor.go +++ b/internal/utils/mocks/CommandExecutor.go @@ -1,4 +1,4 @@ -// Code generated by mockery v0.0.0-dev. DO NOT EDIT. +// Code generated by mockery v2.12.3. DO NOT EDIT. package mocks @@ -38,3 +38,18 @@ func (_m *CommandExecutor) Exec(name string, arg ...string) ([]byte, error) { return r0, r1 } + +type NewCommandExecutorT interface { + mock.TestingT + Cleanup(func()) +} + +// NewCommandExecutor creates a new instance of CommandExecutor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewCommandExecutor(t NewCommandExecutorT) *CommandExecutor { + mock := &CommandExecutor{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +}