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
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): client_ test.go
A [revision details]
M state/api/
Index: [revision details] 20140331192817- ytfa2vb3oz21cj4 e
=== 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-
+New revision: <email address hidden>
Index: state/api/ client_ test.go api/client_ test.go' client_ test.go 2014-03-13 07:54:56 +0000 client_ test.go 2014-04-01 04:30:11 +0000
=== modified file 'state/
--- state/api/
+++ state/api/
@@ -5,6 +5,7 @@
import (
"fmt"
+ "net"
"net/http"
jc "github. com/juju/ testing/ checkers" ).(*net. TCPAddr) .Port localhost:%d", port) HandleFunc( "/charms" , func(w http.ResponseWr iter, r *http.Request) { odNotAllowed) erve(": 8900", nil)
@@ -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(
+ url := fmt.Sprintf("http://
http.
if r.Method == "POST" {
http.Error(w, "Method Not Allowed", http.StatusMeth
}
})
go func() {
- err = http.ListenAndS
+ err = http.Serve(lis, nil)
c.Assert(err, gc.IsNil)
}()
- api.SetServerRo ot(client, "http:// localhost: 8900") ot(client, url) AddLocalCharm( curl, charmArchive) IsCodeNotImplem ented)
+ api.SetServerRo
_, err = client.
c.Assert(err, jc.Satisfies, params.
}