Skip to content

Commit

Permalink
Merge pull request #3 from ghislainbourgeois/add-tests
Browse files Browse the repository at this point in the history
chore: Add tests and standardize CI
  • Loading branch information
gab-arrobo authored Jan 27, 2024
2 parents 5636080 + 5762f03 commit 3178406
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 105 deletions.
17 changes: 17 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2022 Intel Corporation

# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"

- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"

29 changes: 0 additions & 29 deletions .github/workflows/go.yml

This file was deleted.

38 changes: 0 additions & 38 deletions .github/workflows/golangci-lint.yml

This file was deleted.

71 changes: 71 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2024 Canonical Ltd.

name: Main workflow

on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- name: Build
run: go build

lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- name: golangci-lint
uses: golangci/[email protected]
with:
version: latest
args: -v --config ./.golangci.yml

license-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: reuse lint
uses: fsfe/reuse-action@v2

fossa-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: FOSSA scan
uses: fossa-contrib/fossa-action@v3
with:
fossa-api-key: 9dc8fa92e3dd565687317beb87b56d89

unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- name: Unit tests
run: go test ./...
11 changes: 2 additions & 9 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,6 @@ linters-settings:
misspell:
#locale: US
ignore-words:
whitespace:
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
multi-func: false # Enforces newlines (or comments) after every multi-line function signature
wsl:
# If true append is only allowed to be cuddled if appending value is
# matching variables, fields or types on line above. Default is true.
Expand Down Expand Up @@ -246,18 +243,14 @@ linters:
- staticcheck
- unused
- gosimple
- structcheck
- varcheck
- ineffassign
- deadcode
- typecheck
# Additional
- lll
- godox
#- gomnd
#- goconst
- goconst
# - gocognit
# - maligned
# - nestif
# - gomodguard
- nakedret
Expand All @@ -272,7 +265,7 @@ linters:
- bodyclose
- asciicheck
#- stylecheck
# - unparam
- unparam
# - wsl

#disable-all: false
Expand Down
7 changes: 6 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@

module github.com/omec-project/ngap

go 1.14
go 1.21

require (
github.com/antonfisher/nested-logrus-formatter v1.3.1
github.com/omec-project/aper v1.1.0
github.com/omec-project/openapi v1.1.0
github.com/sirupsen/logrus v1.8.1
)

