Skip to content

Commit bf9c087

Browse files
committed
Exclude test helpers from codecov
1 parent e5a4d8d commit bf9c087

File tree

6 files changed

+65
-5
lines changed

6 files changed

+65
-5
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ test: ## Run unit tests
5656
.PHONY: test-coverage-and-junit
5757
test-coverage-and-junit: ## Run unit tests with coverage and junit output
5858
go install github.com/jstemmer/go-junit-report/v2@v2.1.0
59-
$(GOTEST) -v -cover -race -coverprofile=$(COVERAGE_OUT) ./... -json 2>&1 | go-junit-report -parser gojson > $(JUNIT_OUT)
59+
$(GOTEST) -v -cover -race -coverprofile=$(COVERAGE_OUT) ./... -json 2>&1 | go-junit-report -set-exit-code -parser gojson > $(JUNIT_OUT)
6060

6161
.PHONY: coverage-html
6262
coverage-html: test ## Generate and open HTML coverage report

cmd/stackrox-mcp/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestGracefulShutdown(t *testing.T) {
5050
}()
5151

5252
serverURL := "http://" + net.JoinHostPort(cfg.Server.Address, strconv.Itoa(cfg.Server.Port))
53-
err = testutil.WaitForServerReady(serverURL, 3*time.Second)
53+
err = testutil.WaitForServerReady(t, serverURL, 3*time.Second)
5454
require.NoError(t, err, "Server should start within timeout")
5555

5656
// Establish actual HTTP connection to verify server is responding.

internal/server/server_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func TestServer_Start(t *testing.T) {
137137
}()
138138

139139
serverURL := "http://" + net.JoinHostPort(cfg.Server.Address, strconv.Itoa(cfg.Server.Port))
140-
err := testutil.WaitForServerReady(serverURL, 3*time.Second)
140+
err := testutil.WaitForServerReady(t, serverURL, 3*time.Second)
141141
require.NoError(t, err, "Server should start within timeout")
142142

143143
// Verify tools were registered.
@@ -184,7 +184,7 @@ func TestServer_HealthEndpoint(t *testing.T) {
184184
}()
185185

186186
serverURL := "http://" + net.JoinHostPort(cfg.Server.Address, strconv.Itoa(cfg.Server.Port))
187-
err := testutil.WaitForServerReady(serverURL, 3*time.Second)
187+
err := testutil.WaitForServerReady(t, serverURL, 3*time.Second)
188188
require.NoError(t, err, "Server should start within timeout")
189189

190190
// Test health endpoint.

internal/testutil/config_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package testutil
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
"testing"
7+
8+
"github.com/stretchr/testify/assert"
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
func TestWriteYAMLFile(t *testing.T) {
13+
content := "test: value\n"
14+
15+
path := WriteYAMLFile(t, content)
16+
17+
filename := filepath.Base(path)
18+
assert.Contains(t, filename, t.Name(), "Filename should contain test name")
19+
20+
info, err := os.Stat(path)
21+
require.NoError(t, err, "File should exist")
22+
assert.Equal(t, int64(len(content)), info.Size(), "File should not be empty")
23+
}

internal/testutil/server.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package testutil
33
import (
44
"fmt"
55
"net/http"
6+
"testing"
67
"time"
78
)
89

@@ -11,7 +12,9 @@ const timeoutDuration = 100 * time.Millisecond
1112
// WaitForServerReady polls the server until it's ready to accept connections.
1213
// This function is useful for integration tests where you need to wait for
1314
// a server to start before making requests to it.
14-
func WaitForServerReady(address string, timeout time.Duration) error {
15+
func WaitForServerReady(t *testing.T, address string, timeout time.Duration) error {
16+
t.Helper()
17+
1518
deadline := time.Now().Add(timeout)
1619
client := &http.Client{Timeout: timeoutDuration}
1720

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package mock
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stackrox/stackrox-mcp/internal/toolsets"
7+
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
func TestToolset_GetName(t *testing.T) {
12+
toolset := NewToolset("my-toolset", true, nil)
13+
14+
require.NotNil(t, toolset)
15+
assert.Equal(t, "my-toolset", toolset.GetName())
16+
}
17+
18+
func TestToolset_IsEnabled_True(t *testing.T) {
19+
tools := []toolsets.Tool{&Tool{NameValue: "test-tool"}}
20+
toolset := NewToolset("test", true, tools)
21+
22+
require.NotNil(t, toolset)
23+
assert.True(t, toolset.IsEnabled())
24+
assert.Equal(t, tools, toolset.GetTools(), "Should return tools when enabled")
25+
}
26+
27+
func TestToolset_IsEnabled_False(t *testing.T) {
28+
tools := []toolsets.Tool{&Tool{NameValue: "test-tool"}}
29+
toolset := NewToolset("test", false, tools)
30+
31+
require.NotNil(t, toolset)
32+
assert.False(t, toolset.IsEnabled())
33+
assert.Empty(t, toolset.GetTools(), "Should return empty slice when disabled")
34+
}

0 commit comments

Comments
 (0)