diff --git a/src/extensions/nginx-app-protect/nap/nap.go b/src/extensions/nginx-app-protect/nap/nap.go index a062d6aa5..29df9a6f1 100644 --- a/src/extensions/nginx-app-protect/nap/nap.go +++ b/src/extensions/nginx-app-protect/nap/nap.go @@ -10,6 +10,7 @@ import ( var ( requiredNAPFiles = []string{BD_SOCKET_PLUGIN_PATH, NAP_VERSION_FILE} requireNAPProcesses = []string{BD_SOCKET_PLUGIN_PROCESS} + processCheckFunc = core.CheckForProcesses ) // NewNginxAppProtect returns the object NginxAppProtect, which contains information related @@ -158,7 +159,7 @@ func napInstalled(requiredFiles []string) (bool, error) { // the bool will be false and the error will not be nil. func napRunning() (bool, error) { // Check if NAP is running - missingProcesses, err := core.CheckForProcesses(requireNAPProcesses) + missingProcesses, err := processCheckFunc(requireNAPProcesses) if err != nil { return false, err } diff --git a/src/extensions/nginx-app-protect/nap/nap_test.go b/src/extensions/nginx-app-protect/nap/nap_test.go index eff6e8627..b0e74507b 100644 --- a/src/extensions/nginx-app-protect/nap/nap_test.go +++ b/src/extensions/nginx-app-protect/nap/nap_test.go @@ -236,8 +236,13 @@ func TestNAPStatus(t *testing.T) { // Create fake process(es) if tc.procsToCreate != nil { - killFakeProcesses := testutils.StartFakeProcesses(tc.procsToCreate, "5") - t.Cleanup(killFakeProcesses) + processCheckFunc = func(processesToCheck []string) ([]string, error) { + return []string{}, nil + } + } else { + processCheckFunc = func(processesToCheck []string) ([]string, error) { + return []string{"fakeProc"}, nil + } } // Get running status diff --git a/src/plugins/commander_test.go b/src/plugins/commander_test.go index 2ed1cf354..5c1ec917b 100644 --- a/src/plugins/commander_test.go +++ b/src/plugins/commander_test.go @@ -75,15 +75,11 @@ func TestCommander_Process(t *testing.T) { DirectoryMap: &proto.DirectoryMap{}, }, msgTopics: []string{ - core.AgentConnected, core.AgentConnected, core.AgentConfigChanged, core.NginxConfigUpload, core.EnableExtension, core.EnableExtension, - core.NginxConfigUpload, - core.EnableExtension, - core.EnableExtension, }, }, { @@ -223,7 +219,7 @@ func TestCommander_Process(t *testing.T) { ctx := context.TODO() cmdr := tutils.NewMockCommandClient() - mockChannel := testChannel(test.cmd) + mockChannel := testChannel(&proto.Command{}) // setup expectations cmdr.On("Recv").Return(mockChannel) @@ -237,11 +233,11 @@ func TestCommander_Process(t *testing.T) { messagePipe.Process(core.NewMessage(test.topic, test.cmd)) messagePipe.Run() - processedMessages := messagePipe.GetProcessedMessages() - - assert.Eventually(t, func() bool { return len(processedMessages) == len(test.msgTopics) }, 1*time.Second, 100*time.Millisecond) + assert.Eventually(t, func() bool { return len(messagePipe.GetProcessedMessages()) == len(test.msgTopics) }, 1*time.Second, 100*time.Millisecond) cmdr.AssertExpectations(tt) + processedMessages := messagePipe.GetProcessedMessages() + for idx, msg := range processedMessages { if test.msgTopics[idx] != msg.Topic() { tt.Errorf("unexpected message topic: %s :: should have been: %s", msg.Topic(), test.msgTopics[idx]) diff --git a/test/performance/vendor/github.com/nginx/agent/v2/src/extensions/nginx-app-protect/nap/nap.go b/test/performance/vendor/github.com/nginx/agent/v2/src/extensions/nginx-app-protect/nap/nap.go index a062d6aa5..29df9a6f1 100644 --- a/test/performance/vendor/github.com/nginx/agent/v2/src/extensions/nginx-app-protect/nap/nap.go +++ b/test/performance/vendor/github.com/nginx/agent/v2/src/extensions/nginx-app-protect/nap/nap.go @@ -10,6 +10,7 @@ import ( var ( requiredNAPFiles = []string{BD_SOCKET_PLUGIN_PATH, NAP_VERSION_FILE} requireNAPProcesses = []string{BD_SOCKET_PLUGIN_PROCESS} + processCheckFunc = core.CheckForProcesses ) // NewNginxAppProtect returns the object NginxAppProtect, which contains information related @@ -158,7 +159,7 @@ func napInstalled(requiredFiles []string) (bool, error) { // the bool will be false and the error will not be nil. func napRunning() (bool, error) { // Check if NAP is running - missingProcesses, err := core.CheckForProcesses(requireNAPProcesses) + missingProcesses, err := processCheckFunc(requireNAPProcesses) if err != nil { return false, err }