• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

heathcliff26 / go-wol / 17074718299

19 Aug 2025 03:44PM UTC coverage: 91.182% (-0.5%) from 91.71%
17074718299

Pull #86

github

web-flow
Merge 96103ab6b into 9946d24e0
Pull Request #86: Add address to host attributes

84 of 95 new or added lines in 8 files covered. (88.42%)

6 existing lines in 1 file now uncovered.

910 of 998 relevant lines covered (91.18%)

54.26 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.24
/pkg/server/storage/valkey/utils.go
1
package valkey
2

3
import (
4
        "fmt"
5
        "log/slog"
6
        "strings"
7

8
        "github.com/heathcliff26/go-wol/pkg/server/storage/types"
9
)
10

11
const (
12
        keyName    = "name"
13
        keyAddress = "address"
14
)
15

16
// serialize the Host so it can be stored as a single value in Valkey.
17
func serializeHost(host types.Host) string {
150✔
18
        result := fmt.Sprintf("%s=%s;", keyName, host.Name)
150✔
19
        if host.Address != "" {
159✔
20
                result += fmt.Sprintf("%s=%s;", keyAddress, host.Address)
9✔
21
        }
9✔
22
        return result
150✔
23
}
24

25
// Deserialize host back into it's parameters.
26
func deserializeHost(mac, data string) types.Host {
615✔
27
        keyvalues := strings.Split(data, ";")
615✔
28

615✔
29
        host := types.Host{
615✔
30
                MAC: mac,
615✔
31
        }
615✔
32

615✔
33
        // Maintain compatibility with older versions that only stored the name directly.
615✔
34
        if len(keyvalues) == 1 {
616✔
35
                host.Name = keyvalues[0]
1✔
36
                return host
1✔
37
        }
1✔
38

39
        for i, kv := range keyvalues {
1,944✔
40
                if i == len(keyvalues)-1 && kv == "" {
1,944✔
41
                        // Skip the last empty element if it exists
614✔
42
                        continue
614✔
43
                }
44

45
                pair := strings.SplitN(kv, "=", 2)
716✔
46
                if len(pair) != 2 {
716✔
NEW
47
                        slog.Warn("Received invalid host data from valkey, expected pairs key=value separated by semicolons", slog.String("data", data))
×
NEW
48
                        continue
×
49
                }
50
                switch pair[0] {
716✔
51
                case keyName:
614✔
52
                        host.Name = pair[1]
614✔
53
                case keyAddress:
102✔
54
                        host.Address = pair[1]
102✔
NEW
55
                default:
×
NEW
56
                        slog.Warn("Received unknown key in host data from valkey", slog.String("key", pair[0]), slog.String("data", data))
×
57
                }
58
        }
59
        return host
614✔
60
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc