diff --git a/.golangci.yml b/.golangci.yml index d1da516b18..0c73ba9e1c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -41,7 +41,6 @@ issues: - path: '_test.go' linters: - unparam # Tests might have unused function parameters. - - lll - dupl - nestif - gci diff --git a/pkg/kopia/command/parse_command_output_test.go b/pkg/kopia/command/parse_command_output_test.go index 67671e78c4..2455d0a5ef 100644 --- a/pkg/kopia/command/parse_command_output_test.go +++ b/pkg/kopia/command/parse_command_output_test.go @@ -121,7 +121,32 @@ func (kParse *KopiaParseUtilsTestSuite) TestSnapshotInfoFromSnapshotCreateOutput { output: `Snapshotting u2@h2:/tmp/aaa1 ... * 0 hashing, 1 hashed (2 B), 3 cached (4 B), uploaded 5 KB, estimating... - {"id":"00000000000000000000001","source":{"host":"h2","userName":"u2","path":"/tmp/aaa1"},"description":"","startTime":"2021-05-26T05:29:07.206854927Z","endTime":"2021-05-26T05:29:07.207328392Z","rootEntry":{"name":"aaa1","type":"d","mode":"0755","mtime":"2021-05-19T15:45:34.448853232Z","obj":"ka68ba7abe0818b24a2b0647aeeb02f29","summ":{"size":0,"files":1,"symlinks":0,"dirs":1,"maxTime":"2021-05-19T15:45:34.448853232Z","numFailed":0}}} + { + "id": "00000000000000000000001", + "source": { + "host": "h2", + "userName": "u2", + "path": "/tmp/aaa1" + }, + "description": "", + "startTime": "2021-05-26T05:29:07.206854927Z", + "endTime": "2021-05-26T05:29:07.207328392Z", + "rootEntry": { + "name": "aaa1", + "type": "d", + "mode": "0755", + "mtime": "2021-05-19T15:45:34.448853232Z", + "obj": "ka68ba7abe0818b24a2b0647aeeb02f29", + "summ": { + "size": 0, + "files": 1, + "symlinks": 0, + "dirs": 1, + "maxTime": "2021-05-19T15:45:34.448853232Z", + "numFailed": 0 + } + } + } `, checker: IsNil, expectedSnapID: "00000000000000000000001", @@ -143,7 +168,40 @@ func (kParse *KopiaParseUtilsTestSuite) TestSnapshotInfoFromSnapshotCreateOutput expectedRootID: "", }, { - output: `{"id":"1b6639b9797dc77dd4ddf57723918187","source":{"host":"da","userName":"kk","path":"/mnt/nfspvc"},"description":"","startTime":"2023-07-13T00:08:08.049239555Z","endTime":"2023-07-13T00:08:08.054904252Z","incomplete":"canceled","rootEntry":{"name":"nfspvc","type":"d","mode":"0755","mtime":"2023-07-11T20:33:41.386653643Z","obj":"k453085aaf775ecb9018a3fa8e276ca5d","summ":{"size":0,"files":0,"symlinks":0,"dirs":2,"maxTime":"2023-07-11T20:33:27.628326361Z","incomplete":"canceled","numFailed":1,"errors":[{"path":"for1001","error":"permission denied"}]}}}`, + output: `{ + "id": "1b6639b9797dc77dd4ddf57723918187", + "source": { + "host": "da", + "userName": "kk", + "path": "/mnt/nfspvc" + }, + "description": "", + "startTime": "2023-07-13T00:08:08.049239555Z", + "endTime": "2023-07-13T00:08:08.054904252Z", + "incomplete": "canceled", + "rootEntry": { + "name": "nfspvc", + "type": "d", + "mode": "0755", + "mtime": "2023-07-11T20:33:41.386653643Z", + "obj": "k453085aaf775ecb9018a3fa8e276ca5d", + "summ": { + "size": 0, + "files": 0, + "symlinks": 0, + "dirs": 2, + "maxTime": "2023-07-11T20:33:27.628326361Z", + "incomplete": "canceled", + "numFailed": 1, + "errors": [ + { + "path": "for1001", + "error": "permission denied" + } + ] + } + } + }`, checker: NotNil, expectedSnapID: "", expectedRootID: "", @@ -701,7 +759,15 @@ func (kParse *KopiaParseUtilsTestSuite) TestErrorsFromOutput(c *C) { // Some real error case {"ERROR open repository: repository is not connected. See https://kopia.io/docs/repositories/", []string{"open repository: repository is not connected. See https://kopia.io/docs/repositories/"}}, // The same as previous but with coloured ERROR word - {string([]byte{27, 91, 51, 49, 109, 69, 82, 82, 79, 82, 27, 91, 48, 109, 32, 111, 112, 101, 110, 32, 114, 101, 112, 111, 115, 105, 116, 111, 114, 121, 58, 32, 114, 101, 112, 111, 115, 105, 116, 111, 114, 121, 32, 105, 115, 32, 110, 111, 116, 32, 99, 111, 110, 110, 101, 99, 116, 101, 100, 46}), []string{"open repository: repository is not connected."}}, + { + string([]byte{ + 27, 91, 51, 49, 109, 69, 82, 82, 79, 82, 27, 91, 48, 109, 32, 111, 112, 101, 110, + 32, 114, 101, 112, 111, 115, 105, 116, 111, 114, 121, 58, 32, 114, 101, 112, 111, + 115, 105, 116, 111, 114, 121, 32, 105, 115, 32, 110, 111, 116, 32, 99, 111, 110, + 110, 101, 99, 116, 101, 100, 46, + }), + []string{"open repository: repository is not connected."}, + }, // Multiple error lines (seems not possible in real life, but just to cover this possibility) {"ERROR open repository: repository is not connected. See https://kopia.io/docs/repositories/\r\nERROR another error", []string{"open repository: repository is not connected. See https://kopia.io/docs/repositories/", "another error"}}, // Error surrounded by other output diff --git a/pkg/kopia/command/server_test.go b/pkg/kopia/command/server_test.go index 04e76e1dd1..ace89aee41 100644 --- a/pkg/kopia/command/server_test.go +++ b/pkg/kopia/command/server_test.go @@ -59,7 +59,17 @@ func (kServer *KopiaServerTestSuite) TestServerCommands(c *C) { } return ServerStart(args) }, - expectedLog: "bash -o errexit -c kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log server start --tls-generate-cert --address=a-server-address --tls-cert-file=/path/to/cert/tls.crt --tls-key-file=/path/to/key/tls.key --server-username=a-username@a-hostname --server-password=a-user-password --server-control-username=a-username@a-hostname --server-control-password=a-user-password --cache-directory=cache/dir --content-cache-size-limit-mb=500 --metadata-cache-size-limit-mb=500 --enable-pprof --metrics-listen-addr=a-server-address:51516 > /dev/null 2>&1 &", + expectedLog: "bash -o errexit -c " + + "kopia --log-level=error --config-file=path/kopia.config " + + "--log-dir=cache/log server start " + + "--tls-generate-cert --address=a-server-address " + + "--tls-cert-file=/path/to/cert/tls.crt --tls-key-file=/path/to/key/tls.key " + + "--server-username=a-username@a-hostname --server-password=a-user-password " + + "--server-control-username=a-username@a-hostname --server-control-password=a-user-password " + + "--cache-directory=cache/dir " + + "--content-cache-size-limit-mb=500 --metadata-cache-size-limit-mb=500 " + + "--enable-pprof --metrics-listen-addr=a-server-address:51516 " + + "> /dev/null 2>&1 &", }, { f: func() []string { @@ -77,7 +87,17 @@ func (kServer *KopiaServerTestSuite) TestServerCommands(c *C) { } return ServerStart(args) }, - expectedLog: "bash -o errexit -c kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log server start --tls-generate-cert --address=a-server-address --tls-cert-file=/path/to/cert/tls.crt --tls-key-file=/path/to/key/tls.key --server-username=a-username@a-hostname --server-password=a-user-password --server-control-username=a-username@a-hostname --server-control-password=a-user-password --cache-directory=cache/dir --content-cache-size-limit-mb=500 --metadata-cache-size-limit-mb=500 > /dev/null 2>&1 &", + expectedLog: "bash -o errexit -c kopia" + + "kopia --log-level=error --config-file=path/kopia.config " + + "--log-dir=cache/log server start " + + "--tls-generate-cert --address=a-server-address " + + "--tls-cert-file=/path/to/cert/tls.crt --tls-key-file=/path/to/key/tls.key " + + "--server-username=a-username@a-hostname --server-password=a-user-password " + + "--server-control-username=a-username@a-hostname --server-control-password=a-user-password " + + "--cache-directory=cache/dir " + + "--content-cache-size-limit-mb=500 --metadata-cache-size-limit-mb=500 " + + "--enable-pprof --metrics-listen-addr=a-server-address:51516 " + + "> /dev/null 2>&1 &", }, { f: func() []string { @@ -95,7 +115,14 @@ func (kServer *KopiaServerTestSuite) TestServerCommands(c *C) { } return ServerStart(args) }, - expectedLog: "bash -o errexit -c kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log server start --tls-generate-cert --address=a-server-address --tls-cert-file=/path/to/cert/tls.crt --tls-key-file=/path/to/key/tls.key --server-username=a-username@a-hostname --server-password=a-user-password --server-control-username=a-username@a-hostname --server-control-password=a-user-password --cache-directory=cache/dir --content-cache-size-limit-mb=500 --metadata-cache-size-limit-mb=500", + expectedLog: "bash -o errexit -c kopia --log-level=error --config-file=path/kopia.config " + + "--log-dir=cache/log server start " + + "--tls-generate-cert --address=a-server-address " + + "--tls-cert-file=/path/to/cert/tls.crt --tls-key-file=/path/to/key/tls.key " + + "--server-username=a-username@a-hostname --server-password=a-user-password " + + "--server-control-username=a-username@a-hostname --server-control-password=a-user-password " + + "--cache-directory=cache/dir " + + "--content-cache-size-limit-mb=500 --metadata-cache-size-limit-mb=500", }, { f: func() []string { @@ -113,7 +140,15 @@ func (kServer *KopiaServerTestSuite) TestServerCommands(c *C) { } return ServerStart(args) }, - expectedLog: "bash -o errexit -c kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log server start --address=a-server-address --tls-cert-file=/path/to/cert/tls.crt --tls-key-file=/path/to/key/tls.key --server-username=a-username@a-hostname --server-password=a-user-password --server-control-username=a-username@a-hostname --server-control-password=a-user-password --cache-directory=cache/dir --content-cache-size-limit-mb=500 --metadata-cache-size-limit-mb=500 > /dev/null 2>&1 &", + expectedLog: "bash -o errexit -c kopia --log-level=error --config-file=path/kopia.config " + + "--log-dir=cache/log server start " + + "--address=a-server-address " + + "--tls-cert-file=/path/to/cert/tls.crt --tls-key-file=/path/to/key/tls.key " + + "--server-username=a-username@a-hostname --server-password=a-user-password " + + "--server-control-username=a-username@a-hostname --server-control-password=a-user-password " + + "--cache-directory=cache/dir " + + "--content-cache-size-limit-mb=500 --metadata-cache-size-limit-mb=500 " + + "> /dev/null 2>&1 &", }, { f: func() []string { @@ -133,7 +168,15 @@ func (kServer *KopiaServerTestSuite) TestServerCommands(c *C) { } return ServerStart(args) }, - expectedLog: "bash -o errexit -c kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log server start --address=a-server-address --tls-cert-file=/path/to/cert/tls.crt --tls-key-file=/path/to/key/tls.key --htpasswd-file=/path/htpasswd --server-username=a-username@a-hostname --server-password=a-user-password --server-control-username=a-username@a-hostname --server-control-password=a-user-password --cache-directory=cache/dir --content-cache-size-limit-mb=500 --metadata-cache-size-limit-mb=500 --readonly > /dev/null 2>&1 &", + expectedLog: "bash -o errexit -c kopia --log-level=error --config-file=path/kopia.config " + + "--log-dir=cache/log server start " + + "--address=a-server-address " + + "--tls-cert-file=/path/to/cert/tls.crt --tls-key-file=/path/to/key/tls.key " + + "--server-username=a-username@a-hostname --server-password=a-user-password " + + "--server-control-username=a-username@a-hostname --server-control-password=a-user-password " + + "--cache-directory=cache/dir " + + "--content-cache-size-limit-mb=500 --metadata-cache-size-limit-mb=500 " + + "> /dev/null 2>&1 &", }, { f: func() []string { @@ -146,7 +189,12 @@ func (kServer *KopiaServerTestSuite) TestServerCommands(c *C) { } return ServerStatus(args) }, - expectedLog: "kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log server status --address=a-server-address --server-cert-fingerprint=a-fingerprint --server-username=a-username@a-hostname --server-password=a-user-password", + expectedLog: "kopia --log-level=error --config-file=path/kopia.config " + + "--log-dir=cache/log server status " + + "--address=a-server-address " + + "--server-cert-fingerprint=a-fingerprint " + + "--server-username=a-username@a-hostname " + + "--server-password=a-user-password", }, { f: func() []string { @@ -220,7 +268,12 @@ func (kServer *KopiaServerTestSuite) TestServerCommands(c *C) { } return ServerRefresh(args) }, - expectedLog: "kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log --password=encr-key server refresh --server-cert-fingerprint=a-fingerprint --address=a-server-address --server-username=a-username@a-hostname --server-password=a-user-password", + expectedLog: "kopia --log-level=error --config-file=path/kopia.config " + + "--log-dir=cache/log --password=encr-key " + + "server refresh --server-cert-fingerprint=a-fingerprint " + + "--address=a-server-address " + + "--server-username=a-username@a-hostname " + + "--server-password=a-user-password", }, } { cmd := strings.Join(tc.f(), " ") diff --git a/pkg/restic/restic_test.go b/pkg/restic/restic_test.go index b2e06985ca..c04fb4681a 100644 --- a/pkg/restic/restic_test.go +++ b/pkg/restic/restic_test.go @@ -38,8 +38,48 @@ func (s *ResticDataSuite) TestGetSnapshotIDFromTag(c *C) { expected string checker Checker }{ - {log: `[{"time":"2019-03-28T17:35:15.146526-07:00","hostname":"MacBook-Pro.local","username":"abc","uid":501,"gid":20,"tags":["backup123"],"id":"7c0bfeb93dd5b390a6eaf8a386ec8cb86e4631f2d96400407b529b53d979536a","short_id":"7c0bfeb9"}]`, expected: "7c0bfeb9", checker: IsNil}, - {log: `[{"time":"2019-03-28T17:35:15.146526-07:00","hostname":"MacBook-Pro.local","username":"abc","uid":501,"gid":20,"tags":["backup123"],"id":"7c0bfeb93dd5b390a6eaf8a386ec8cb86e4631f2d96400407b529b53d979536a","short_id":"7c0bfeb9"},{"time":"2019-03-28T17:35:15.146526-07:00","hostname":"MacBook-Pro.local","username":"abc","uid":501,"gid":20,"tags":["backup123"],"id":"7c0bfeb93dd5b390a6eaf8a386ec8cb86e4631f2d96400407b529b53d979536a","short_id":"7c0bfeb9"}]`, expected: "7c0bfeb9", checker: IsNil}, + { + log: `[ + { + "time": "2019-03-28T17:35:15.146526-07:00", + "hostname": "MacBook-Pro.local", + "username": "abc", + "uid": 501, + "gid": 20, + "tags": ["backup123"], + "id": "7c0bfeb93dd5b390a6eaf8a386ec8cb86e4631f2d96400407b529b53d979536a", + "short_id": "7c0bfeb9" + } + ]`, + expected: "7c0bfeb9", + checker: IsNil, + }, + { + log: `[ + { + "time": "2019-03-28T17:35:15.146526-07:00", + "hostname": "MacBook-Pro.local", + "username": "abc", + "uid": 501, + "gid": 20, + "tags": ["backup123"], + "id": "7c0bfeb93dd5b390a6eaf8a386ec8cb86e4631f2d96400407b529b53d979536a", + "short_id": "7c0bfeb9" + }, + { + "time": "2019-03-28T17:35:15.146526-07:00", + "hostname": "MacBook-Pro.local", + "username": "abc", + "uid": 501, + "gid": 20, + "tags": ["backup123"], + "id": "7c0bfeb93dd5b390a6eaf8a386ec8cb86e4631f2d96400407b529b53d979536a", + "short_id": "7c0bfeb9" + } + ]`, + expected: "7c0bfeb9", + checker: IsNil, + }, {log: `null`, expected: "", checker: NotNil}, } { id, err := SnapshotIDFromSnapshotLog(tc.log)