import (
"fmt"
+ "math"
"os"
"path/filepath"
"sort"
// Early entries have higher priorities
groupPriority := make(map[string]int)
for i, x := range s.config.GroupOrder {
- groupPriority[x] = i + 1
+ groupPriority[x] = math.MinInt32 + i + 1
}
// Host itself always has highest priority
- groupPriority[s.host.Name] = -1
+ groupPriority[s.host.Name] = math.MinInt32
// Sort groups after priority and name
sort.Slice(groups, func(i, j int) bool {
},
nil,
},
+
+ {
+ "group_order (single group)",
+ "project-group_order-single",
+ "host1.example.org",
+ nil,
+ safcm.LogDebug3,
+ safcm.MsgSyncReq{
+ Groups: []string{"all", "group-b", "group-a", "host1.example.org"},
+ Files: map[string]*safcm.File{
+ "/": {
+ Path: "/",
+ Mode: fs.ModeDir | 0755,
+ Uid: -1,
+ Gid: -1,
+ OrigGroup: "group-a",
+ },
+ "/file.txt": {
+ Path: "/file.txt",
+ Mode: 0644,
+ Uid: -1,
+ Gid: -1,
+ Data: []byte("file.txt: from group-a\n"),
+ OrigGroup: "group-a",
+ },
+ },
+ },
+ []string{
+ "host1.example.org: <nil> 3 host groups: all group-a group-b host1.example.org",
+ "host1.example.org: <nil> 3 host group priorities (desc. order): host1.example.org group-a",
+ },
+ nil,
+ },
}
for _, tc := range tests {