From 5507508d1f3021383a4155bccb5c8942f83f5984 Mon Sep 17 00:00:00 2001 From: Chris Marget Date: Mon, 7 Oct 2024 09:02:44 -0400 Subject: [PATCH] restore `l3_server` port role... for now. --- apstra/enum/enum.go | 5 +++++ apstra/logical_device_port_roles.go | 11 ++++++++++- apstra/logical_device_port_roles_unit_test.go | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/apstra/enum/enum.go b/apstra/enum/enum.go index 6e28e52..2a775b7 100644 --- a/apstra/enum/enum.go +++ b/apstra/enum/enum.go @@ -237,6 +237,7 @@ var ( _ enum = new(PortRole) PortRoleAccess = PortRole{Value: "access"} PortRoleGeneric = PortRole{Value: "generic"} + PortRoleL3Server = PortRole{Value: "l3_server"} // todo: remove this PortRoleLeaf = PortRole{Value: "leaf"} PortRolePeer = PortRole{Value: "peer"} PortRoleSpine = PortRole{Value: "spine"} @@ -245,6 +246,10 @@ var ( PortRoles = oenum.New( PortRoleAccess, PortRoleGeneric, + // todo: remove PortRoleL3Server. Then: + // - remove TestLogicalDevicePortRoles_SetAll + // - simplify LogicalDevicePortRoles.SetAll() + PortRoleL3Server, PortRoleLeaf, PortRolePeer, PortRoleSpine, diff --git a/apstra/logical_device_port_roles.go b/apstra/logical_device_port_roles.go index 3794c04..554353d 100644 --- a/apstra/logical_device_port_roles.go +++ b/apstra/logical_device_port_roles.go @@ -39,7 +39,16 @@ func (o *LogicalDevicePortRoles) FromStrings(in []string) error { } func (o *LogicalDevicePortRoles) SetAll() { - *o = enum.PortRoles.Members() + members := enum.PortRoles.Members() + for i, member := range members { + if member == enum.PortRoleL3Server { + members[i] = members[len(members)-1] + members = members[:len(members)-1] + } + } + + *o = members + o.Sort() } func (o *LogicalDevicePortRoles) Sort() { diff --git a/apstra/logical_device_port_roles_unit_test.go b/apstra/logical_device_port_roles_unit_test.go index 32885ad..b4199bc 100644 --- a/apstra/logical_device_port_roles_unit_test.go +++ b/apstra/logical_device_port_roles_unit_test.go @@ -108,3 +108,21 @@ func TestLogicalDevicePortRoles_Sort(t *testing.T) { }) } } + +func TestLogicalDevicePortRoles_SetAll(t *testing.T) { + var data apstra.LogicalDevicePortRoles + data.SetAll() + + expected := apstra.LogicalDevicePortRoles{ + enum.PortRoleAccess, + enum.PortRoleGeneric, + // enum.PortRoleL3Server, <---- TEST VALIDATES THAT THIS ONE IS OMITTED + enum.PortRoleLeaf, + enum.PortRolePeer, + enum.PortRoleSpine, + enum.PortRoleSuperspine, + enum.PortRoleUnused, + } + + require.Equal(t, expected, data) +}