]> ruderich.org/simon Gitweb - safcm/safcm.git/blob - cmd/safcm-remote/sync/triggers_test.go
27a0d022cf7ef6e1d2e3f32f900903c76655d789
[safcm/safcm.git] / cmd / safcm-remote / sync / triggers_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 sync
17
18 import (
19         "reflect"
20         "testing"
21
22         "github.com/google/go-cmp/cmp"
23 )
24
25 func TestTriggerPaths(t *testing.T) {
26         tests := []struct {
27                 name string
28                 path string
29                 exp  []string
30         }{
31
32                 {
33                         "root",
34                         "/",
35                         []string{"/"},
36                 },
37
38                 {
39                         "absolute path",
40                         "/foo/bar/baz",
41                         []string{"/", "/foo", "/foo/bar", "/foo/bar/baz"},
42                 },
43
44                 {
45                         "dot",
46                         ".",
47                         []string{"."},
48                 },
49
50                 {
51                         "relative path (for tests)",
52                         "foo/bar/baz",
53                         []string{".", "foo", "foo/bar", "foo/bar/baz"},
54                 },
55         }
56
57         for _, tc := range tests {
58                 res := triggerPaths(tc.path)
59                 if !reflect.DeepEqual(tc.exp, res) {
60                         t.Errorf("%s: res: %s", tc.name,
61                                 cmp.Diff(tc.exp, res))
62                 }
63         }
64 }