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

bavix / gripmock / 17066567963

19 Aug 2025 10:15AM UTC coverage: 52.632% (-0.9%) from 53.531%
17066567963

push

github

web-flow
Merge pull request #653 from bavix/652-field-outputheaders-not-being-sent-as-trailers-if-outputcode-0

Fix Trailers

78 of 190 new or added lines in 8 files covered. (41.05%)

7 existing lines in 1 file now uncovered.

1590 of 3021 relevant lines covered (52.63%)

30.19 hits per line

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

72.0
/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
                        defer func() {
2✔
40
                                if r := recover(); r != nil {
1✔
NEW
41
                                        zerolog.Ctx(ctx).
×
NEW
42
                                                Fatal().
×
NEW
43
                                                Interface("panic", r).
×
NEW
44
                                                Msg("Fatal panic in REST server goroutine - terminating server")
×
NEW
45
                                }
×
46
                        }()
47
                        if err := restServe(ctx, builder); err != nil {
1✔
NEW
48
                                zerolog.Ctx(ctx).Fatal().Err(err).Msg("Fatal error in REST server - terminating server")
×
49
                        }
×
50
                }()
51

52
                defer builder.Shutdown(context.WithoutCancel(ctx))
1✔
53

1✔
54
                return builder.GRPCServe(ctx, proto.New(args, importsFlag))
1✔
55
        },
56
}
57

58
func restServe(ctx context.Context, builder *deps.Builder) error {
1✔
59
        srv, err := builder.RestServe(ctx, stubFlag)
1✔
60
        if err != nil {
1✔
61
                return errors.Wrap(err, "failed to start rest server")
×
62
        }
×
63

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

1✔
66
        ch := make(chan error)
1✔
67

1✔
68
        go func() {
2✔
69
                defer func() {
2✔
70
                        if r := recover(); r != nil {
1✔
NEW
71
                                zerolog.Ctx(ctx).
×
NEW
72
                                        Fatal().
×
NEW
73
                                        Interface("panic", r).
×
NEW
74
                                        Msg("Fatal panic in HTTP server goroutine - terminating server")
×
NEW
75
                        }
×
76
                }()
77
                defer close(ch)
1✔
78

1✔
79
                select {
1✔
80
                case <-ctx.Done():
1✔
81
                        if !errors.Is(ctx.Err(), context.Canceled) {
1✔
82
                                ch <- ctx.Err()
×
83
                        }
×
84

85
                        return
1✔
86
                case ch <- srv.ListenAndServe():
×
87
                        return
×
88
                }
89
        }()
90

91
        if err := <-ch; !errors.Is(err, http.ErrServerClosed) {
2✔
92
                return errors.Wrap(err, "http server failed")
1✔
93
        }
1✔
94

95
        return nil
×
96
}
97

98
func init() { //nolint:gochecknoinits
2✔
99
        rootCmd.Flags().StringVarP(
2✔
100
                &stubFlag,
2✔
101
                "stub",
2✔
102
                "s",
2✔
103
                "",
2✔
104
                "Path where the stub files are (Optional)")
2✔
105

2✔
106
        rootCmd.Flags().StringSliceVarP(
2✔
107
                &importsFlag,
2✔
108
                "imports",
2✔
109
                "i",
2✔
110
                []string{},
2✔
111
                "Path to import proto-libraries")
2✔
112
}
2✔
113

114
// Execute runs the root command with the given context.
115
func Execute(ctx context.Context) {
2✔
116
        if err := rootCmd.ExecuteContext(ctx); err != nil {
2✔
117
                os.Exit(1)
×
118
        }
×
119
}
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