]> ruderich.org/simon Gitweb - safcm/safcm.git/blob - cmd/safcm/sync_info_test.go
e01083bb8172b668c95c108fd113232899eff17b
[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         "reflect"
20         "testing"
21
22         "github.com/google/go-cmp/cmp"
23
24         "ruderich.org/simon/safcm"
25 )
26
27 func TestHostInfoRespToGroups(t *testing.T) {
28         tests := []struct {
29                 name string
30                 resp safcm.MsgInfoResp
31                 exp  []string
32         }{
33
34                 {
35                         "no output",
36                         safcm.MsgInfoResp{
37                                 Goos:   "linux",
38                                 Goarch: "amd64",
39                                 Output: nil,
40                         },
41                         []string{
42                                 "detected_linux",
43                                 "detected_amd64",
44                         },
45                 },
46
47                 {
48                         "output",
49                         safcm.MsgInfoResp{
50                                 Goos:   "linux",
51                                 Goarch: "amd64",
52                                 Output: []string{
53                                         "simple",
54                                         "with spaces",
55                                         "with UPPERcase",
56                                         "with UTF-8: Hello, 世界",
57                                 },
58                         },
59                         []string{
60                                 "detected_linux",
61                                 "detected_amd64",
62                                 "detected_simple",
63                                 "detected_with_spaces",
64                                 "detected_with_uppercase",
65                                 "detected_with_utf-8_hello_",
66                         },
67                 },
68         }
69
70         for _, tc := range tests {
71                 t.Run(tc.name, func(t *testing.T) {
72                         res := hostInfoRespToGroups(tc.resp)
73                         if !reflect.DeepEqual(tc.exp, res) {
74                                 t.Errorf("res: %s", cmp.Diff(tc.exp, res))
75                         }
76                 })
77         }
78 }