From ef33b719253e716cbc1603ca70d13ae9a05d0690 Mon Sep 17 00:00:00 2001 From: Matt Fellows Date: Sat, 11 Jun 2016 08:12:35 +1000 Subject: [PATCH] refactor(daemon): cleanup pointer usage in daemon code --- daemon/daemon.go | 22 +++++++++++----------- daemon/daemon_test.go | 18 +++++++++--------- dsl/client.go | 2 +- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/daemon/daemon.go b/daemon/daemon.go index 29df57e60..65d7a86c0 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -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() @@ -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 { @@ -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) @@ -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(), } @@ -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()), } @@ -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 @@ -142,7 +142,7 @@ func (d *Daemon) ListServers(request types.PactMockServer, reply *types.PactList }) } - *reply = *&types.PactListResponse{ + *reply = types.PactListResponse{ Servers: servers, } @@ -150,7 +150,7 @@ func (d *Daemon) ListServers(request types.PactMockServer, reply *types.PactList } // 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 { @@ -158,7 +158,7 @@ func (d *Daemon) StopServer(request *types.PactMockServer, reply *types.PactMock } else { request.Status = 1 } - *reply = *request + *reply = request return nil } diff --git a/daemon/daemon_test.go b/daemon/daemon_test.go index dd9c1e167..7c8174946 100644 --- a/daemon/daemon_test.go +++ b/daemon/daemon_test.go @@ -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) } @@ -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) } @@ -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) } @@ -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) @@ -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) @@ -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) @@ -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) } @@ -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) } @@ -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) } diff --git a/dsl/client.go b/dsl/client.go index 613f22f83..df10142b0 100644 --- a/dsl/client.go +++ b/dsl/client.go @@ -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