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

cybertec-postgresql / pgwatch3 / 10456355969

19 Aug 2024 03:31PM UTC coverage: 27.846% (-0.4%) from 28.289%
10456355969

Pull #504

github

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

48 of 262 new or added lines in 17 files covered. (18.32%)

10 existing lines in 2 files now uncovered.

1284 of 4611 relevant lines covered (27.85%)

0.31 hits per line

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

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

3
import (
4
        "context"
5
        "fmt"
6
        "os"
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

NEW
28
func (cmd *SourcePingCommand) Execute(args []string) error {
×
NEW
29
        err := cmd.owner.InitSourceReader(context.Background())
×
NEW
30
        if err != nil {
×
NEW
31
                return err
×
NEW
32
        }
×
NEW
33
        srcs, err := cmd.owner.SourcesReaderWriter.GetSources()
×
NEW
34
        if err != nil {
×
NEW
35
                return err
×
NEW
36
        }
×
NEW
37
        var foundSources sources.Sources
×
NEW
38
        if len(args) == 0 {
×
NEW
39
                foundSources = srcs
×
NEW
40
        } else {
×
NEW
41
                for _, name := range args {
×
NEW
42
                        for _, s := range srcs {
×
NEW
43
                                if s.Name == name {
×
NEW
44
                                        foundSources = append(foundSources, s)
×
NEW
45
                                }
×
46
                        }
47
                }
48
        }
NEW
49
        var e error
×
NEW
50
        for _, s := range foundSources {
×
NEW
51
                switch s.Kind {
×
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)
×
NEW
56
                default:
×
NEW
57
                        mdb := &sources.MonitoredDatabase{Source: s}
×
NEW
58
                        e = mdb.Connect(context.Background())
×
59
                }
NEW
60
                if e != nil {
×
NEW
61
                        fmt.Printf("FAIL:\t%s (%s)\n", s.Name, e)
×
NEW
62
                } else {
×
NEW
63
                        fmt.Printf("OK:\t%s\n", s.Name)
×
NEW
64
                }
×
65
        }
66

NEW
67
        os.Exit(map[bool]int{true: int(ExitCodeOK), false: int(ExitCodeCmdError)}[e == nil])
×
NEW
68
        return nil
×
69
}
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