Skip to content

Commit

Permalink
[Heartbeat] Unit test plugin import at cmd level (#39830) (#39831)
Browse files Browse the repository at this point in the history
* [Heartbeat] Unit test plugin imports inside cmd module
Add unit test to cover plugin imports at cmd module, to be run from agentbeat.

(cherry picked from commit 3b24698)

Co-authored-by: Emilio Alvarez Piñeiro <[email protected]>
  • Loading branch information
mergify[bot] and emilioalvap authored Jun 7, 2024
1 parent ff4b518 commit 8e624ca
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
40 changes: 40 additions & 0 deletions heartbeat/cmd/root_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package cmd

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"

"github.com/elastic/beats/v7/heartbeat/monitors/plugin"
)

// Test all required plugins are exported by this module, since it's the
// one imported by agentbeat: https://github.com/elastic/beats/pull/39818
func TestRootCmdPlugins(t *testing.T) {
t.Parallel()
plugins := []string{"http", "tcp", "icmp"}
for _, p := range plugins {
t.Run(fmt.Sprintf("%s plugin", p), func(t *testing.T) {
_, found := plugin.GlobalPluginsReg.Get(p)
assert.True(t, found)
})
}
}
28 changes: 28 additions & 0 deletions x-pack/heartbeat/cmd/root_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.
//go:build linux || synthetics

package cmd

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"

"github.com/elastic/beats/v7/heartbeat/monitors/plugin"
)

// Test all required plugins are exported by this module, since it's the
// one imported by agentbeat: https://github.com/elastic/beats/pull/39818
func TestRootCmdPlugins(t *testing.T) {
t.Parallel()
plugins := []string{"http", "tcp", "icmp", "browser"}
for _, p := range plugins {
t.Run(fmt.Sprintf("%s plugin", p), func(t *testing.T) {
_, found := plugin.GlobalPluginsReg.Get(p)
assert.True(t, found)
})
}
}

0 comments on commit 8e624ca

Please sign in to comment.