]> ruderich.org/simon Gitweb - safcm/safcm.git/blob - cmd/safcm/sync_info_test.go
Use SPDX license identifiers
[safcm/safcm.git] / cmd / safcm / sync_info_test.go
1 // SPDX-License-Identifier: GPL-3.0-or-later
2 // Copyright (C) 2021-2024  Simon Ruderich
3
4 package main
5
6 import (
7         "testing"
8
9         "ruderich.org/simon/safcm"
10         "ruderich.org/simon/safcm/testutil"
11 )
12
13 func TestHostInfoRespToGroups(t *testing.T) {
14         tests := []struct {
15                 name string
16                 resp safcm.MsgInfoResp
17                 exp  []string
18         }{
19
20                 {
21                         "no output",
22                         safcm.MsgInfoResp{
23                                 Goos:   "linux",
24                                 Goarch: "amd64",
25                                 Output: nil,
26                         },
27                         []string{
28                                 "detected_linux",
29                                 "detected_amd64",
30                         },
31                 },
32
33                 {
34                         "output",
35                         safcm.MsgInfoResp{
36                                 Goos:   "linux",
37                                 Goarch: "amd64",
38                                 Output: []string{
39                                         "simple",
40                                         " with spaces \t",
41                                         "with UPPERcase",
42                                         "with UTF-8: Hello, 世界",
43                                 },
44                         },
45                         []string{
46                                 "detected_linux",
47                                 "detected_amd64",
48                                 "detected_simple",
49                                 "detected_with_spaces",
50                                 "detected_with_uppercase",
51                                 "detected_with_utf-8_hello_",
52                         },
53                 },
54
55                 {
56                         "invalid goos/goarch",
57                         safcm.MsgInfoResp{
58                                 Goos:   " INVALID goos! ",
59                                 Goarch: "Hello, 世界",
60                                 Output: nil,
61                         },
62                         []string{
63                                 "detected_invalid_goos_",
64                                 "detected_hello_",
65                         },
66                 },
67         }
68
69         for _, tc := range tests {
70                 t.Run(tc.name, func(t *testing.T) {
71                         res := hostInfoRespToGroups(tc.resp)
72                         testutil.AssertEqual(t, "res", res, tc.exp)
73                 })
74         }
75 }