Skip to content

Commit

Permalink
Merge pull request #31 from ian60509/refactor/processor-consumer
Browse files Browse the repository at this point in the history
test: fix testing file error
  • Loading branch information
ianchen0119 authored Jun 27, 2024
2 parents 5d49a34 + 935260e commit e098113
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 12 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/free5gc/openapi v1.0.8
github.com/free5gc/util v1.0.6
github.com/gin-gonic/gin v1.9.1
github.com/golang/mock v1.4.4
github.com/google/uuid v1.3.0
github.com/mitchellh/mapstructure v1.4.3
github.com/pkg/errors v0.9.1
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFU
github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.4 h1:l75CXGRSwbaYNpl/Z2X1XIIAMSCquvXgpVZDhwEIJsc=
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down
44 changes: 34 additions & 10 deletions internal/sbi/api_sanity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import (
"testing"

"github.com/gin-gonic/gin"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"

"github.com/free5gc/openapi/models"
db "github.com/free5gc/udr/internal/database"
"github.com/free5gc/udr/internal/logger"
"github.com/free5gc/udr/internal/sbi/processor"
"github.com/free5gc/udr/pkg/factory"
util_logger "github.com/free5gc/util/logger"
"github.com/free5gc/util/mongoapi"
Expand All @@ -24,10 +26,32 @@ type testdata struct {
supi string
}

func setupHttpServer() *gin.Engine {
func setupHttpServer(t *testing.T) *gin.Engine {
router := util_logger.NewGinWithLogrus(logger.GinLog)
dataRepositoryGroup := router.Group(factory.UdrDrResUriPrefix)
var s Server
ctrl := gomock.NewController(t)
defer ctrl.Finish()

udr := NewMockUDR(ctrl)
factory.UdrConfig = &factory.Config{
Configuration: &factory.Configuration{
DbConnectorType: "mongodb",
Mongodb: &factory.Mongodb{},
Sbi: &factory.Sbi{
BindingIPv4: "127.0.0.1",
Port: 8000,
},
},
}
udr.EXPECT().
Config().
Return(factory.UdrConfig).
AnyTimes()

processor := processor.NewProcessor(udr)
udr.EXPECT().Processor().Return(processor).AnyTimes()

s := NewServer(udr, "")
dataRepositoryRoutes := s.getDataRepositoryRoutes()
AddService(dataRepositoryGroup, dataRepositoryRoutes)
return router
Expand All @@ -45,7 +69,7 @@ func setupMongoDB(t *testing.T) {
}

func getUri(t *testing.T, baseUri, extUri string) *httptest.ResponseRecorder {
server := setupHttpServer()
server := setupHttpServer(t)
reqUri := baseUri + extUri
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, reqUri, nil)
require.Nil(t, err)
Expand Down Expand Up @@ -84,7 +108,7 @@ func getInfluData(supi string) *models.TrafficInfluData {
func postPutInfluData(t *testing.T, method string, baseUri, extUri string, influData *models.TrafficInfluData) (
*httptest.ResponseRecorder, []byte,
) {
server := setupHttpServer()
server := setupHttpServer(t)
reqUri := baseUri + extUri
bjson, err := json.Marshal(influData)
require.Nil(t, err)
Expand All @@ -109,7 +133,7 @@ func putInfluData(t *testing.T, baseUri, extUri string, influData *models.Traffi
}

func delUri(t *testing.T, baseUri, extUri string) *httptest.ResponseRecorder {
server := setupHttpServer()
server := setupHttpServer(t)
reqUri := baseUri + extUri
req, err := http.NewRequestWithContext(context.Background(), http.MethodDelete, reqUri, nil)
require.Nil(t, err)
Expand All @@ -119,7 +143,7 @@ func delUri(t *testing.T, baseUri, extUri string) *httptest.ResponseRecorder {
}

func TestUDR_Root(t *testing.T) {
server := setupHttpServer()
server := setupHttpServer(t)
reqUri := factory.UdrDrResUriPrefix + "/"

req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, reqUri, nil)
Expand All @@ -138,7 +162,7 @@ func TestUDR_GetSubs2Notify_GetBeforeCreateingOne(t *testing.T) {
t.Skip("skipping testing in short mode")
}

server := setupHttpServer()
server := setupHttpServer(t)
reqUri := factory.UdrDrResUriPrefix + "/application-data/influenceData/subs-to-notify?dnn=internet"

req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, reqUri, nil)
Expand All @@ -157,7 +181,7 @@ func TestUDR_GetSubs2Notify_CreateThenGet(t *testing.T) {
t.Skip("skipping testing in short mode")
}

server := setupHttpServer()
server := setupHttpServer(t)
baseUri := factory.UdrDrResUriPrefix + "/application-data/influenceData/subs-to-notify"
reqUri := baseUri

Expand Down Expand Up @@ -233,7 +257,7 @@ func TestUDR_InfluData_GetBeforeCreateing(t *testing.T) {
t.Skip("skipping testing in short mode")
}

server := setupHttpServer()
server := setupHttpServer(t)
reqUri := factory.UdrDrResUriPrefix + "/application-data/influenceData"

req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, reqUri, nil)
Expand All @@ -255,7 +279,7 @@ func TestUDR_InfluData_CreateThenGet(t *testing.T) {

// PUT, PATCH, DELETE
setupMongoDB(t)
server := setupHttpServer()
server := setupHttpServer(t)
baseUri := factory.UdrDrResUriPrefix + "/application-data/influenceData"
td1 := testdata{"/influenceId0001", "imsi-208930000000001"}
td2 := testdata{"/influenceId0002", "imsi-208930000000002"}
Expand Down
3 changes: 1 addition & 2 deletions internal/sbi/processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package processor
import (
"github.com/free5gc/udr/internal/database"
"github.com/free5gc/udr/pkg/app"
"github.com/free5gc/udr/pkg/factory"
)

type Processor struct {
Expand All @@ -14,6 +13,6 @@ type Processor struct {
func NewProcessor(udr app.App) *Processor {
return &Processor{
App: udr,
DbConnector: database.NewDbConnector(factory.UdrConfig.Configuration.DbConnectorType),
DbConnector: database.NewDbConnector(udr.Config().Configuration.DbConnectorType),
}
}
139 changes: 139 additions & 0 deletions internal/sbi/server_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e098113

Please sign in to comment.