Refactor the code
[ric-plt/vespamgr.git] / cmd / vesmgr / vesmgr_queryxappconfig_test.go
similarity index 67%
rename from cmd/vesmgr/vesmgr_queryxappssttus_test.go
rename to cmd/vesmgr/vesmgr_queryxappconfig_test.go
index 5f0f36c..e9bcbfe 100644 (file)
@@ -19,25 +19,26 @@ package main
 
 import (
        "fmt"
-       "github.com/stretchr/testify/suite"
        "net"
        "net/http"
        "net/url"
        "os"
        "testing"
        "time"
+
+       "github.com/stretchr/testify/suite"
 )
 
 type do func(w http.ResponseWriter)
 
-type QueryXAppsStatusTestSuite struct {
+type QueryXAppsConfigTestSuite struct {
        suite.Suite
        listener    net.Listener
        xAppMgrFunc do
 }
 
 // suite setup creates the HTTP server
-func (suite *QueryXAppsStatusTestSuite) SetupSuite() {
+func (suite *QueryXAppsConfigTestSuite) SetupSuite() {
        os.Unsetenv("http_proxy")
        os.Unsetenv("HTTP_PROXY")
        var err error
@@ -46,7 +47,7 @@ func (suite *QueryXAppsStatusTestSuite) SetupSuite() {
        go runXAppMgr(suite.listener, "/test_url/", suite)
 }
 
-func runXAppMgr(listener net.Listener, url string, suite *QueryXAppsStatusTestSuite) {
+func runXAppMgr(listener net.Listener, url string, suite *QueryXAppsConfigTestSuite) {
 
        http.HandleFunc(url, func(w http.ResponseWriter, r *http.Request) {
                switch r.Method {
@@ -57,44 +58,44 @@ func runXAppMgr(listener net.Listener, url string, suite *QueryXAppsStatusTestSu
        http.Serve(listener, nil)
 }
 
-func (suite *QueryXAppsStatusTestSuite) TestQueryXAppsStatusFailsWithTimeout() {
-       do_sleep := func(w http.ResponseWriter) {
+func (suite *QueryXAppsConfigTestSuite) TestQueryXAppsConfigFailsWithTimeout() {
+       doSleep := func(w http.ResponseWriter) {
                time.Sleep(time.Second * 2)
        }
-       suite.xAppMgrFunc = do_sleep
+       suite.xAppMgrFunc = doSleep
 
-       data, err := queryXAppsStatus("http://"+suite.listener.Addr().String()+"/test_url/", 1)
-       suite.Nil(data)
+       data, err := queryXAppsConfig("http://"+suite.listener.Addr().String()+"/test_url/", 1)
+       suite.Equal([]byte("{}"), data)
        suite.NotNil(err)
        e, ok := err.(*url.Error)
        suite.Equal(ok, true)
        suite.Equal(e.Timeout(), true)
 }
 
-func (suite *QueryXAppsStatusTestSuite) TestQueryXAppsStatusFailsWithAnErrorReply() {
-       do_reply_with_err := func(w http.ResponseWriter) {
+func (suite *QueryXAppsConfigTestSuite) TestQueryXAppsConfigFailsWithAnErrorReply() {
+       doReplyWithErr := func(w http.ResponseWriter) {
                http.Error(w, "405 method not allowed", http.StatusMethodNotAllowed)
        }
-       suite.xAppMgrFunc = do_reply_with_err
+       suite.xAppMgrFunc = doReplyWithErr
 
-       data, err := queryXAppsStatus("http://"+suite.listener.Addr().String()+"/test_url/", 1)
-       suite.Nil(data)
+       data, err := queryXAppsConfig("http://"+suite.listener.Addr().String()+"/test_url/", 1)
+       suite.Equal([]byte("{}"), data)
        suite.NotNil(err)
        suite.Equal("405 Method Not Allowed", err.Error())
 }
 
-func (suite *QueryXAppsStatusTestSuite) TestQueryXAppsStatusOk() {
-       do_reply := func(w http.ResponseWriter) {
+func (suite *QueryXAppsConfigTestSuite) TestQueryXAppsConfigOk() {
+       doReply := func(w http.ResponseWriter) {
                fmt.Fprintf(w, "reply message")
        }
-       suite.xAppMgrFunc = do_reply
+       suite.xAppMgrFunc = doReply
 
-       data, err := queryXAppsStatus("http://"+suite.listener.Addr().String()+"/test_url/", 1)
+       data, err := queryXAppsConfig("http://"+suite.listener.Addr().String()+"/test_url/", 1)
        suite.NotNil(data)
        suite.Nil(err)
        suite.Equal(data, []byte("reply message"))
 }
 
-func TestQueryXAppsStatusTestSuite(t *testing.T) {
-       suite.Run(t, new(QueryXAppsStatusTestSuite))
+func TestQueryXAppsConfigTestSuite(t *testing.T) {
+       suite.Run(t, new(QueryXAppsConfigTestSuite))
 }