Skip to content

Commit

Permalink
test: add SnssaiToNas test
Browse files Browse the repository at this point in the history
  • Loading branch information
andy89923 committed Aug 7, 2024
1 parent 1f64e9b commit ed354e5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
4 changes: 2 additions & 2 deletions nasConvert/Snssai.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

// TS24.501 9.11.2.8 S-NSSAI
func SnssaiToModels(nasSnssai *nasType.SNSSAI) (snssai models.Snssai) {
sD := nasSnssai.GetSD()
if nasSnssai.GetLen() >= uint8(3) {
if nasSnssai.GetLen() == uint8(4) {
sD := nasSnssai.GetSD()
snssai.Sd = hex.EncodeToString(sD[:])
}
snssai.Sst = int32(nasSnssai.GetSST())
Expand Down
35 changes: 35 additions & 0 deletions nasConvert/Snssai_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,38 @@ func TestSnssaiToModels(t *testing.T) {
})
}
}

func TestSnssaiToNas(t *testing.T) {
testCase := []struct {
Name string
Snssai models.Snssai
nasSnssai []uint8
}{
{
Name: "Default",
Snssai: models.Snssai{
Sst: int32(1),
Sd: "010203",
},
nasSnssai: []uint8{
04, 01, 01, 02, 03,
},
},
{
Name: "Empty SD",
Snssai: models.Snssai{
Sst: int32(1),
},
nasSnssai: []uint8{
01, 01,
},
},
}

for _, tc := range testCase {
t.Run(tc.Name, func(t *testing.T) {
result := nasConvert.SnssaiToNas(tc.Snssai)
require.Equal(t, tc.nasSnssai, result)
})
}
}

0 comments on commit ed354e5

Please sign in to comment.