-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert http-server output into a mock server
- Loading branch information
Showing
12 changed files
with
1,029 additions
and
332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Licensed to Elasticsearch B.V. under one or more agreements. | ||
// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
package command | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"go.uber.org/zap" | ||
|
||
"github.com/elastic/stream/pkg/httpserver" | ||
) | ||
|
||
type httpServerRunner struct { | ||
logger *zap.SugaredLogger | ||
cmd *cobra.Command | ||
opts *httpserver.Options | ||
} | ||
|
||
func newHTTPServerRunner(options *httpserver.Options, logger *zap.Logger) *cobra.Command { | ||
r := &httpServerRunner{ | ||
opts: options, | ||
cmd: &cobra.Command{ | ||
Use: "http-server [options]", | ||
Short: "Set up a mock http server", | ||
}, | ||
} | ||
|
||
r.cmd.RunE = func(_ *cobra.Command, args []string) error { | ||
r.logger = logger.Sugar().With("address", options.Addr) | ||
return r.Run() | ||
} | ||
|
||
return r.cmd | ||
} | ||
|
||
func (r *httpServerRunner) Run() error { | ||
r.logger.Debug("mock server running...") | ||
server, err := httpserver.New(r.opts, r.logger) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := server.Start(r.cmd.Context()); err != nil { | ||
return err | ||
} | ||
|
||
<-r.cmd.Context().Done() | ||
|
||
return server.Close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.