-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d55ba43
commit 3440ac9
Showing
6 changed files
with
99 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package types | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestParseNET(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
input []byte | ||
expected *NET | ||
wantFail bool | ||
}{ | ||
{ | ||
name: "Simple long valid NET", | ||
input: []byte{ | ||
0x49, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Area (including AFI) | ||
0x01, 0x00, 0x00, 0x00, 0x00, 0x01, // SysID | ||
0x00, // SEL | ||
}, | ||
expected: &NET{ | ||
AreaID: []byte{ | ||
0x49, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
}, | ||
SystemID: SystemID{ | ||
0x01, 0x00, 0x00, 0x00, 0x00, 0x01, | ||
}, | ||
SEL: 0x00, | ||
}, | ||
}, | ||
{ | ||
name: "Simple short valid NET", | ||
input: []byte{ | ||
0x49, // Area (including AFI) | ||
0x01, 0x00, 0x00, 0x00, 0x00, 0x01, // SysID | ||
0x00, // SEL | ||
}, | ||
expected: &NET{ | ||
AreaID: []byte{ | ||
0x49, | ||
}, | ||
SystemID: SystemID{ | ||
0x01, 0x00, 0x00, 0x00, 0x00, 0x01, | ||
}, | ||
SEL: 0x00, | ||
}, | ||
}, | ||
{ | ||
name: "Too long NET", | ||
input: []byte{ | ||
0x49, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, // Area (including AFI) | ||
0x01, 0x00, 0x00, 0x00, 0x00, 0x01, // SysID | ||
0x00, // SEL | ||
}, | ||
wantFail: true, | ||
}, | ||
{ | ||
name: "Too short NET", | ||
input: []byte{ | ||
0x01, 0x00, 0x00, 0x00, 0x00, 0x01, // SysID | ||
0x00, // SEL | ||
}, | ||
wantFail: true, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
n, err := ParseNET([]byte(test.input)) | ||
if err != nil && !test.wantFail { | ||
t.Errorf("unexpected failure for test %q: %v", test.name, err) | ||
return | ||
} | ||
|
||
if err == nil && test.wantFail { | ||
t.Errorf("unexpected success for test %q", test.name) | ||
return | ||
} | ||
|
||
assert.Equal(t, test.expected, n, test.name) | ||
}) | ||
} | ||
} |
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