aboutsummaryrefslogtreecommitdiff
path: root/wakeonlan/wakeonlan_test.go
blob: 82d6ab8c97651fb4eab39df2d76c2bc0b96282c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// SPDX-FileCopyrightText: 2020 Ethel Morgan
//
// SPDX-License-Identifier: MIT

package wakeonlan

import (
	"encoding/hex"
	"net"
	"reflect"
	"testing"
)

func TestPacket(t *testing.T) {
	tests := []struct {
		mac    string
		packet string
	}{
		{
			"a8:23:22:ad:be:c7",
			"ffffffffffffa82322adbec7a82322adbec7a82322adbec7a82322adbec7a82322adbec7a82322adbec7a82322adbec7a82322adbec7a82322adbec7a82322adbec7a82322adbec7a82322adbec7a82322adbec7a82322adbec7a82322adbec7a82322adbec7",
		},
	}

	for i, test := range tests {
		mac, err := net.ParseMAC(test.mac)
		if err != nil {
			t.Fatalf("invalid MAC address %q: %v", test.mac, err)
		}

		if len(test.packet) != 102 {
			if err != nil {
				t.Fatalf("invalid packet length address: found %v, want 102", len(test.packet))
			}
		}
		want, err := hex.DecodeString(test.packet)
		if err != nil {
			t.Fatalf("invalid hex string: %v", err)
		}

		got := packet(mac)
		if !reflect.DeepEqual(want, got) {
			t.Errorf("[test %d]\nwanted %v\nlen %d\ngot %v\nlen %d", i, want, len(want), got, len(got))
		}
	}
}