Skip to content

Commit

Permalink
fix flare tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brycekahle committed Nov 18, 2024
1 parent d0cda43 commit 0257bff
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 10 deletions.
38 changes: 38 additions & 0 deletions cmd/agent/subcommands/flare/command_darwin_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2024-present Datadog, Inc.

package flare

import (
"net/http"
"net/http/httptest"
"path"
"testing"

"github.com/stretchr/testify/require"

"github.com/DataDog/datadog-agent/pkg/config/model"
)

func sysprobeSocketPath(t *testing.T) string {
return path.Join(t.TempDir(), "sysprobe.sock")
}

// NewSystemProbeTestServer starts a new mock server to handle System Probe requests.
func NewSystemProbeTestServer(_ http.Handler) (*httptest.Server, error) {
return nil, nil
}

// InjectConnectionFailures injects a failure in TestReadProfileDataErrors.
func InjectConnectionFailures(_ model.Config, _ model.Config) {
// macOS doesn't currently support any system-probe modules
}

// CheckExpectedConnectionFailures checks the expected errors after simulated
// connection failures.
func CheckExpectedConnectionFailures(c *commandTestSuite, err error) {
// System probe by default is disabled and no connection is attempted for it in the test.
require.Regexp(c.T(), "^4 errors occurred:\n", err.Error())
}
9 changes: 6 additions & 3 deletions cmd/agent/subcommands/flare/command_other_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2024-present Datadog, Inc.

//go:build !windows
//go:build !windows && !darwin

// Package flare implements 'agent flare'.
package flare

import (
"net/http"
"net/http/httptest"
"path"
"testing"

"github.com/stretchr/testify/require"

"github.com/DataDog/datadog-agent/pkg/config/model"
)

const systemProbeTestPipeName = ""
func sysprobeSocketPath(t *testing.T) string {
return path.Join(t.TempDir(), "sysprobe.sock")
}

// NewSystemProbeTestServer starts a new mock server to handle System Probe requests.
func NewSystemProbeTestServer(_ http.Handler) (*httptest.Server, error) {
Expand All @@ -35,6 +39,5 @@ func InjectConnectionFailures(mockSysProbeConfig model.Config, _ model.Config) {
// CheckExpectedConnectionFailures checks the expected errors after simulated
// connection failures.
func CheckExpectedConnectionFailures(c *commandTestSuite, err error) {
// System probe by default is disabled and no connection is attempted for it in the test.
require.Regexp(c.T(), "^5 errors occurred:\n", err.Error())
}
7 changes: 1 addition & 6 deletions cmd/agent/subcommands/flare/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"path"
"runtime"
"testing"

Expand All @@ -36,11 +35,7 @@ type commandTestSuite struct {

func (c *commandTestSuite) SetupSuite() {
t := c.T()
if runtime.GOOS == "windows" {
c.sysprobeSocketPath = systemProbeTestPipeName
} else {
c.sysprobeSocketPath = path.Join(t.TempDir(), "sysprobe.sock")
}
c.sysprobeSocketPath = sysprobeSocketPath(t)
}

// startTestServers starts test servers from a clean state to ensure no cache responses are used.
Expand Down
7 changes: 6 additions & 1 deletion cmd/agent/subcommands/flare/command_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package flare
import (
"net/http"
"net/http/httptest"
"testing"

"github.com/stretchr/testify/require"

Expand All @@ -19,10 +20,14 @@ import (
)

const (
// SystemProbeTestPipeName is the test named pipe for system-probe
// systemProbeTestPipeName is the test named pipe for system-probe
systemProbeTestPipeName = `\\.\pipe\dd_system_probe_flare_test`
)

func sysprobeSocketPath(_ *testing.T) string {
return systemProbeTestPipeName
}

// NewSystemProbeTestServer starts a new mock server to handle System Probe requests.
func NewSystemProbeTestServer(handler http.Handler) (*httptest.Server, error) {
server := httptest.NewUnstartedServer(handler)
Expand Down

0 comments on commit 0257bff

Please sign in to comment.