Skip to content

Commit

Permalink
restore l3_server port role... for now.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismarget-j committed Oct 7, 2024
1 parent 2cd1817 commit 5507508
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
5 changes: 5 additions & 0 deletions apstra/enum/enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand All @@ -245,6 +246,10 @@ var (
PortRoles = oenum.New(
PortRoleAccess,
PortRoleGeneric,
// todo: remove PortRoleL3Server. Then:
// - remove TestLogicalDevicePortRoles_SetAll
// - simplify LogicalDevicePortRoles.SetAll()
PortRoleL3Server,
PortRoleLeaf,
PortRolePeer,
PortRoleSpine,
Expand Down
11 changes: 10 additions & 1 deletion apstra/logical_device_port_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
18 changes: 18 additions & 0 deletions apstra/logical_device_port_roles_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 5507508

Please sign in to comment.