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

bavix / gripmock / 28320783112

28 Jun 2026 11:30AM UTC coverage: 71.667% (-0.6%) from 72.243%
28320783112

Pull #877

github

web-flow
Merge 03f99b8f3 into 2c3fde067
Pull Request #877: Connect server

472 of 882 new or added lines in 17 files covered. (53.51%)

39 existing lines in 3 files now uncovered.

12819 of 17887 relevant lines covered (71.67%)

130.73 hits per line

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

76.07
/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
        "github.com/bavix/gripmock/v3/internal/infra/build"
15
)
16

17
var (
18
        stubFlag    string   //nolint:gochecknoglobals
19
        importsFlag []string //nolint:gochecknoglobals
20
        pluginsFlag []string //nolint:gochecknoglobals
21
        sourceFlag  []string //nolint:gochecknoglobals
22
)
23

24
var rootCmd = &cobra.Command{ //nolint:gochecknoglobals
25
        Use:     "gripmock",
26
        Short:   "gRPC Mock Server",
27
        Version: build.Version + " (" + build.Commit + ") " + build.Date,
28
        Args:    cobra.ArbitraryArgs,
29
        RunE: func(cmd *cobra.Command, args []string) error {
1✔
30
                builder := deps.NewBuilder(
1✔
31
                        deps.WithDefaultConfig(),
1✔
32
                        deps.WithPlugins(pluginsFlag),
1✔
33
                )
1✔
34

1✔
35
                ctx, cancel := builder.SignalNotify(cmd.Context())
1✔
36
                defer cancel()
1✔
37

1✔
38
                ctx = builder.Logger(ctx)
1✔
39
                builder.InitTelemetry(ctx)
1✔
40
                builder.LoadPlugins(ctx)
1✔
41

1✔
42
                zerolog.Ctx(ctx).Info().
1✔
43
                        Str("release", build.Version).
1✔
44
                        Str("commit", build.Commit).
1✔
45
                        Str("date", build.Date).
1✔
46
                        Int("pid", os.Getpid()).
1✔
47
                        Msg("Starting GripMock")
1✔
48

1✔
49
                go func() {
2✔
50
                        defer func() {
2✔
51
                                if r := recover(); r != nil {
1✔
52
                                        zerolog.Ctx(ctx).
×
53
                                                Fatal().
×
54
                                                Interface("panic", r).
×
55
                                                Msg("Fatal panic in REST server goroutine - terminating server")
×
56
                                }
×
57
                        }()
58

59
                        if err := restServe(ctx, builder); err != nil {
1✔
60
                                zerolog.Ctx(ctx).Fatal().Err(err).Msg("Fatal error in REST server - terminating server")
×
61
                        }
×
62
                }()
63

64
                go func() {
2✔
65
                        defer func() {
2✔
66
                                if r := recover(); r != nil {
1✔
NEW
67
                                        zerolog.Ctx(ctx).
×
NEW
68
                                                Fatal().
×
NEW
69
                                                Interface("panic", r).
×
NEW
70
                                                Msg("Fatal panic in ConnectRPC server goroutine - terminating server")
×
NEW
71
                                }
×
72
                        }()
73

74
                        if err := builder.ConnectServe(ctx); err != nil {
1✔
NEW
75
                                zerolog.Ctx(ctx).Fatal().Err(err).Msg("Fatal error in ConnectRPC server - terminating server")
×
NEW
76
                        }
×
77
                }()
78

79
                defer builder.Shutdown(context.WithoutCancel(ctx))
1✔
80

1✔
81
                // Parse arguments with per-proxy source bindings
1✔
82
                // This uses raw os.Args to detect -S flag positioning relative to proxy URLs
1✔
83
                params := proto.ParseArgumentsWithBindings(args, importsFlag, sourceFlag)
1✔
84

1✔
85
                zerolog.Ctx(ctx).Info().
1✔
86
                        Strs("args", args).
1✔
87
                        Strs("sourceFlag", sourceFlag).
1✔
88
                        Msg("Starting GRPCServe")
1✔
89

1✔
90
                return builder.GRPCServe(ctx, params)
1✔
91
        },
92
}
93

94
func restServe(ctx context.Context, builder *deps.Builder) error {
1✔
95
        srv, err := builder.RestServe(ctx, stubFlag)
1✔
96
        if err != nil {
1✔
97
                return errors.Wrap(err, "failed to start rest server")
×
98
        }
×
99

100
        zerolog.Ctx(ctx).Info().Str("addr", srv.Addr()).Bool("tls", srv.TLSEnabled()).Msg("HTTP server is now running")
1✔
101

1✔
102
        ch := make(chan error)
1✔
103

1✔
104
        go func() {
2✔
105
                defer func() {
2✔
106
                        if r := recover(); r != nil {
1✔
107
                                zerolog.Ctx(ctx).
×
108
                                        Fatal().
×
109
                                        Interface("panic", r).
×
110
                                        Msg("Fatal panic in HTTP server goroutine - terminating server")
×
111
                        }
×
112
                }()
113
                defer close(ch)
1✔
114

1✔
115
                select {
1✔
116
                case <-ctx.Done():
1✔
117
                        if !errors.Is(ctx.Err(), context.Canceled) {
1✔
118
                                ch <- ctx.Err()
×
119
                        }
×
120

121
                        return
1✔
122
                case ch <- srv.ListenAndServe():
×
123
                        return
×
124
                }
125
        }()
126

127
        if err := <-ch; !errors.Is(err, http.ErrServerClosed) {
2✔
128
                return errors.Wrap(err, "http server failed")
1✔
129
        }
1✔
130

131
        return nil
×
132
}
133

134
func init() { //nolint:gochecknoinits
3✔
135
        rootCmd.PersistentFlags().StringVarP(
3✔
136
                &stubFlag,
3✔
137
                "stub",
3✔
138
                "s",
3✔
139
                "",
3✔
140
                "Path where the stub files are (Optional)")
3✔
141

3✔
142
        rootCmd.PersistentFlags().StringSliceVarP(
3✔
143
                &importsFlag,
3✔
144
                "imports",
3✔
145
                "i",
3✔
146
                []string{},
3✔
147
                "Path to import proto-libraries")
3✔
148

3✔
149
        rootCmd.PersistentFlags().StringSliceVar(
3✔
150
                &pluginsFlag,
3✔
151
                "plugins",
3✔
152
                []string{},
3✔
153
                "Template plugin paths (.so)")
3✔
154

3✔
155
        rootCmd.PersistentFlags().StringSliceVarP(
3✔
156
                &sourceFlag,
3✔
157
                "source",
3✔
158
                "S",
3✔
159
                []string{},
3✔
160
                "Local descriptor sources for proxy modes (.proto, .protoset, .pb, directory)")
3✔
161
}
3✔
162

163
// Execute runs the root command with the given context.
164
func Execute(ctx context.Context) {
2✔
165
        if err := rootCmd.ExecuteContext(ctx); err != nil {
2✔
166
                os.Exit(1)
×
167
        }
×
168
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc