"net/http"
"net/url"
"os"
+ "sync"
"testing"
"time"
suite.Suite
listener net.Listener
xAppMgrFunc do
+ mu sync.Mutex
}
// suite setup creates the HTTP server
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)
}
})
+
http.Serve(listener, nil)
}
doSleep := func(w http.ResponseWriter) {
time.Sleep(time.Second * 2)
}
+
+ suite.mu.Lock()
suite.xAppMgrFunc = doSleep
+ suite.mu.Unlock()
data, err := queryXAppsConfig("http://"+suite.listener.Addr().String()+"/test_url/", 1)
suite.Equal([]byte("{}"), data)
doReplyWithErr := func(w http.ResponseWriter) {
http.Error(w, "405 method not allowed", http.StatusMethodNotAllowed)
}
+
+ suite.mu.Lock()
suite.xAppMgrFunc = doReplyWithErr
+ suite.mu.Unlock()
data, err := queryXAppsConfig("http://"+suite.listener.Addr().String()+"/test_url/", 1)
suite.Equal([]byte("{}"), data)
doReply := func(w http.ResponseWriter) {
fmt.Fprintf(w, "reply message")
}
+
+ suite.mu.Lock()
suite.xAppMgrFunc = doReply
+ suite.mu.Unlock()
data, err := queryXAppsConfig("http://"+suite.listener.Addr().String()+"/test_url/", 1)
suite.NotNil(data)