Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,16 @@ linters:

forbidigo:
forbid:
# General rule - applies everywhere (pkg: all preserves original behavior)
- pkg: all
pattern: ^(fmt\.Print(|f|ln)|print|println)$
pattern: '^(fmt\.Print(|f|ln)|print|println)$'
# Test-specific rules (scoped to test files via exclusions below)
- pattern: '^os\.MkdirTemp$'
msg: "use t.TempDir() instead of os.MkdirTemp() in tests"
- pattern: '^os\.Setenv$'
msg: "use t.Setenv() instead of os.Setenv() in tests"
- pattern: '^context\.(Background|TODO)$'
msg: "use t.Context() instead of context.Background()/context.TODO() in tests"
analyze-types: true

gocritic:
Expand Down Expand Up @@ -221,6 +229,11 @@ linters:
linters:
- staticcheck
text: "SA5011"
# Exclude test-specific forbidigo rules from non-test files
- path-except: '_test\.go$'
linters:
- forbidigo
text: 'use t\.'

issues:
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
Expand Down
8 changes: 4 additions & 4 deletions cmd/cli/commands/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func generateReferenceTestCases(info modelInfo) []referenceTestCase {

// setupTestEnv creates the complete test environment with registry and DMR
func setupTestEnv(t *testing.T) *testEnv {
ctx := context.Background()
ctx := t.Context()

// Set environment variables for the test process to match the DMR container.
// This ensures CLI functions use the same default registry when parsing references.
Expand Down Expand Up @@ -142,7 +142,7 @@ func setupTestEnv(t *testing.T) *testEnv {

func ociRegistry(t *testing.T, ctx context.Context, net *testcontainers.DockerNetwork) string {
t.Log("Starting OCI registry container...")
ctr, err := tc.Run(context.Background(), "registry:3",
ctr, err := tc.Run(t.Context(), "registry:3",
network.WithNetwork([]string{"registry.local"}, net),
)
require.NoError(t, err)
Expand Down Expand Up @@ -251,7 +251,7 @@ func verifyModelInspect(t *testing.T, client *desktop.Client, ref, expectedID, e
// createAndPushTestModel creates a minimal test model and pushes it to the local registry.
// Returns the model ID, FQDNs for host and network access, and the manifest digest.
func createAndPushTestModel(t *testing.T, registryURL, modelRef string, contextSize *int32) (modelID, hostFQDN, networkFQDN, digest string) {
ctx := context.Background()
ctx := t.Context()

// Use the dummy GGUF file from assets
dummyGGUFPath := filepath.Join("../../../assets/dummy.gguf")
Expand Down Expand Up @@ -1157,7 +1157,7 @@ func int32ptr(n int32) *int32 {
// the real Docker Hub (index.docker.io) as the default registry.
// This is used to test that pulling from Docker Hub works correctly.
func setupDockerHubTestEnv(t *testing.T) *testEnv {
ctx := context.Background()
ctx := t.Context()

// Create a custom network for container communication
net, err := network.New(ctx)
Expand Down
5 changes: 1 addition & 4 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"os"
"testing"

"github.com/docker/model-runner/pkg/inference/backends/llamacpp"
Expand Down Expand Up @@ -58,10 +57,8 @@ func TestCreateLlamaCppConfigFromEnv(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Set up environment
if tt.llamaArgs != "" {
os.Setenv("LLAMA_ARGS", tt.llamaArgs)
defer os.Unsetenv("LLAMA_ARGS")
t.Setenv("LLAMA_ARGS", tt.llamaArgs)
}

// Create a test logger that captures fatal errors
Expand Down
Loading
Loading