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

bavix / gripmock / 16916245200

12 Aug 2025 05:30PM UTC coverage: 51.846% (-0.07%) from 51.92%
16916245200

push

github

web-flow
Merge pull request #635 from bavix/dependabot/github_actions/actions/download-artifact-5

Bump actions/download-artifact from 4 to 5

1418 of 2735 relevant lines covered (51.85%)

23.8 hits per line

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

78.69
/cmd/root.go
1
package cmd
2

3
import (
4
        "context"
5
        "net/http"
6
        "os"
7

8
        "github.com/cockroachdb/errors"
9
        "github.com/rs/zerolog"
10
        "github.com/spf13/cobra"
11

12
        "github.com/bavix/gripmock/v3/internal/deps"
13
        "github.com/bavix/gripmock/v3/internal/domain/proto"
14
)
15

16
var (
17
        stubFlag    string   //nolint:gochecknoglobals
18
        importsFlag []string //nolint:gochecknoglobals
19
        version     = "development"
20
)
21

22
var rootCmd = &cobra.Command{ //nolint:gochecknoglobals
23
        Use:     "gripmock",
24
        Short:   "gRPC Mock Server",
25
        Version: version,
26
        Args:    cobra.MinimumNArgs(1),
27
        RunE: func(cmd *cobra.Command, args []string) error {
1✔
28
                builder := deps.NewBuilder(deps.WithDefaultConfig())
1✔
29
                ctx, cancel := builder.SignalNotify(cmd.Context())
1✔
30
                defer cancel()
1✔
31

1✔
32
                ctx = builder.Logger(ctx)
1✔
33

1✔
34
                zerolog.Ctx(ctx).Info().
1✔
35
                        Str("release", version).
1✔
36
                        Msg("Starting GripMock")
1✔
37

1✔
38
                go func() {
2✔
39
                        if err := restServe(ctx, builder); err != nil {
1✔
40
                                zerolog.Ctx(ctx).Err(err).Msg("Failed to start rest server")
×
41
                        }
×
42
                }()
43

44
                defer builder.Shutdown(context.WithoutCancel(ctx))
1✔
45

1✔
46
                return builder.GRPCServe(ctx, proto.New(args, importsFlag))
1✔
47
        },
48
}
49

50
func restServe(ctx context.Context, builder *deps.Builder) error {
1✔
51
        srv, err := builder.RestServe(ctx, stubFlag)
1✔
52
        if err != nil {
1✔
53
                return errors.Wrap(err, "failed to start rest server")
×
54
        }
×
55

56
        zerolog.Ctx(ctx).Info().Str("addr", srv.Addr).Msg("HTTP server is now running")
1✔
57

1✔
58
        ch := make(chan error)
1✔
59

1✔
60
        go func() {
2✔
61
                defer close(ch)
1✔
62

1✔
63
                select {
1✔
64
                case <-ctx.Done():
×
65
                        if !errors.Is(ctx.Err(), context.Canceled) {
×
66
                                ch <- ctx.Err()
×
67
                        }
×
68

69
                        return
×
70
                case ch <- srv.ListenAndServe():
1✔
71
                        return
1✔
72
                }
73
        }()
74

75
        if err := <-ch; !errors.Is(err, http.ErrServerClosed) {
1✔
76
                return errors.Wrap(err, "http server failed")
×
77
        }
×
78

79
        return nil
1✔
80
}
81

82
func init() { //nolint:gochecknoinits
2✔
83
        rootCmd.Flags().StringVarP(
2✔
84
                &stubFlag,
2✔
85
                "stub",
2✔
86
                "s",
2✔
87
                "",
2✔
88
                "Path where the stub files are (Optional)")
2✔
89

2✔
90
        rootCmd.Flags().StringSliceVarP(
2✔
91
                &importsFlag,
2✔
92
                "imports",
2✔
93
                "i",
2✔
94
                []string{},
2✔
95
                "Path to import proto-libraries")
2✔
96
}
2✔
97

98
// Execute runs the root command with the given context.
99
func Execute(ctx context.Context) {
2✔
100
        if err := rootCmd.ExecuteContext(ctx); err != nil {
2✔
101
                os.Exit(1)
×
102
        }
×
103
}
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