Skip to content

Commit

Permalink
make port range last struct elements public
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismarget-j committed Jan 12, 2024
1 parent 8e01c83 commit 8e1b90b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
20 changes: 10 additions & 10 deletions apstra/two_stage_l3_clos_policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ func TestPortRangeString(t *testing.T) {
tests = append(tests, struct {
data PortRange
expected string
}{data: PortRange{First: 10, last: 10}, expected: "10"})
}{data: PortRange{First: 10, Last: 10}, expected: "10"})

tests = append(tests, struct {
data PortRange
expected string
}{data: PortRange{First: 10, last: 20}, expected: "10-20"})
}{data: PortRange{First: 10, Last: 20}, expected: "10-20"})

tests = append(tests, struct {
data PortRange
expected string
}{data: PortRange{First: 20, last: 10}, expected: "10-20"})
}{data: PortRange{First: 20, Last: 10}, expected: "10-20"})

for _, test := range tests {
if test.expected != test.data.string() {
Expand All @@ -48,7 +48,7 @@ func portRangeSlicesMatch(a, b []PortRange) bool {
if a[i].First != b[i].First {
return false
}
if a[i].last != b[i].last {
if a[i].Last != b[i].Last {
return false
}
}
Expand All @@ -64,22 +64,22 @@ func TestRawPortRangesParse(t *testing.T) {
tests = append(tests, struct {
data rawPortRanges
expected []PortRange
}{data: "10", expected: []PortRange{{First: 10, last: 10}}})
}{data: "10", expected: []PortRange{{First: 10, Last: 10}}})

tests = append(tests, struct {
data rawPortRanges
expected []PortRange
}{data: "10,11", expected: []PortRange{{First: 10, last: 10}, {First: 11, last: 11}}})
}{data: "10,11", expected: []PortRange{{First: 10, Last: 10}, {First: 11, Last: 11}}})

tests = append(tests, struct {
data rawPortRanges
expected []PortRange
}{data: "12,11", expected: []PortRange{{First: 12, last: 12}, {First: 11, last: 11}}})
}{data: "12,11", expected: []PortRange{{First: 12, Last: 12}, {First: 11, Last: 11}}})

tests = append(tests, struct {
data rawPortRanges
expected []PortRange
}{data: "10-11,12-13", expected: []PortRange{{First: 10, last: 11}, {First: 12, last: 13}}})
}{data: "10-11,12-13", expected: []PortRange{{First: 10, Last: 11}, {First: 12, Last: 13}}})

for i, test := range tests {
parsed, err := test.data.parse()
Expand Down Expand Up @@ -130,8 +130,8 @@ func comparePolicyPortRanges(a PortRange, aName string, b PortRange, bName strin
t.Fatalf("Policy Port Ranges 'first' field don't match: %s has %d, %s has %d", aName, a.First, bName, b.First)
}

if a.last != b.last {
t.Fatalf("Policy Port Ranges 'last' field don't match: %s has %d, %s has %d", aName, a.last, bName, b.last)
if a.Last != b.Last {
t.Fatalf("Policy Port Ranges 'last' field don't match: %s has %d, %s has %d", aName, a.Last, bName, b.Last)
}
}

Expand Down
12 changes: 6 additions & 6 deletions apstra/two_stage_l3_clos_policy_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ var (

type PortRange struct {
First uint16
last uint16
Last uint16
}

func (o PortRange) string() string {
switch {
case o.First == o.last:
case o.First == o.Last:
return strconv.Itoa(int(o.First))
case o.First < o.last:
return strconv.Itoa(int(o.First)) + portRangeSep + strconv.Itoa(int(o.last))
case o.First < o.Last:
return strconv.Itoa(int(o.First)) + portRangeSep + strconv.Itoa(int(o.Last))
default:
return strconv.Itoa(int(o.last)) + portRangeSep + strconv.Itoa(int(o.First))
return strconv.Itoa(int(o.Last)) + portRangeSep + strconv.Itoa(int(o.First))
}
}

Expand Down Expand Up @@ -106,7 +106,7 @@ func (o rawPortRanges) parse() (PortRanges, error) {
}
result[i] = PortRange{
First: uint16(first),
last: uint16(last),
Last: uint16(last),
}
}
return result, nil
Expand Down

0 comments on commit 8e1b90b

Please sign in to comment.