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

cybertec-postgresql / pg_timetable / 18127629475

30 Sep 2025 10:59AM UTC coverage: 84.299% (-1.9%) from 86.155%
18127629475

Pull #720

github

web-flow
Merge f545f91b2 into 61518f6b4
Pull Request #720: [!] add YAML-based chain definitions

196 of 204 new or added lines in 7 files covered. (96.08%)

62 existing lines in 4 files now uncovered.

1659 of 1968 relevant lines covered (84.3%)

0.97 hits per line

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

74.29
/internal/scheduler/shell.go
1
package scheduler
2

3
import (
4
        "context"
5
        "encoding/json"
6
        "errors"
7
        "fmt"
8
        "os/exec"
9
        "strings"
10
)
11

12
type commander interface {
13
        CombinedOutput(context.Context, string, ...string) ([]byte, error)
14
}
15

16
type realCommander struct{}
17

18
// CombinedOutput executes program command and returns combined stdout and stderr
UNCOV
19
func (c realCommander) CombinedOutput(ctx context.Context, command string, args ...string) ([]byte, error) {
×
UNCOV
20
        cmd := exec.CommandContext(ctx, command, args...)
×
UNCOV
21
        cmd.Stdin = nil
×
UNCOV
22
        return cmd.CombinedOutput()
×
UNCOV
23
}
×
24

25
// Cmd executes a command
26
var Cmd commander = realCommander{}
27

28
// ExecuteProgramCommand executes program command and returns status code, output and error if any
29
func (sch *Scheduler) ExecuteProgramCommand(ctx context.Context, command string, paramValues []string) (code int, stdout string, stderr error) {
1✔
30

1✔
31
        command = strings.TrimSpace(command)
1✔
32
        if command == "" {
2✔
33
                return -1, "", errors.New("program command cannot be empty")
1✔
34
        }
1✔
35
        if len(paramValues) == 0 { //mimic empty param
2✔
36
                paramValues = []string{""}
1✔
37
        }
1✔
38
        for _, val := range paramValues {
2✔
39
                params := []string{}
1✔
40
                if val > "" {
2✔
41
                        if err := json.Unmarshal([]byte(val), &params); err != nil {
2✔
42
                                return -1, "", err
1✔
43
                        }
1✔
44
                }
45
                out, err := Cmd.CombinedOutput(ctx, command, params...) // #nosec
1✔
46
                cmdLine := fmt.Sprintf("%s %v: ", command, params)
1✔
47
                stdout = strings.TrimSpace(string(out))
1✔
48
                l := sch.l.WithField("command", cmdLine).
1✔
49
                        WithField("output", string(out))
1✔
50
                if err != nil {
2✔
51
                        //check if we're dealing with an ExitError - i.e. return code other than 0
1✔
52
                        if exitError, ok := err.(*exec.ExitError); ok {
1✔
UNCOV
53
                                exitCode := exitError.ExitCode()
×
UNCOV
54
                                l.WithField("retcode", exitCode).Debug("Program run", cmdLine, exitCode)
×
UNCOV
55
                                return exitCode, stdout, exitError
×
UNCOV
56
                        }
×
57
                        return -1, stdout, err
1✔
58
                }
59
                l.WithField("retcode", 0).Debug("Program run")
1✔
60
        }
61
        return 0, stdout, nil
1✔
62
}
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