Skip to content

Commit

Permalink
chore: Add first unit tests (#55)
Browse files Browse the repository at this point in the history
* chore: Add first unit tests

* gofmt consumer/nf_management_test.go

---------

Co-authored-by: gab-arrobo <[email protected]>
  • Loading branch information
ghislainbourgeois and gab-arrobo authored Jan 19, 2024
1 parent 9546427 commit 2ffbd22
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion consumer/nf_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func BuildNFProfile(context *nssf_context.NSSFContext) (profile models.NfProfile
if len(services) > 0 {
profile.NfServices = &services
}
return
return profile, err
}

var SendRegisterNFInstance = func(nrfUri, nfInstanceId string, profile models.NfProfile) (
Expand Down
56 changes: 56 additions & 0 deletions consumer/nf_management_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2024 Canonical Ltd.
//
// SPDX-License-Identifier: Apache-2.0
package consumer_test

import (
"testing"

"github.com/omec-project/nssf/consumer"
"github.com/omec-project/nssf/context"
"github.com/omec-project/openapi/models"
)

func TestBuildNFProfile_EmptyContext(t *testing.T) {
ctx := context.NSSFContext{NfId: "test-id"}

profile, err := consumer.BuildNFProfile(&ctx)

if err != nil {
t.Errorf("Error building NFProfile: %v\n", err)
}

if profile.NfInstanceId != "test-id" ||
profile.NfType != models.NfType_NSSF ||
profile.NfStatus != models.NfStatus_REGISTERED ||
len(*profile.PlmnList) != 0 ||
profile.Ipv4Addresses[0] != ctx.RegisterIPv4 ||
profile.NfServices != nil {
t.Errorf("Unexpected NfProfile built: %v\n", profile)
}
}

func TestBuildNFProfile_InitializedContext(t *testing.T) {
ctx := context.NSSFContext{NfId: "test-id",
SupportedPlmnList: []models.PlmnId{{Mcc: "200", Mnc: "99"}},
RegisterIPv4: "127.0.0.42",
NfService: map[models.ServiceName]models.NfService{models.ServiceName_NNSSF_NSSELECTION: {ServiceInstanceId: "instance-id",
ServiceName: "service-name"}},
}

profile, err := consumer.BuildNFProfile(&ctx)

if err != nil {
t.Errorf("Error building NFProfile: %v\n", err)
}

if profile.NfInstanceId != "test-id" ||
profile.NfType != models.NfType_NSSF ||
profile.NfStatus != models.NfStatus_REGISTERED ||
(*profile.PlmnList)[0].Mcc != "200" ||
(*profile.PlmnList)[0].Mnc != "99" ||
profile.Ipv4Addresses[0] != ctx.RegisterIPv4 ||
(*profile.NfServices)[0].ServiceName != "service-name" {
t.Errorf("Unexpected NfProfile built: %v\n", profile)
}
}

0 comments on commit 2ffbd22

Please sign in to comment.