Skip to content

Commit

Permalink
Add search domains to parseIPAM, add test:
Browse files Browse the repository at this point in the history
Search domains was missing from being parsed.
Some basic tests were added.

Signed-off-by: Jacob Weinstock <[email protected]>
  • Loading branch information
jacobweinstock committed Nov 23, 2024
1 parent b7f6251 commit 183d3f4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/iso/iso.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,13 @@ func parseIPAM(d *data.DHCP) string {

return ""
}()
ipam[7] = func() string {
if len(d.DomainSearch) > 0 {
return strings.Join(d.DomainSearch, ",")
}

return ""
}()
ipam[8] = func() string {
var ntp []string
for _, e := range d.NTPServers {
Expand Down
37 changes: 37 additions & 0 deletions internal/iso/iso_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net"
"net/http"
"net/http/httptest"
"net/netip"
"net/url"
"os"
"testing"
Expand Down Expand Up @@ -194,3 +195,39 @@ func (m *mockBackend) GetByIP(context.Context, net.IP) (*data.DHCP, *data.Netboo
}
return d, n, nil
}

func TestParseIPAM(t *testing.T) {
tests := map[string]struct {
input *data.DHCP
want string
}{
"empty": {},
"only MAC": {
input: &data.DHCP{MACAddress: net.HardwareAddr{0xde, 0xed, 0xbe, 0xef, 0xfe, 0xed}},
want: "ipam=de-ed-be-ef-fe-ed::::::::",
},
"everything": {
input: &data.DHCP{
MACAddress: net.HardwareAddr{0xde, 0xed, 0xbe, 0xef, 0xfe, 0xed},
IPAddress: netip.AddrFrom4([4]byte{127, 0, 0, 1}),
SubnetMask: net.IPv4Mask(255, 255, 255, 0),
DefaultGateway: netip.AddrFrom4([4]byte{127, 0, 0, 2}),
NameServers: []net.IP{{1, 1, 1, 1}, {4, 4, 4, 4}},
Hostname: "myhost",
NTPServers: []net.IP{{129,6,15,28}, {129,6,15,29}},
DomainSearch: []string{"example.com", "example.org"},
VLANID: "400",
},
want: "ipam=de-ed-be-ef-fe-ed:400:127.0.0.1:255.255.255.0:127.0.0.2:myhost:1.1.1.1,4.4.4.4:example.com,example.org:129.6.15.28,129.6.15.29",
},
}

for name, tt := range tests {
t.Run(name, func(t *testing.T) {
got := parseIPAM(tt.input)
if diff := cmp.Diff(tt.want, got); diff != "" {
t.Fatalf("diff: %v", diff)
}
})
}
}

0 comments on commit 183d3f4

Please sign in to comment.