Code review comment for lp:~thumper/juju-core/client-test-no-fixed-port

Revision history for this message
Tim Penhey (thumper) wrote :

Reviewers: mp+213582_code.launchpad.net,

Message:
Please take a look.

Description:
Make the test not use a fixed port.

Simple change to avoid a fixed port in the test.

https://code.launchpad.net/~thumper/juju-core/client-test-no-fixed-port/+merge/213582

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/82940044/

Affected files (+9, -2 lines):
   A [revision details]
   M state/api/client_test.go

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-20140331192817-ytfa2vb3oz21cj4e
+New revision: <email address hidden>

Index: state/api/client_test.go
=== modified file 'state/api/client_test.go'
--- state/api/client_test.go 2014-03-13 07:54:56 +0000
+++ state/api/client_test.go 2014-04-01 04:30:11 +0000
@@ -5,6 +5,7 @@

  import (
   "fmt"
+ "net"
   "net/http"

   jc "github.com/juju/testing/checkers"
@@ -65,17 +66,21 @@
   // Finally, try the NotImplementedError by mocking the server
   // address to a handler that returns 405 Method Not Allowed for
   // POST.
+ lis, err := net.Listen("tcp", ":0")
+ c.Assert(err, gc.IsNil)
+ port := lis.Addr().(*net.TCPAddr).Port
+ url := fmt.Sprintf("http://localhost:%d", port)
   http.HandleFunc("/charms", func(w http.ResponseWriter, r *http.Request) {
    if r.Method == "POST" {
     http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed)
    }
   })
   go func() {
- err = http.ListenAndServe(":8900", nil)
+ err = http.Serve(lis, nil)
    c.Assert(err, gc.IsNil)
   }()

- api.SetServerRoot(client, "http://localhost:8900")
+ api.SetServerRoot(client, url)
   _, err = client.AddLocalCharm(curl, charmArchive)
   c.Assert(err, jc.Satisfies, params.IsCodeNotImplemented)
  }

« Back to merge proposal