Skip to content

Commit

Permalink
make port range first/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 b7e1cb8 commit 8e01c83
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 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 @@ -45,7 +45,7 @@ func portRangeSlicesMatch(a, b []PortRange) bool {
}

for i := 0; i < len(a); i++ {
if a[i].first != b[i].first {
if a[i].First != b[i].First {
return false
}
if a[i].last != b[i].last {
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 @@ -126,8 +126,8 @@ func TestGetAllPolicies(t *testing.T) {
}

func comparePolicyPortRanges(a PortRange, aName string, b PortRange, bName string, t *testing.T) {
if a.first != b.first {
t.Fatalf("Policy Port Ranges 'first' field don't match: %s has %d, %s has %d", aName, a.first, bName, b.first)
if a.First != b.First {
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 {
Expand Down
14 changes: 7 additions & 7 deletions apstra/two_stage_l3_clos_policy_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@ var (
)

type PortRange struct {
first uint16
First uint16
last uint16
}

func (o PortRange) string() string {
switch {
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))
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 @@ -105,7 +105,7 @@ func (o rawPortRanges) parse() (PortRanges, error) {
return nil, fmt.Errorf("port spec '%s' falls outside of range %d-%d", raw, 0, math.MaxUint16)
}
result[i] = PortRange{
first: uint16(first),
First: uint16(first),
last: uint16(last),
}
}
Expand Down

0 comments on commit 8e01c83

Please sign in to comment.