Skip to content

Commit

Permalink
Test icingadb/v1.Address6Bin#Value()
Browse files Browse the repository at this point in the history
  • Loading branch information
Al2Klimov committed Sep 5, 2024
1 parent 2cab34c commit eda6366
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pkg/icingadb/v1/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,28 @@ func TestAddressBin_Value(t *testing.T) {
})
}
}

func TestAddress6Bin_Value(t *testing.T) {
ffff192020 := []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 192, 0, 2, 0}

subtests := []struct {
name string
input *Host
output driver.Value
}{
{name: "nil-host"},
{name: "invalid-address", input: &Host{Address: "invalid"}},
{"IPv6", &Host{Address6: "2001:db8::"}, []byte{32, 1, 13, 184, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
{name: "IPv4", input: &Host{Address6: "192.0.2.0"}, output: ffff192020},
{name: "ffff-IPv4", input: &Host{Address6: "::ffff:192.0.2.0"}, output: ffff192020},
}

for _, st := range subtests {
t.Run(st.name, func(t *testing.T) {
v, err := (Address6Bin{Host: st.input}).Value()

require.NoError(t, err)
require.Equal(t, st.output, v)
})
}
}

0 comments on commit eda6366

Please sign in to comment.