-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: removing NRF cache data after checking notification event type (#…
…325) * fix removing NRFcache without checking notification event type Signed-off-by: gatici <[email protected]> * chore: adding licence header Signed-off-by: gatici <[email protected]> --------- Signed-off-by: gatici <[email protected]>
- Loading branch information
Showing
6 changed files
with
231 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
// Copyright 2024 Canonical Ltd. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package producer | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"os" | ||
"testing" | ||
|
||
"github.com/omec-project/openapi/models" | ||
smfContext "github.com/omec-project/smf/context" | ||
"github.com/omec-project/smf/factory" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var ( | ||
nfInstanceID = "34343-4343-43-434-343" | ||
subscriptionID = "46326-232353-2323" | ||
) | ||
|
||
func setupTest() { | ||
if err := factory.InitConfigFactory("../config/smfcfg.yaml"); err != nil { | ||
fmt.Printf("Could not InitConfigFactory: %+v", err) | ||
} | ||
} | ||
|
||
func TestNfSubscriptionStatusNotify(t *testing.T) { | ||
t.Logf("test cases fore NfSubscriptionStatusNotify") | ||
callCountSendRemoveSubscription := 0 | ||
callCountNRFCacheRemoveNfProfileFromNrfCache := 0 | ||
origSendRemoveSubscription := SendRemoveSubscription | ||
origNRFCacheRemoveNfProfileFromNrfCache := NRFCacheRemoveNfProfileFromNrfCache | ||
defer func() { | ||
SendRemoveSubscription = origSendRemoveSubscription | ||
NRFCacheRemoveNfProfileFromNrfCache = origNRFCacheRemoveNfProfileFromNrfCache | ||
}() | ||
SendRemoveSubscription = func(subscriptionId string) (problemDetails *models.ProblemDetails, err error) { | ||
t.Logf("test SendRemoveSubscription called") | ||
callCountSendRemoveSubscription++ | ||
return nil, nil | ||
} | ||
NRFCacheRemoveNfProfileFromNrfCache = func(nfInstanceId string) bool { | ||
t.Logf("test NRFCacheRemoveNfProfileFromNrfCache called") | ||
callCountNRFCacheRemoveNfProfileFromNrfCache++ | ||
return true | ||
} | ||
udmProfile := models.NfProfileNotificationData{ | ||
UdrInfo: &models.UdrInfo{ | ||
SupportedDataSets: []models.DataSetId{ | ||
models.DataSetId_SUBSCRIPTION, | ||
}, | ||
}, | ||
NfInstanceId: nfInstanceID, | ||
NfType: "UDM", | ||
NfStatus: "DEREGISTERED", | ||
} | ||
badRequestProblem := models.ProblemDetails{ | ||
Status: http.StatusBadRequest, | ||
Cause: "MANDATORY_IE_MISSING", | ||
Detail: "Missing IE [Event]/[NfInstanceUri] in NotificationData", | ||
} | ||
parameters := []struct { | ||
expectedProblem *models.ProblemDetails | ||
testName string | ||
result string | ||
nfInstanceId string | ||
nfInstanceIdForSubscription string | ||
subscriptionID string | ||
notificationEventType string | ||
expectedCallCountSendRemoveSubscription int | ||
expectedCallCountNRFCacheRemoveNfProfileFromNrfCache int | ||
enableNrfCaching bool | ||
}{ | ||
{ | ||
nil, | ||
"Notification event type DEREGISTERED NRF caching is enabled", | ||
"NF profile removed from cache and subscription is removed", | ||
nfInstanceID, | ||
nfInstanceID, | ||
subscriptionID, | ||
"NF_DEREGISTERED", | ||
1, | ||
1, | ||
true, | ||
}, | ||
{ | ||
nil, | ||
"Notification event type DEREGISTERED NRF caching is enabled Subscription is not found", | ||
"NF profile removed from cache and subscription is not removed", | ||
nfInstanceID, | ||
"", | ||
"", | ||
"NF_DEREGISTERED", | ||
0, | ||
1, | ||
true, | ||
}, | ||
{ | ||
nil, | ||
"Notification event type DEREGISTERED NRF caching is disabled", | ||
"NF profile is not removed from cache and subscription is removed", | ||
nfInstanceID, | ||
nfInstanceID, | ||
subscriptionID, | ||
"NF_DEREGISTERED", | ||
1, | ||
0, | ||
false, | ||
}, | ||
{ | ||
nil, | ||
"Notification event type REGISTERED NRF caching is enabled", | ||
"NF profile is not removed from cache and subscription is not removed", | ||
nfInstanceID, | ||
nfInstanceID, | ||
subscriptionID, | ||
"NF_REGISTERED", | ||
0, | ||
0, | ||
true, | ||
}, | ||
{ | ||
nil, | ||
"Notification event type DEREGISTERED NRF caching is enabled NfInstanceUri in notificationData is different", | ||
"NF profile removed from cache and subscription is not removed", | ||
nfInstanceID, | ||
nfInstanceID, | ||
subscriptionID, | ||
"NF_DEREGISTERED", | ||
1, | ||
1, | ||
true, | ||
}, | ||
{ | ||
&badRequestProblem, | ||
"Notification event type DEREGISTERED NRF caching is enabled NfInstanceUri in notificationData is empty", | ||
"Return StatusBadRequest with cause MANDATORY_IE_MISSING", | ||
"", | ||
"", | ||
subscriptionID, | ||
"NF_DEREGISTERED", | ||
0, | ||
0, | ||
true, | ||
}, | ||
{ | ||
&badRequestProblem, | ||
"Notification event type empty NRF caching is enabled", | ||
"Return StatusBadRequest with cause MANDATORY_IE_MISSING", | ||
nfInstanceID, | ||
nfInstanceID, | ||
subscriptionID, | ||
"", | ||
0, | ||
0, | ||
true, | ||
}, | ||
} | ||
for i := range parameters { | ||
t.Run(fmt.Sprintf("NfSubscriptionStatusNotify testname %v result %v", parameters[i].testName, parameters[i].result), func(t *testing.T) { | ||
smfContext.SMF_Self().EnableNrfCaching = parameters[i].enableNrfCaching | ||
smfContext.SMF_Self().NfStatusSubscriptions.Store(parameters[i].nfInstanceIdForSubscription, parameters[i].subscriptionID) | ||
notificationData := models.NotificationData{ | ||
Event: models.NotificationEventType(parameters[i].notificationEventType), | ||
NfInstanceUri: parameters[i].nfInstanceId, | ||
NfProfile: &udmProfile, | ||
ProfileChanges: []models.ChangeItem{}, | ||
} | ||
err := NfSubscriptionStatusNotifyProcedure(notificationData) | ||
assert.Equal(t, parameters[i].expectedProblem, err, "NfSubscriptionStatusNotifyProcedure is failed.") | ||
// Subscription is removed. | ||
assert.Equal(t, parameters[i].expectedCallCountSendRemoveSubscription, callCountSendRemoveSubscription, "Subscription is not removed.") | ||
// NF Profile is removed from NRF cache. | ||
assert.Equal(t, parameters[i].expectedCallCountNRFCacheRemoveNfProfileFromNrfCache, callCountNRFCacheRemoveNfProfileFromNrfCache, "NF Profile is not removed from NRF cache.") | ||
callCountSendRemoveSubscription = 0 | ||
callCountNRFCacheRemoveNfProfileFromNrfCache = 0 | ||
smfContext.SMF_Self().NfStatusSubscriptions.Delete(parameters[i].nfInstanceIdForSubscription) | ||
}) | ||
} | ||
} | ||
|
||
func TestMain(m *testing.M) { | ||
setupTest() | ||
exitVal := m.Run() | ||
os.Exit(exitVal) | ||
} |