Skip to content

Commit

Permalink
fix: Add test for unchanging NRF URI
Browse files Browse the repository at this point in the history
  • Loading branch information
ghislainbourgeois committed Nov 23, 2023
1 parent cbdd2b5 commit be89e02
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
9 changes: 4 additions & 5 deletions service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,15 +429,14 @@ func (udm *UDM) registerNF() {
self := context.UDM_Self()
for msg := range ConfigPodTrigger {
initLog.Infof("Minimum configuration from config pod available %v", msg)
proflie, err := consumer.BuildNFInstance(self)
profile, err := consumer.BuildNFInstance(self)
if err != nil {
logger.InitLog.Errorln(err.Error())
} else {
var err1 error
var prof models.NfProfile
prof, _, self.NfId, err1 = consumer.SendRegisterNFInstance(self.NrfUri, self.NfId, proflie)
if err1 != nil {
logger.InitLog.Errorln(err1.Error())
prof, _, self.NfId, err = consumer.SendRegisterNFInstance(self.NrfUri, self.NfId, profile)
if err != nil {
logger.InitLog.Errorln(err.Error())
} else {
udm.StartKeepAliveTimer(prof)
logger.CfgLog.Infof("Sent Register NF Instance with updated profile")
Expand Down
35 changes: 35 additions & 0 deletions service/init_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2023 Open Networking Foundation <[email protected]>
//

package service

import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
"time"

"github.com/omec-project/udm/context"
)

func Test_nrf_url_is_not_overwritten_when_registering(t *testing.T) {
svr := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "banana")
}))
svr.EnableHTTP2 = true
svr.StartTLS()
defer svr.Close()
self := context.UDM_Self()
self.NrfUri = svr.URL
self.RegisterIPv4 = "127.0.0.2"
var udm *UDM
go udm.registerNF()
ConfigPodTrigger <- true

time.Sleep(1 * time.Second)
if self.NrfUri != svr.URL {
t.Errorf("Expected NRF URL to stay %v, but was %v", svr.URL, self.NrfUri)
}
}

0 comments on commit be89e02

Please sign in to comment.