]> ruderich.org/simon Gitweb - safcm/safcm.git/blobdiff - cmd/safcm/sync_sync_test.go
Use SPDX license identifiers
[safcm/safcm.git] / cmd / safcm / sync_sync_test.go
index 40c5c556eccd5961513abe52c4671ed467a6b7db..614b5b0c72254dc17240db2a5e6888d9d355547e 100644 (file)
@@ -1,17 +1,5 @@
-// Copyright (C) 2021  Simon Ruderich
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+// SPDX-License-Identifier: GPL-3.0-or-later
+// Copyright (C) 2021-2024  Simon Ruderich
 
 package main
 
@@ -33,7 +21,7 @@ func TestHostSyncReq(t *testing.T) {
        if err != nil {
                t.Fatal(err)
        }
-       defer os.Chdir(cwd)
+       defer os.Chdir(cwd) //nolint:errcheck
 
        tests := []struct {
                name      string
@@ -62,8 +50,9 @@ func TestHostSyncReq(t *testing.T) {
                                        "host1.example.org",
                                },
                                Files: map[string]*safcm.File{
-                                       "/": &safcm.File{Path: "/",
+                                       "/": {
                                                OrigGroup: "group",
+                                               Path:      "/",
                                                Mode:      fs.ModeDir | 0755 | fs.ModeSetgid,
                                                Uid:       -1,
                                                Gid:       -1,
@@ -71,14 +60,14 @@ func TestHostSyncReq(t *testing.T) {
                                                        "touch /.update",
                                                },
                                        },
-                                       "/etc": &safcm.File{
+                                       "/etc": {
                                                OrigGroup: "group",
                                                Path:      "/etc",
                                                Mode:      fs.ModeDir | 0755,
                                                Uid:       -1,
                                                Gid:       -1,
                                        },
-                                       "/etc/.hidden": &safcm.File{
+                                       "/etc/.hidden": {
                                                OrigGroup: "group",
                                                Path:      "/etc/.hidden",
                                                Mode:      0100 | fs.ModeSetuid | fs.ModeSetgid | fs.ModeSticky,
@@ -86,7 +75,7 @@ func TestHostSyncReq(t *testing.T) {
                                                Gid:       -1,
                                                Data:      []byte("..."),
                                        },
-                                       "/etc/motd": &safcm.File{
+                                       "/etc/motd": {
                                                OrigGroup: "group",
                                                Path:      "/etc/motd",
                                                Mode:      0644,
@@ -94,7 +83,7 @@ func TestHostSyncReq(t *testing.T) {
                                                Gid:       -1,
                                                Data:      []byte("Welcome to Host ONE\n\n\n\n\n\nall\n\n\nhost1.example.org\n\n\n\n"),
                                        },
-                                       "/etc/rc.local": &safcm.File{
+                                       "/etc/rc.local": {
                                                OrigGroup: "group",
                                                Path:      "/etc/rc.local",
                                                Mode:      0700,
@@ -105,7 +94,7 @@ func TestHostSyncReq(t *testing.T) {
                                                        "/etc/rc.local",
                                                },
                                        },
-                                       "/etc/resolv.conf": &safcm.File{
+                                       "/etc/resolv.conf": {
                                                OrigGroup: "group",
                                                Path:      "/etc/resolv.conf",
                                                Mode:      0641,
@@ -118,7 +107,7 @@ func TestHostSyncReq(t *testing.T) {
                                                        "echo resolv.conf updated",
                                                },
                                        },
-                                       "/etc/test": &safcm.File{
+                                       "/etc/test": {
                                                OrigGroup: "group",
                                                Path:      "/etc/test",
                                                Mode:      os.ModeSymlink | 0777,
@@ -225,26 +214,26 @@ func TestHostSyncReq(t *testing.T) {
                                Groups: []string{"all", "group-b", "group-a", "host1.example.org"},
                                Files: map[string]*safcm.File{
                                        "/": {
+                                               OrigGroup: "host1.example.org",
                                                Path:      "/",
                                                Mode:      fs.ModeDir | 0755,
                                                Uid:       -1,
                                                Gid:       -1,
-                                               OrigGroup: "host1.example.org",
                                        },
                                        "/etc": {
+                                               OrigGroup: "host1.example.org",
                                                Path:      "/etc",
                                                Mode:      fs.ModeDir | 0755,
                                                Uid:       -1,
                                                Gid:       -1,
-                                               OrigGroup: "host1.example.org",
                                        },
                                        "/etc/dir-to-file": {
+                                               OrigGroup: "group-a",
                                                Path:      "/etc/dir-to-file",
                                                Mode:      0644,
                                                Uid:       -1,
                                                Gid:       -1,
                                                Data:      []byte("dir-to-file: from group-a\n"),
-                                               OrigGroup: "group-a",
                                        },
                                        "/etc/dir-to-filex": {
                                                OrigGroup: "group-b",
@@ -255,12 +244,12 @@ func TestHostSyncReq(t *testing.T) {
                                                Data:      []byte("dir-to-filex\n"),
                                        },
                                        "/etc/dir-to-link": {
+                                               OrigGroup: "group-a",
                                                Path:      "/etc/dir-to-link",
                                                Mode:      fs.ModeSymlink | 0777,
                                                Uid:       -1,
                                                Gid:       -1,
                                                Data:      []byte("target"),
-                                               OrigGroup: "group-a",
                                        },
                                        "/etc/dir-to-linkx": {
                                                OrigGroup: "group-b",
@@ -271,42 +260,42 @@ func TestHostSyncReq(t *testing.T) {
                                                Data:      []byte("dir-to-linkx\n"),
                                        },
                                        "/etc/file-to-dir": {
+                                               OrigGroup: "group-a",
                                                Path:      "/etc/file-to-dir",
                                                Mode:      fs.ModeDir | 0755,
                                                Uid:       -1,
                                                Gid:       -1,
-                                               OrigGroup: "group-a",
                                        },
                                        "/etc/file-to-dir/file": {
+                                               OrigGroup: "group-a",
                                                Path:      "/etc/file-to-dir/file",
                                                Mode:      0644,
                                                Uid:       -1,
                                                Gid:       -1,
                                                Data:      []byte("file: from group-a\n"),
-                                               OrigGroup: "group-a",
                                        },
                                        "/etc/file-to-dir/dir": {
+                                               OrigGroup: "group-a",
                                                Path:      "/etc/file-to-dir/dir",
                                                Mode:      fs.ModeDir | 0755,
                                                Uid:       -1,
                                                Gid:       -1,
-                                               OrigGroup: "group-a",
                                        },
                                        "/etc/file-to-dir/dir/file2": {
+                                               OrigGroup: "group-a",
                                                Path:      "/etc/file-to-dir/dir/file2",
                                                Mode:      0644,
                                                Uid:       -1,
                                                Gid:       -1,
                                                Data:      []byte("file2: from group-a\n"),
-                                               OrigGroup: "group-a",
                                        },
                                        "/etc/motd": {
+                                               OrigGroup: "host1.example.org",
                                                Path:      "/etc/motd",
                                                Mode:      0644,
                                                Uid:       -1,
                                                Gid:       -1,
                                                Data:      []byte("motd: from host1\n"),
-                                               OrigGroup: "host1.example.org",
                                        },
                                },
                        },
@@ -328,19 +317,19 @@ func TestHostSyncReq(t *testing.T) {
                                Groups: []string{"all", "group-b", "group-a", "host1.example.org"},
                                Files: map[string]*safcm.File{
                                        "/": {
+                                               OrigGroup: "group-a",
                                                Path:      "/",
                                                Mode:      fs.ModeDir | 0755,
                                                Uid:       -1,
                                                Gid:       -1,
-                                               OrigGroup: "group-a",
                                        },
                                        "/file.txt": {
+                                               OrigGroup: "group-a",
                                                Path:      "/file.txt",
                                                Mode:      0644,
                                                Uid:       -1,
                                                Gid:       -1,
                                                Data:      []byte("file.txt: from group-a\n"),
-                                               OrigGroup: "group-a",
                                        },
                                },
                        },