-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into candlerb/autoconfigure
- Loading branch information
Showing
8 changed files
with
111 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package dhcpv4 | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestOptIPAddressLeaseTime(t *testing.T) { | ||
o := OptIPAddressLeaseTime(43200 * time.Second) | ||
require.Equal(t, OptionIPAddressLeaseTime, o.Code, "Code") | ||
require.Equal(t, []byte{0, 0, 168, 192}, o.Value.ToBytes(), "ToBytes") | ||
require.Equal(t, "IP Addresses Lease Time: 12h0m0s", o.String(), "String") | ||
} | ||
|
||
func TestGetIPAddressLeaseTime(t *testing.T) { | ||
m, _ := New(WithGeneric(OptionIPAddressLeaseTime, []byte{0, 0, 168, 192})) | ||
leaseTime := m.IPAddressLeaseTime(0) | ||
require.Equal(t, 43200*time.Second, leaseTime) | ||
|
||
// Too short. | ||
m, _ = New(WithGeneric(OptionIPAddressLeaseTime, []byte{168, 192})) | ||
leaseTime = m.IPAddressLeaseTime(0) | ||
require.Equal(t, time.Duration(0), leaseTime) | ||
|
||
// Too long. | ||
m, _ = New(WithGeneric(OptionIPAddressLeaseTime, []byte{1, 1, 1, 1, 1})) | ||
leaseTime = m.IPAddressLeaseTime(0) | ||
require.Equal(t, time.Duration(0), leaseTime) | ||
|
||
// Empty. | ||
m, _ = New() | ||
require.Equal(t, time.Duration(10), m.IPAddressLeaseTime(10)) | ||
} | ||
|
||
func TestOptIPv6OnlyPreferred(t *testing.T) { | ||
o := OptIPv6OnlyPreferred(43200 * time.Second) | ||
require.Equal(t, OptionIPv6OnlyPreferred, o.Code, "Code") | ||
require.Equal(t, []byte{0, 0, 168, 192}, o.Value.ToBytes(), "ToBytes") | ||
require.Equal(t, "IPv6-Only Preferred: 12h0m0s", o.String(), "String") | ||
} | ||
|
||
func TestOptIPv6OnlyPreferredZero(t *testing.T) { | ||
o := OptIPv6OnlyPreferred(0) | ||
require.Equal(t, OptionIPv6OnlyPreferred, o.Code, "Code") | ||
require.Equal(t, []byte{0, 0, 0, 0}, o.Value.ToBytes(), "ToBytes") | ||
require.Equal(t, "IPv6-Only Preferred: 0s", o.String(), "String") | ||
} | ||
|
||
func TestGetIPv6OnlyPreferred(t *testing.T) { | ||
m, _ := New(WithGeneric(OptionIPv6OnlyPreferred, []byte{0, 0, 168, 192})) | ||
v6onlyWait, ok := m.IPv6OnlyPreferred() | ||
require.True(t, ok) | ||
require.Equal(t, 43200*time.Second, v6onlyWait) | ||
|
||
// Too short. | ||
m, _ = New(WithGeneric(OptionIPv6OnlyPreferred, []byte{168, 192})) | ||
_, ok = m.IPv6OnlyPreferred() | ||
require.False(t, ok) | ||
|
||
// Too long. | ||
m, _ = New(WithGeneric(OptionIPv6OnlyPreferred, []byte{1, 1, 1, 1, 1})) | ||
_, ok = m.IPv6OnlyPreferred() | ||
require.False(t, ok) | ||
|
||
// Missing. | ||
m, _ = New() | ||
_, ok = m.IPv6OnlyPreferred() | ||
require.False(t, ok) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters