-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from ghislainbourgeois/add-tests
chore: Add tests and standardize CI
- Loading branch information
Showing
9 changed files
with
217 additions
and
105 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
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" | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,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 ./... |
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,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) | ||
} | ||
} |