.SECONDEXPANSION:
$(GO_CACHE_DIR)/%_test: $(GOALLFILES) $(GOMODFILES) $$(BUILDDEPS) FORCE
@echo "Testing:\t$*"
- @eval GO111MODULE=on GOSUMDB=off GO_ENABLED=0 GOOS=linux $(BUILDARGS) $(GOTEST) -coverprofile $(COVEROUT) -c -o $@ ./$*
+ @eval GO111MODULE=on GOSUMDB=off GO_ENABLED=0 GOOS=linux $(BUILDARGS) $(GOTEST) -cover -coverprofile=coverage.out -c -o $@ ./$*
@if test -e $@ ; then eval $(TESTENV) $@ -test.v -test.coverprofile $(COVEROUT); else true ; fi
@if test -e $@ ; then go tool cover -html=$(COVEROUT) -o $(COVERHTML); else true ; fi
}
func (r *Router) GetSymptomDataParams(w http.ResponseWriter, req *http.Request) SymptomDataParams {
+ Logger.Info("GetSymptomDataParams ...")
+
params := SymptomDataParams{}
queryParams := req.URL.Query()
+ Logger.Info("GetSymptomDataParams: %+v", queryParams)
+
for p := range queryParams {
if p == "timeout" {
fmt.Sscanf(p, "%d", ¶ms.Timeout)
"bytes"
"crypto/md5"
"fmt"
- "github.com/spf13/viper"
"strings"
"time"
"unsafe"
+
+ "github.com/spf13/viper"
)
var RMRCounterOpts = []CounterOpts{
return
}
- // Special case for multiple consumers
- for _, c := range m.consumers {
- cptr := unsafe.Pointer(rxBuffer.payload)
- params.Payload = C.GoBytes(cptr, C.int(rxBuffer.len))
- params.PayloadLen = int(rxBuffer.len)
- params.Mtype = int(rxBuffer.mtype)
- params.SubId = int(rxBuffer.sub_id)
+ /*
+ // Special case for multiple consumers
+ for _, c := range m.consumers {
+ cptr := unsafe.Pointer(rxBuffer.payload)
+ params.Payload = C.GoBytes(cptr, C.int(rxBuffer.len))
+ params.PayloadLen = int(rxBuffer.len)
+ params.Mtype = int(rxBuffer.mtype)
+ params.SubId = int(rxBuffer.sub_id)
- err := c.Consume(params)
- if err != nil {
- Logger.Warn("rmrClient: Consumer returned error: %v", err)
+ err := c.Consume(params)
+ if err != nil {
+ Logger.Warn("rmrClient: Consumer returned error: %v", err)
+ }
}
- }
+ */
}
func (m *RMRClient) Allocate(size int) *C.rmr_mbuf_t {
"bytes"
"encoding/json"
"fmt"
+ "io/ioutil"
+ "net/http"
+ "os"
+ "time"
+
"github.com/go-openapi/loads"
httptransport "github.com/go-openapi/runtime/client"
"github.com/go-openapi/runtime/middleware"
"github.com/go-openapi/strfmt"
"github.com/spf13/viper"
- "io/ioutil"
- "net/http"
- "os"
- "time"
apiclient "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/clientapi"
apicommon "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/clientapi/common"
func (r *Subscriber) CreateTransport() *apiclient.RICSubscription {
return apiclient.New(httptransport.New(r.remoteHost, r.remoteUrl, r.remoteProt), strfmt.Default)
}
-
-/*func (r *Subscriber) getXappConfig() (appconfig models.XappConfigList, err error) {
-
- Logger.Error("Inside getXappConfig")
-
- var metadata models.ConfigMetadata
- var xappconfig models.XAppConfig
- name := viper.GetString("name")
- configtype := "json"
- metadata.XappName = &name
- metadata.ConfigType = &configtype
-
- configFile, err := os.Open("/opt/ric/config/config-file.json")
- if err != nil {
- Logger.Error("Cannot open config file: %v", err)
- return nil,errors.New("Could Not parse the config file")
- }
-
- body, err := ioutil.ReadAll(configFile)
-
- defer configFile.Close()
-
- xappconfig.Metadata = &metadata
- xappconfig.Config = body
-
- appconfig = append(appconfig,&xappconfig)
-
- return appconfig,nil
-}*/
package xapp
import (
+ "bytes"
"fmt"
+ "net/http"
+ "net/http/httptest"
"testing"
"time"
assert.Equal(t, err, nil)
}
+func TestResponseHandler(t *testing.T) {
+ Subscription.SetResponseCB(SubscriptionRespHandler)
+
+ payload := []byte(`{"SubscriptionInstances":[{"tXappEventInstanceID": 1}]`)
+ req, err := http.NewRequest("POST", "/ric/v1/subscriptions/response", bytes.NewBuffer(payload))
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ rr := httptest.NewRecorder()
+ handler := http.HandlerFunc(Subscription.ResponseHandler)
+ handler.ServeHTTP(rr, req)
+
+ if status := rr.Code; status != http.StatusOK {
+ t.Errorf("handler returned wrong status code: got %v want %v", status, http.StatusOK)
+ }
+ time.Sleep(time.Duration(2) * time.Second)
+}
+
// Helper functions
+func SubscriptionRespHandler(resp *clientmodel.SubscriptionResponse) {
+}
+
func processSubscriptions(subscriptionId string) {
// Generate requestorId, instanceId
xappInstanceId := int64(11)
package xapp
import (
+ "io/ioutil"
"net/http"
+ "os"
"testing"
"github.com/stretchr/testify/assert"
utils.FetchFiles("./", []string{"go.mod"})
utils.FetchFiles("./", []string{"go.mod"})
+ tmpFile, err := ioutil.TempFile("", "symptom")
+ assert.Equal(t, err, nil)
+ defer os.Remove(tmpFile.Name())
+
+ err = utils.ZipFiles(tmpFile, "/tmp/abcd", []string{"/tmp/abcd/file.txt"})
+ assert.Equal(t, err, nil)
+
utils.DeleteFile("/tmp/abcd")
}
func TestSymptomdata(t *testing.T) {
+ os.Setenv("RMR_STASH_RT", "config/uta_rtg.rt.stash.inc")
assert.Equal(t, Resource.CollectDefaultSymptomData("abcd.tgz", "data"), "/tmp/xapp/")
}
func TestSymptomdataCollection(t *testing.T) {
- var handler = func(w http.ResponseWriter, r *http.Request) {
+ var handler1 = func(w http.ResponseWriter, r *http.Request) {
Resource.SendSymptomDataJson(w, r, "data", "aaaa")
Resource.SendSymptomDataFile(w, r, "./config", "symptomdata.gz")
}
- Resource.InjectQueryRoute("/ric/v1/user", handler, "GET", "foo", "bar", "id", "mykey")
+ Resource.InjectQueryRoute("/ric/v1/user1", handler1, "GET", "foo", "bar", "id", "mykey")
- req, _ := http.NewRequest("GET", "/ric/v1/user?foo=bar&id=mykey", nil)
+ req, _ := http.NewRequest("GET", "/ric/v1/user1?foo=bar&id=mykey", nil)
resp := executeRequest(req, nil)
checkResponseCode(t, http.StatusOK, resp.Code)
}
func TestSymptomdataCollectionError(t *testing.T) {
- var handler = func(w http.ResponseWriter, r *http.Request) {
+ var handler2 = func(w http.ResponseWriter, r *http.Request) {
Resource.SendSymptomDataError(w, r, "Error text")
}
- Resource.InjectQueryRoute("/ric/v1/user", handler, "GET", "foo", "bar", "id", "mykey")
+ Resource.InjectQueryRoute("/ric/v1/user2", handler2, "GET", "foo", "bar", "id", "mykey")
- req, _ := http.NewRequest("GET", "/ric/v1/user?foo=bar&id=mykey", nil)
+ req, _ := http.NewRequest("GET", "/ric/v1/user2?foo=bar&id=mykey", nil)
resp := executeRequest(req, nil)
- checkResponseCode(t, http.StatusOK, resp.Code)
+ checkResponseCode(t, http.StatusInternalServerError, resp.Code)
}
func TestGetSymptomDataParams(t *testing.T) {
- var handler = func(w http.ResponseWriter, r *http.Request) {
+ var handler3 = func(w http.ResponseWriter, r *http.Request) {
Resource.GetSymptomDataParams(w, r)
}
- Resource.InjectQueryRoute("/ric/v1/user", handler, "GET", "foo", "bar", "id", "mykey")
+ Resource.InjectQueryRoute("/ric/v1/user3", handler3, "GET", "timeout", "10", "fromtime", "1", "totime", "2")
- req, _ := http.NewRequest("GET", "/ric/v1/user?foo=bar&id=mykey", nil)
+ req, _ := http.NewRequest("GET", "/ric/v1/user3?timeout=10&fromtime=1&totime=2", nil)
resp := executeRequest(req, nil)
checkResponseCode(t, http.StatusOK, resp.Code)
}
func TestAppconfigHandler(t *testing.T) {
- var handler = func(w http.ResponseWriter, r *http.Request) {
+ var handler4 = func(w http.ResponseWriter, r *http.Request) {
appconfigHandler(w, r)
}
- Resource.InjectQueryRoute("/ric/v1/user", handler, "GET", "foo", "bar", "id", "mykey")
+ Resource.InjectQueryRoute("/ric/v1/user4", handler4, "GET", "foo", "bar", "id", "mykey")
- req, _ := http.NewRequest("GET", "/ric/v1/user?foo=bar&id=mykey", nil)
+ req, _ := http.NewRequest("GET", "/ric/v1/user4?foo=bar&id=mykey", nil)
resp := executeRequest(req, nil)
- checkResponseCode(t, http.StatusOK, resp.Code)
+ checkResponseCode(t, http.StatusInternalServerError, resp.Code)
}
"bytes"
"encoding/json"
"fmt"
- "github.com/spf13/viper"
"net/http"
"os"
"os/signal"
"sync/atomic"
"syscall"
"time"
+
+ "github.com/spf13/viper"
)
type ReadyCB func(interface{})
svc := fmt.Sprintf(service, strings.ToUpper(appnamespace), strings.ToUpper(host))
url := strings.Split(os.Getenv(strings.Replace(svc, "-", "_", -1)), "//")
+
+ Logger.Info("getService: %+v %+v", svc, url)
if len(url) > 1 {
return url[1]
}
import (
"bytes"
- "github.com/gorilla/mux"
- "github.com/spf13/viper"
- "github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"
"time"
+
+ "github.com/gorilla/mux"
+ "github.com/spf13/viper"
+ "github.com/stretchr/testify/assert"
)
//var _ = func() bool {
// Test cases
func TestMain(m *testing.M) {
+ os.Setenv("SERVICE_RICXAPP_UEEC_HTTP_PORT", "tcp://localhost:8080")
+ os.Setenv("SERVICE_RICXAPP_UEEC_RMR_PORT", "tcp://localhost:4561")
go RunWithParams(Consumer{}, viper.GetBool("controls.waitForSdl"))
time.Sleep(time.Duration(5) * time.Second)
code := m.Run()
return true
}
Resource.InjectStatusCb(f)
+ Resource.CheckStatus()
}
func TestSdlInterfaces(t *testing.T) {
func TestMisc(t *testing.T) {
Logger.Info("CASE: TestMisc")
-
+ var cb = func() {}
IsReady()
SetReadyCB(func(interface{}) {}, "")
XappReadyCb("")
- SetShutdownCB(func() {})
+ SetShutdownCB(cb)
+ XappShutdownCb()
+ getService("ueec", SERVICE_HTTP)
+
+ Logger.SetFormat(1)
+ Logger.SetLevel(0)
+ Logger.Error("...")
+ Logger.Warn("...")
+ Logger.Info("...")
+
+ mb := Rmr.Allocate(100)
+ Rmr.ReAllocate(mb, 200)
+
+ NewMetrics("", "", Resource.router)
}
func TestTeardown(t *testing.T) {
Sdl.Clear()
Sdl.IsReady()
Sdl.GetStat()
+ Rnib.GetNodebByGlobalNbId(1, &RNIBGlobalNbId{})
+ Rnib.SaveNodeb(&RNIBNbIdentity{}, &RNIBNodebInfo{})
+ go Sdl.TestConnection()
+ time.Sleep(time.Duration(2) * time.Second)
}
// Helper functions