Code Review
/
ric-plt
/
vespamgr.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
More UT fixes
[ric-plt/vespamgr.git]
/
cmd
/
vesmgr
/
vesmgr_queryxappconfig_test.go
diff --git
a/cmd/vesmgr/vesmgr_queryxappconfig_test.go
b/cmd/vesmgr/vesmgr_queryxappconfig_test.go
old mode 100644
(file)
new mode 100755
(executable)
index
8cc3ad4
..
053adcc
--- a/
cmd/vesmgr/vesmgr_queryxappconfig_test.go
+++ b/
cmd/vesmgr/vesmgr_queryxappconfig_test.go
@@
-27,6
+27,7
@@
import (
"net/http"
"net/url"
"os"
"net/http"
"net/url"
"os"
+ "sync"
"testing"
"time"
"testing"
"time"
@@
-39,6
+40,7
@@
type QueryXAppsConfigTestSuite struct {
suite.Suite
listener net.Listener
xAppMgrFunc do
suite.Suite
listener net.Listener
xAppMgrFunc do
+ mu sync.Mutex
}
// suite setup creates the HTTP server
}
// suite setup creates the HTTP server
@@
-56,9
+58,12
@@
func runXAppMgr(listener net.Listener, url string, suite *QueryXAppsConfigTestSu
http.HandleFunc(url, func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "GET":
http.HandleFunc(url, func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "GET":
+ suite.mu.Lock()
+ defer suite.mu.Unlock()
suite.xAppMgrFunc(w)
}
})
suite.xAppMgrFunc(w)
}
})
+
http.Serve(listener, nil)
}
http.Serve(listener, nil)
}
@@
-66,7
+71,10
@@
func (suite *QueryXAppsConfigTestSuite) TestQueryXAppsConfigFailsWithTimeout() {
doSleep := func(w http.ResponseWriter) {
time.Sleep(time.Second * 2)
}
doSleep := func(w http.ResponseWriter) {
time.Sleep(time.Second * 2)
}
+
+ suite.mu.Lock()
suite.xAppMgrFunc = doSleep
suite.xAppMgrFunc = doSleep
+ suite.mu.Unlock()
data, err := queryXAppsConfig("http://"+suite.listener.Addr().String()+"/test_url/", 1)
suite.Equal([]byte("{}"), data)
data, err := queryXAppsConfig("http://"+suite.listener.Addr().String()+"/test_url/", 1)
suite.Equal([]byte("{}"), data)
@@
-80,7
+88,10
@@
func (suite *QueryXAppsConfigTestSuite) TestQueryXAppsConfigFailsWithAnErrorRepl
doReplyWithErr := func(w http.ResponseWriter) {
http.Error(w, "405 method not allowed", http.StatusMethodNotAllowed)
}
doReplyWithErr := func(w http.ResponseWriter) {
http.Error(w, "405 method not allowed", http.StatusMethodNotAllowed)
}
+
+ suite.mu.Lock()
suite.xAppMgrFunc = doReplyWithErr
suite.xAppMgrFunc = doReplyWithErr
+ suite.mu.Unlock()
data, err := queryXAppsConfig("http://"+suite.listener.Addr().String()+"/test_url/", 1)
suite.Equal([]byte("{}"), data)
data, err := queryXAppsConfig("http://"+suite.listener.Addr().String()+"/test_url/", 1)
suite.Equal([]byte("{}"), data)
@@
-92,7
+103,10
@@
func (suite *QueryXAppsConfigTestSuite) TestQueryXAppsConfigOk() {
doReply := func(w http.ResponseWriter) {
fmt.Fprintf(w, "reply message")
}
doReply := func(w http.ResponseWriter) {
fmt.Fprintf(w, "reply message")
}
+
+ suite.mu.Lock()
suite.xAppMgrFunc = doReply
suite.xAppMgrFunc = doReply
+ suite.mu.Unlock()
data, err := queryXAppsConfig("http://"+suite.listener.Addr().String()+"/test_url/", 1)
suite.NotNil(data)
data, err := queryXAppsConfig("http://"+suite.listener.Addr().String()+"/test_url/", 1)
suite.NotNil(data)