Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabled lll linter for test packages #3117

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ issues:
- path: '_test.go'
linters:
- unparam # Tests might have unused function parameters.
- lll
- dupl
- nestif

Expand Down
72 changes: 69 additions & 3 deletions pkg/kopia/command/parse_command_output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}}
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be wrong, but it seems that this test will fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@julio-lopez let me resolve merge confllict

Copy link
Contributor Author

@anishbista60 anishbista60 Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@julio-lopez the changes that i made here is to log file and which will be changed every time . So, enabling this lll linter does not make sense. what do you think ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you run the test?

Copy link
Contributor Author

@anishbista60 anishbista60 Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you asking for Entire test cases or golint only? .Talking about linter test case, it has passed .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests as well, it looks like those are going to fail

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, make test went to failure .

ok  	github.com/kanisterio/kanister/pkg/virtualfs	0.011s
FAIL
real 360.99
user 0.05
sys 1.52
make[1]: *** [Makefile:217: run] Error 1
make[1]: Leaving directory '/home/anishbista/kanister'
make: *** [Makefile:165: go-test] Error 2

But honestly unable to figure out the reason behind it .
could you run the test cases here ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @anishbista60,

could you run the test cases here ?

If it's failing for you, it's going to fail for anyone else who tries to run the test.

But honestly unable to figure out the reason behind it .

do you need help figuring out why the test is failing? Do you understand what exactly the test is doing?

"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: check.IsNil,
expectedSnapID: "00000000000000000000001",
Expand All @@ -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: check.NotNil,
expectedSnapID: "",
expectedRootID: "",
Expand Down Expand Up @@ -701,7 +759,15 @@ func (kParse *KopiaParseUtilsTestSuite) TestErrorsFromOutput(c *check.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
Expand Down
67 changes: 60 additions & 7 deletions pkg/kopia/command/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,17 @@ func (kServer *KopiaServerTestSuite) TestServerCommands(c *check.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 {
Expand All @@ -77,7 +87,17 @@ func (kServer *KopiaServerTestSuite) TestServerCommands(c *check.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 {
Expand All @@ -95,7 +115,14 @@ func (kServer *KopiaServerTestSuite) TestServerCommands(c *check.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 {
Expand All @@ -113,7 +140,15 @@ func (kServer *KopiaServerTestSuite) TestServerCommands(c *check.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 {
Expand All @@ -133,7 +168,15 @@ func (kServer *KopiaServerTestSuite) TestServerCommands(c *check.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 {
Expand All @@ -146,7 +189,12 @@ func (kServer *KopiaServerTestSuite) TestServerCommands(c *check.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 {
Expand Down Expand Up @@ -220,7 +268,12 @@ func (kServer *KopiaServerTestSuite) TestServerCommands(c *check.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(), " ")
Expand Down
44 changes: 42 additions & 2 deletions pkg/restic/restic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,48 @@ func (s *ResticDataSuite) TestGetSnapshotIDFromTag(c *check.C) {
expected string
checker check.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: check.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: check.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: check.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: check.IsNil,
},
{log: `null`, expected: "", checker: check.NotNil},
} {
id, err := SnapshotIDFromSnapshotLog(tc.log)
Expand Down