Skip to content

Commit

Permalink
refactor(daemon): cleanup pointer usage in daemon code
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Jun 10, 2016
1 parent 6a9ea3d commit ef33b71
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
22 changes: 11 additions & 11 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func NewDaemon(pactMockServiceManager Service, verificationServiceManager Servic
}

// StartDaemon starts the daemon RPC server.
func (d *Daemon) StartDaemon(port int) {
func (d Daemon) StartDaemon(port int) {
log.Println("[INFO] daemon - starting daemon on port", port)

serv := rpc.NewServer()
Expand Down Expand Up @@ -69,14 +69,14 @@ func (d *Daemon) StartDaemon(port int) {

// StopDaemon allows clients to programmatically shuts down the running Daemon
// via RPC.
func (d *Daemon) StopDaemon(request string, reply *string) error {
func (d Daemon) StopDaemon(request string, reply *string) error {
log.Println("[DEBUG] daemon - stop daemon")
d.signalChan <- os.Interrupt
return nil
}

// Shutdown ensures all services are cleanly destroyed.
func (d *Daemon) Shutdown() {
func (d Daemon) Shutdown() {
log.Println("[DEBUG] daemon - shutdown")
for _, s := range d.verificationSvcManager.List() {
if s != nil {
Expand All @@ -87,7 +87,7 @@ func (d *Daemon) Shutdown() {

// StartServer starts a mock server and returns a pointer to atypes.PactMockServer
// struct.
func (d *Daemon) StartServer(request *types.PactMockServer, reply *types.PactMockServer) error {
func (d Daemon) StartServer(request types.PactMockServer, reply *types.PactMockServer) error {
log.Println("[DEBUG] daemon - starting mock server")
server := &types.PactMockServer{}
port, svc := d.pactMockSvcManager.NewService(request.Args)
Expand All @@ -100,14 +100,14 @@ func (d *Daemon) StartServer(request *types.PactMockServer, reply *types.PactMoc
}

// VerifyProvider runs the Pact Provider Verification Process.
func (d *Daemon) VerifyProvider(request *types.VerifyRequest, reply *types.CommandResponse) error {
func (d Daemon) VerifyProvider(request types.VerifyRequest, reply *types.CommandResponse) error {
log.Println("[DEBUG] daemon - verifying provider")
exitCode := 1

// Convert request into flags, and validate request
err := request.Validate()
if err != nil {
*reply = *&types.CommandResponse{
*reply = types.CommandResponse{
ExitCode: exitCode,
Message: err.Error(),
}
Expand All @@ -122,7 +122,7 @@ func (d *Daemon) VerifyProvider(request *types.VerifyRequest, reply *types.Comma
exitCode = 0
}

*reply = *&types.CommandResponse{
*reply = types.CommandResponse{
ExitCode: exitCode,
Message: string(out.Bytes()),
}
Expand All @@ -131,7 +131,7 @@ func (d *Daemon) VerifyProvider(request *types.VerifyRequest, reply *types.Comma
}

// ListServers returns a slice of all running types.PactMockServers.
func (d *Daemon) ListServers(request types.PactMockServer, reply *types.PactListResponse) error {
func (d Daemon) ListServers(request types.PactMockServer, reply *types.PactListResponse) error {
log.Println("[DEBUG] daemon - listing mock servers")
var servers []*types.PactMockServer

Expand All @@ -142,23 +142,23 @@ func (d *Daemon) ListServers(request types.PactMockServer, reply *types.PactList
})
}

*reply = *&types.PactListResponse{
*reply = types.PactListResponse{
Servers: servers,
}

return nil
}

// StopServer stops the given mock server.
func (d *Daemon) StopServer(request *types.PactMockServer, reply *types.PactMockServer) error {
func (d Daemon) StopServer(request types.PactMockServer, reply *types.PactMockServer) error {
log.Println("[DEBUG] daemon - stopping mock server")
success, err := d.pactMockSvcManager.Stop(request.Pid)
if success == true && err == nil {
request.Status = 0
} else {
request.Status = 1
}
*reply = *request
*reply = request

return nil
}
18 changes: 9 additions & 9 deletions daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func TestStartServer(t *testing.T) {

req := types.PactMockServer{Pid: 1234}
res := types.PactMockServer{}
err := daemon.StartServer(&req, &res)
err := daemon.StartServer(req, &res)
if err != nil {
t.Fatalf("Error: %v", err)
}
Expand Down Expand Up @@ -187,7 +187,7 @@ func TestStopServer(t *testing.T) {
Pid: cmd.Process.Pid,
}

err := daemon.StopServer(&request, &res)
err := daemon.StopServer(request, &res)
if err != nil {
t.Fatalf("Error: %v", err)
}
Expand Down Expand Up @@ -215,7 +215,7 @@ func TestStopServer_Fail(t *testing.T) {

manager.ServiceStopError = errors.New("failed to stop server")

err := daemon.StopServer(&request, &res)
err := daemon.StopServer(request, &res)
if err != nil {
t.Fatalf("Error: %v", err)
}
Expand All @@ -235,7 +235,7 @@ func TestStopServer_FailedStatus(t *testing.T) {

manager.ServiceStopResult = false

daemon.StopServer(&request, &res)
daemon.StopServer(request, &res)

if res.Status != 1 {
t.Fatalf("Expected exit status to be 1 but got: %d", res.Status)
Expand All @@ -247,7 +247,7 @@ func TestVerifyProvider_MissingProviderBaseURL(t *testing.T) {

req := types.VerifyRequest{}
res := types.CommandResponse{}
err := daemon.VerifyProvider(&req, &res)
err := daemon.VerifyProvider(req, &res)

if err != nil {
t.Fatalf("Error: %v", err)
Expand All @@ -268,7 +268,7 @@ func TestVerifyProvider_MissingPactURLs(t *testing.T) {
ProviderBaseURL: "http://foo.com",
}
res := types.CommandResponse{}
err := daemon.VerifyProvider(&req, &res)
err := daemon.VerifyProvider(req, &res)

if err != nil {
t.Fatalf("Error: %v", err)
Expand All @@ -290,7 +290,7 @@ func TestVerifyProvider_Valid(t *testing.T) {
PactURLs: []string{"foo.json", "bar.json"},
}
res := types.CommandResponse{}
err := daemon.VerifyProvider(&req, &res)
err := daemon.VerifyProvider(req, &res)
if err != nil {
t.Fatalf("Error: %v", err)
}
Expand All @@ -304,7 +304,7 @@ func TestVerifyProvider_FailedCommand(t *testing.T) {
PactURLs: []string{"foo.json", "bar.json"},
}
res := types.CommandResponse{}
err := daemon.VerifyProvider(&req, &res)
err := daemon.VerifyProvider(req, &res)
if err != nil {
t.Fatalf("Error: %v", err)
}
Expand All @@ -329,7 +329,7 @@ func TestVerifyProvider_ValidProviderStates(t *testing.T) {
ProviderStatesSetupURL: "http://foo/states/setup",
}
res := types.CommandResponse{}
err := daemon.VerifyProvider(&req, &res)
err := daemon.VerifyProvider(req, &res)
if err != nil {
t.Fatalf("Error: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion dsl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (p *PactClient) VerifyProvider(request *types.VerifyRequest) *types.Command
return &res
}

// ListServers starts a remote Pact Mock Server.
// ListServers lists all running Pact Mock Servers.
func (p *PactClient) ListServers() *types.PactListResponse {
log.Println("[DEBUG] client: listing servers")
var res types.PactListResponse
Expand Down

0 comments on commit ef33b71

Please sign in to comment.