• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pact-foundation / pact-go / 18960722150

31 Oct 2025 02:20AM UTC coverage: 30.702% (+2.4%) from 28.272%
18960722150

Pull #455

github

YOU54F
chore: make the linter happy
Pull Request #455: Feat/purego

386 of 514 new or added lines in 8 files covered. (75.1%)

3 existing lines in 2 files now uncovered.

2003 of 6524 relevant lines covered (30.7%)

16.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

6.52
/command/test.go
1
package command
2

3
import (
4
        "log"
5
        "os"
6
        "os/exec"
7
        "syscall"
8

9
        "github.com/pact-foundation/pact-go/v2/installer"
10
        "github.com/spf13/cobra"
11
)
12

13
var testCmd = &cobra.Command{
14
        Use:                "test",
15
        Short:              "Run go test with Pact library path configured",
16
        Long:               "Wrapper for 'go test' that sets PACT_LD_LIBRARY_PATH to the configured library directory",
17
        DisableFlagParsing: true,
NEW
18
        Run: func(cmd *cobra.Command, args []string) {
×
NEW
19
                setLogLevel(verbose, logLevel)
×
NEW
20

×
NEW
21
                // Get the configured library directory
×
NEW
22
                libDir := installer.GetConfigLibDir()
×
NEW
23
                if libDir == "" {
×
NEW
24
                        log.Println("[WARN] No library directory configured. Run 'pact-go install -d <path>' to set one.")
×
NEW
25
                        // check PACT_LD_LIBRARY_PATH env var
×
NEW
26
                        if envLibDir := os.Getenv("PACT_LD_LIBRARY_PATH"); envLibDir != "" {
×
NEW
27
                                libDir = envLibDir
×
NEW
28
                                log.Printf("[INFO] Using PACT_LD_LIBRARY_PATH from environment: %s", libDir)
×
NEW
29
                        } else {
×
NEW
30
                                log.Println("[ERROR] No library directory configured and PACT_LD_LIBRARY_PATH is not set. Cannot run tests.")
×
NEW
31
                                os.Exit(1)
×
NEW
32
                        }
×
33
                }
34

35
                // Set the PACT_LD_LIBRARY_PATH environment variable
NEW
36
                err := os.Setenv("PACT_LD_LIBRARY_PATH", libDir)
×
NEW
37
                if err != nil {
×
NEW
38
                        log.Printf("[ERROR] Failed to set PACT_LD_LIBRARY_PATH: %v", err)
×
NEW
39
                        os.Exit(1)
×
NEW
40
                }
×
41

NEW
42
                log.Printf("[INFO] Running go test with PACT_LD_LIBRARY_PATH=%s", libDir)
×
NEW
43

×
NEW
44
                // Prepare the go test command
×
NEW
45
                goTestArgs := append([]string{"test"}, args...)
×
NEW
46
                goCmd := exec.Command("go", goTestArgs...)
×
NEW
47

×
NEW
48
                // Pass through environment variables
×
NEW
49
                goCmd.Env = os.Environ()
×
NEW
50

×
NEW
51
                // Set up stdout, stderr, and stdin
×
NEW
52
                goCmd.Stdout = os.Stdout
×
NEW
53
                goCmd.Stderr = os.Stderr
×
NEW
54
                goCmd.Stdin = os.Stdin
×
NEW
55

×
NEW
56
                // Execute the command and exit with the same exit code
×
NEW
57
                if err := goCmd.Run(); err != nil {
×
NEW
58
                        if exitError, ok := err.(*exec.ExitError); ok {
×
NEW
59
                                // Exit with the same code as go test
×
NEW
60
                                if status, ok := exitError.Sys().(syscall.WaitStatus); ok {
×
NEW
61
                                        os.Exit(status.ExitStatus())
×
NEW
62
                                }
×
63
                        }
NEW
64
                        log.Printf("[ERROR] Failed to run go test: %v", err)
×
NEW
65
                        os.Exit(1)
×
66
                }
67
        },
68
}
69

70
func init() {
12✔
71
        RootCmd.AddCommand(testCmd)
12✔
72
}
12✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc