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

cybertec-postgresql / pgwatch3 / 10458886373

19 Aug 2024 06:27PM UTC coverage: 28.809% (+0.5%) from 28.289%
10458886373

Pull #504

github

web-flow
Merge 83d8f530f into 11ec15c1b
Pull Request #504: [!] add support for application commands

95 of 295 new or added lines in 17 files covered. (32.2%)

3 existing lines in 3 files now uncovered.

1335 of 4634 relevant lines covered (28.81%)

0.33 hits per line

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

76.19
/src/config/cmdsource.go
1
package config
2

3
import (
4
        "context"
5
        "errors"
6
        "fmt"
7

8
        "github.com/cybertec-postgresql/pgwatch3/sources"
9
)
10

11
type SourceCommand struct {
12
        owner *Options
13
        Ping  SourcePingCommand `command:"ping" description:"Try to connect to configured sources, report errors if any and then exit"`
14
        // PrintSQL  SourcePrintCommand `command:"print" description:"Get and print SQL for a given Source"`
15
}
16

17
func NewSourceCommand(owner *Options) *SourceCommand {
1✔
18
        return &SourceCommand{
1✔
19
                owner: owner,
1✔
20
                Ping:  SourcePingCommand{owner: owner},
1✔
21
        }
1✔
22
}
1✔
23

24
type SourcePingCommand struct {
25
        owner *Options
26
}
27

28
func (cmd *SourcePingCommand) Execute(args []string) error {
1✔
29
        err := cmd.owner.InitSourceReader(context.Background())
1✔
30
        if err != nil {
1✔
NEW
31
                return err
×
NEW
32
        }
×
33
        srcs, err := cmd.owner.SourcesReaderWriter.GetSources()
1✔
34
        if err != nil {
1✔
NEW
35
                return err
×
NEW
36
        }
×
37
        var foundSources sources.Sources
1✔
38
        if len(args) == 0 {
2✔
39
                foundSources = srcs
1✔
40
        } else {
2✔
41
                for _, name := range args {
2✔
42
                        for _, s := range srcs {
2✔
43
                                if s.Name == name {
2✔
44
                                        foundSources = append(foundSources, s)
1✔
45
                                }
1✔
46
                        }
47
                }
48
        }
49
        var e error
1✔
50
        for _, s := range foundSources {
2✔
51
                switch s.Kind {
1✔
NEW
52
                case sources.SourcePatroni, sources.SourcePatroniContinuous, sources.SourcePatroniNamespace:
×
NEW
53
                        _, e = sources.ResolveDatabasesFromPatroni(s)
×
NEW
54
                case sources.SourcePostgresContinuous:
×
NEW
55
                        _, e = sources.ResolveDatabasesFromPostgres(s)
×
56
                default:
1✔
57
                        mdb := &sources.MonitoredDatabase{Source: s}
1✔
58
                        e = mdb.Ping(context.Background())
1✔
59
                }
60
                if e != nil {
2✔
61
                        fmt.Printf("FAIL:\t%s (%s)\n", s.Name, e)
1✔
62
                } else {
1✔
NEW
63
                        fmt.Printf("OK:\t%s\n", s.Name)
×
NEW
64
                }
×
65
                err = errors.Join(err, e)
1✔
66
        }
67
        // err here specifies execution error, not configuration error
68
        // so we indicate it with a special exit code
69
        // but we still return nil to indicate that the command was executed
70
        cmd.owner.CompleteCommand(map[bool]int32{true: ExitCodeCmdError, false: ExitCodeOK}[err != nil])
1✔
71
        return nil
1✔
72
}
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