From 8e1b90b34471ed8b414f01f98c5978c6423cd2f8 Mon Sep 17 00:00:00 2001 From: Chris Marget Date: Thu, 11 Jan 2024 23:16:34 -0500 Subject: [PATCH] make port range last struct elements public --- apstra/two_stage_l3_clos_policies_test.go | 20 ++++++++++---------- apstra/two_stage_l3_clos_policy_rules.go | 12 ++++++------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/apstra/two_stage_l3_clos_policies_test.go b/apstra/two_stage_l3_clos_policies_test.go index be9451a3..dc572757 100644 --- a/apstra/two_stage_l3_clos_policies_test.go +++ b/apstra/two_stage_l3_clos_policies_test.go @@ -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() { @@ -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 } } @@ -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() @@ -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) } } diff --git a/apstra/two_stage_l3_clos_policy_rules.go b/apstra/two_stage_l3_clos_policy_rules.go index d2ccd621..b7308b10 100644 --- a/apstra/two_stage_l3_clos_policy_rules.go +++ b/apstra/two_stage_l3_clos_policy_rules.go @@ -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)) } } @@ -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