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

salsadigitalauorg / shipshape / 13157284528

05 Feb 2025 12:23PM UTC coverage: 61.165% (+0.6%) from 60.56%
13157284528

Pull #71

github

yusufhm
[DEVOPS-158] Added more doc pages.

- Started a guide on connections.
- Added a connection example.
- Added stub pages for other sections.
- Added a file for analyse common fields.
- Started adding some details for `allowed:list`.
Pull Request #71: [DEVOPS-158] Implement required value(s)

111 of 156 new or added lines in 11 files covered. (71.15%)

1 existing line in 1 file now uncovered.

3361 of 5495 relevant lines covered (61.16%)

5.01 hits per line

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

76.0
/pkg/command/command.go
1
// Package command provides an interface and implementations for shell commands
2
// which allow for easy testing and mocking.
3
//
4
// It follows the instructions at https://stackoverflow.com/a/74671137/351590
5
// and https://github.com/schollii/go-test-mock-exec-command which makes use
6
// of polymorphism to achieve proper testing and mocking.
7
package command
8

9
import (
10
        "errors"
11
        "io/fs"
12
        "os/exec"
13

14
        log "github.com/sirupsen/logrus"
15
)
16

17
// IShellCommand is an interface for running shell commands.
18
type IShellCommand interface {
19
        Output() ([]byte, error)
20
}
21

22
// ExecShellCommand implements IShellCommand.
23
type ExecShellCommand struct {
24
        *exec.Cmd
25
}
26

27
// NewExecShellCommander returns a command instance.
28
func NewExecShellCommander(name string, arg ...string) IShellCommand {
1✔
29
        execCmd := exec.Command(name, arg...)
1✔
30
        return &ExecShellCommand{Cmd: execCmd}
1✔
31
}
1✔
32

33
func (c *ExecShellCommand) Output() ([]byte, error) {
×
34
        log.WithField("command", c).Debug("running command")
×
35
        return c.Cmd.Output()
×
36
}
×
37

38
// ShellCommander provides a wrapper around the commander to allow for better
39
// testing and mocking.
40
var ShellCommander = NewExecShellCommander
41

42
// GetMsgFromCommandError attempts to extract the error message from a command
43
// run's stderr.
44
func GetMsgFromCommandError(err error) string {
3✔
45
        var pathErr *fs.PathError
3✔
46
        var exitErr *exec.ExitError
3✔
47
        var errMsg string
3✔
48
        if errors.As(err, &pathErr) {
4✔
49
                errMsg = pathErr.Path + ": " + pathErr.Err.Error()
1✔
50
        } else if errors.As(err, &exitErr) {
4✔
51
                stderr := string(exitErr.Stderr)
1✔
52
                if stderr != "" {
2✔
53
                        errMsg = string(exitErr.Error()) + ": " + string(exitErr.Stderr)
1✔
54
                } else {
1✔
NEW
55
                        errMsg = string(exitErr.Error())
×
NEW
56
                }
×
57
        } else {
1✔
58
                errMsg = err.Error()
1✔
59
        }
1✔
60
        return errMsg
3✔
61
}
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

© 2026 Coveralls, Inc