]> ruderich.org/simon Gitweb - safcm/safcm.git/blob - cmd/safcm/sync_info_test.go
7ad13c9fd01084e6c54c9915cf418b9f9d57e663
[safcm/safcm.git] / cmd / safcm / sync_info_test.go
1 // Copyright (C) 2021  Simon Ruderich
2 //
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16 package main
17
18 import (
19         "testing"
20
21         "ruderich.org/simon/safcm"
22         "ruderich.org/simon/safcm/testutil"
23 )
24
25 func TestHostInfoRespToGroups(t *testing.T) {
26         tests := []struct {
27                 name string
28                 resp safcm.MsgInfoResp
29                 exp  []string
30         }{
31
32                 {
33                         "no output",
34                         safcm.MsgInfoResp{
35                                 Goos:   "linux",
36                                 Goarch: "amd64",
37                                 Output: nil,
38                         },
39                         []string{
40                                 "detected_linux",
41                                 "detected_amd64",
42                         },
43                 },
44
45                 {
46                         "output",
47                         safcm.MsgInfoResp{
48                                 Goos:   "linux",
49                                 Goarch: "amd64",
50                                 Output: []string{
51                                         "simple",
52                                         "with spaces",
53                                         "with UPPERcase",
54                                         "with UTF-8: Hello, 世界",
55                                 },
56                         },
57                         []string{
58                                 "detected_linux",
59                                 "detected_amd64",
60                                 "detected_simple",
61                                 "detected_with_spaces",
62                                 "detected_with_uppercase",
63                                 "detected_with_utf-8_hello_",
64                         },
65                 },
66         }
67
68         for _, tc := range tests {
69                 t.Run(tc.name, func(t *testing.T) {
70                         res := hostInfoRespToGroups(tc.resp)
71                         testutil.AssertEqual(t, "res", res, tc.exp)
72                 })
73         }
74 }