require (
github.com/golang-jwt/jwt v3.2.1+incompatible // indirect
golang.org/x/sys v0.0.0-20210423082822-04245dca01da // indirect
)
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
Expand Down Expand Up @@ -369,7 +367,6 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/h2non/gock.v1 v1.1.2/go.mod h1:n7UGz/ckNChHiK05rDoiC4MYSunEC/lyaUm2WWaDva0=
Expand Down
49 changes: 24 additions & 25 deletions ngapConvert/TimeStamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,30 @@ import (
/*
RFC 5905 Section 6 https://tools.ietf.org/html/rfc5905#section-6
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Seconds |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Fraction |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
NTP Timestamp Format
The 64-bit timestamp format is used in packet headers and other
places with limited word size. It includes a 32-bit unsigned seconds
field spanning 136 years and a 32-bit fraction field resolving 232
picoseconds. The 32-bit short format is used in delay and dispersion
header fields where the full resolution and range of the other
formats are not justified. It includes a 16-bit unsigned seconds
field and a 16-bit fraction field.
In the date and timestamp formats, the prime epoch, or base date of
era 0, is 0 h 1 January 1900 UTC, when all bits are zero. It should
be noted that strictly speaking, UTC did not exist prior to 1 January
1972, but it is convenient to assume it has existed for all eternity,
even if all knowledge of historic leap seconds has been lost. Dates
are relative to the prime epoch; values greater than zero represent
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Seconds |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Fraction |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
NTP Timestamp Format
The 64-bit timestamp format is used in packet headers and other
places with limited word size. It includes a 32-bit unsigned seconds
field spanning 136 years and a 32-bit fraction field resolving 232
picoseconds. The 32-bit short format is used in delay and dispersion
header fields where the full resolution and range of the other
formats are not justified. It includes a 16-bit unsigned seconds
field and a 16-bit fraction field.
In the date and timestamp formats, the prime epoch, or base date of
era 0, is 0 h 1 January 1900 UTC, when all bits are zero. It should
be noted that strictly speaking, UTC did not exist prior to 1 January
1972, but it is convenient to assume it has existed for all eternity,
even if all knowledge of historic leap seconds has been lost. Dates
are relative to the prime epoch; values greater than zero represent
*/
func TimeStampToInt32(timeStampNgap aper.OctetString) (timeStamp int32) {
if len(timeStampNgap) != 4 {
Expand Down
97 changes: 97 additions & 0 deletions ngap_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Copyright 2024 Canonical, Ltd.
//
// SPDX-License-Identifier: Apache-2.0

package ngap_test

import (
"testing"

"github.com/omec-project/aper"
"github.com/omec-project/ngap"
"github.com/omec-project/ngap/ngapType"
)

// globalRANIDIE for MCC 208, MNC 93
var globalRANIDIE ngapType.NGSetupRequestIEs = ngapType.NGSetupRequestIEs{
Id: ngapType.ProtocolIEID{Value: ngapType.ProtocolIEIDGlobalRANNodeID},
Criticality: ngapType.Criticality{Value: ngapType.CriticalityPresentReject},
Value: ngapType.NGSetupRequestIEsValue{
Present: ngapType.GlobalRANNodeIDPresentGlobalGNBID,
GlobalRANNodeID: &ngapType.GlobalRANNodeID{
Present: ngapType.GlobalRANNodeIDPresentGlobalGNBID,
GlobalGNBID: &ngapType.GlobalGNBID{
PLMNIdentity: ngapType.PLMNIdentity{Value: aper.OctetString{0x02, 0xF8, 0x39}},
GNBID: ngapType.GNBID{
Present: ngapType.GNBIDPresentGNBID,
GNBID: &aper.BitString{
Bytes: []byte{0x00, 0x01, 0x02},
BitLength: 24,
},
},
},
},
},
}

func TestSimplePDUEncoding(t *testing.T) {
// NGSetupRequest PDU
pdu := ngapType.NGAPPDU{
Present: ngapType.NGAPPDUPresentInitiatingMessage,
InitiatingMessage: &ngapType.InitiatingMessage{
ProcedureCode: ngapType.ProcedureCode{Value: ngapType.ProcedureCodeNGSetup},
Criticality: ngapType.Criticality{Value: ngapType.CriticalityPresentReject},
Value: ngapType.InitiatingMessageValue{
Present: ngapType.InitiatingMessagePresentNGSetupRequest,
NGSetupRequest: &ngapType.NGSetupRequest{
ProtocolIEs: ngapType.ProtocolIEContainerNGSetupRequestIEs{
List: []ngapType.NGSetupRequestIEs{
globalRANIDIE,
},
},
},
},
},
}

result, err := ngap.Encoder(pdu)
if err != nil {
t.Errorf("Could not encode simple PDU: %v; got error: %v\n", pdu, err)
}

expected := []byte{
0x00, 0x15, 0x00, 0x0F, 0x00, 0x00, 0x01, 0x00, 0x1B, 0x00,
0x08, 0x00, 0x02, 0xF8, 0x39, 0x10, 0x00, 0x01, 0x02,
}

if len(result) != len(expected) {
t.Errorf("Got wrong result length: %v\n", len(result))
}

for i, b := range result {
if b != expected[i] {
t.Errorf("Byte %d was %v, expected %v\n", i, b, expected[i])
}
}
}

func TestSimplePDUDecoding(t *testing.T) {
// ASN.1 PER encoded PDU
pdu_bytes := []byte{
0x00, 0x15, 0x00, 0x0F, 0x00, 0x00, 0x01, 0x00, 0x1B, 0x00,
0x08, 0x00, 0x02, 0xF8, 0x39, 0x10, 0x00, 0x01, 0x02,
}

pdu, err := ngap.Decoder(pdu_bytes)
if err != nil {
t.Errorf("Could not decode simple PDU bytes: %v; got error: %v\n", pdu_bytes, err)
}

ie := pdu.InitiatingMessage.Value.NGSetupRequest.ProtocolIEs.List[0]
plmn := ie.Value.GlobalRANNodeID.GlobalGNBID.PLMNIdentity.Value

if len(plmn) != 3 || plmn[0] != 0x02 || plmn[1] != 0xF8 || plmn[2] != 0x39 {
t.Errorf("Failed decoding simple PDU: %v; Expected PLMN: %v, got %v\n",
pdu_bytes, []byte{0x02, 0xF8, 0x39}, plmn)
}
}

0 comments on commit 3178406

Please sign in to comment.