X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=cmd%2Fvesmgr%2Fvesmgr_queryxappconfig_test.go;h=053adcc91e3dd9fbbe17d0956c653ef3c6132ef4;hb=280b4eb6efbe989f79ee5bf816b9fb970d5121e9;hp=e9bcbfe6006e84ab1749e82088cce792619678eb;hpb=fc77ebb24a8627ccfb18edd8b5dbc038da475eab;p=ric-plt%2Fvespamgr.git diff --git a/cmd/vesmgr/vesmgr_queryxappconfig_test.go b/cmd/vesmgr/vesmgr_queryxappconfig_test.go old mode 100644 new mode 100755 index e9bcbfe..053adcc --- a/cmd/vesmgr/vesmgr_queryxappconfig_test.go +++ b/cmd/vesmgr/vesmgr_queryxappconfig_test.go @@ -13,6 +13,10 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * This source code is part of the near-RT RIC (RAN Intelligent Controller) + * platform project (RICP). + * */ package main @@ -23,6 +27,7 @@ import ( "net/http" "net/url" "os" + "sync" "testing" "time" @@ -35,6 +40,7 @@ type QueryXAppsConfigTestSuite struct { suite.Suite listener net.Listener xAppMgrFunc do + mu sync.Mutex } // suite setup creates the HTTP server @@ -52,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": + suite.mu.Lock() + defer suite.mu.Unlock() suite.xAppMgrFunc(w) } }) + http.Serve(listener, nil) } @@ -62,7 +71,10 @@ func (suite *QueryXAppsConfigTestSuite) TestQueryXAppsConfigFailsWithTimeout() { 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) @@ -76,7 +88,10 @@ func (suite *QueryXAppsConfigTestSuite) TestQueryXAppsConfigFailsWithAnErrorRepl 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) @@ -88,7 +103,10 @@ func (suite *QueryXAppsConfigTestSuite) TestQueryXAppsConfigOk() { 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)