Conversation
…orms via converting them to slash separated (unix style) path
…t supported on Windows
…upported on windows
…line split method for Windows
…platform agnostic
|
I did first set of fixes for tests on Windows. I had to touch some internal components. Please, review. |
logger/logger_test.go
Outdated
| SetupLogging(config) | ||
| log.Printf("E! TEST") | ||
| log.Printf("I! TEST") // <- should be ignored | ||
| log.Printf("I! TEST") // <- should be ignoredgo |
|
|
||
| tags1 := map[string]string{ | ||
| "path": "/", | ||
| "path": string(os.PathSeparator), |
There was a problem hiding this comment.
Tell me a bit about this, we aren't actually running the plugin on the filesystem right? Why do we need to modify the path separators?
There was a problem hiding this comment.
Generally, go filesystem related functions on Windows can take Unix style paths, but return Windows style (problem also for globpath).
And this line sets path with \.
There was a problem hiding this comment.
Ahh, can we use "path": filepath.Clean("/") for these?
There was a problem hiding this comment.
filepath.Clean("/") could the work, but seems a bit magic on the places when we need to construct a OS specific file path.
plugins/inputs/exec/exec.go
Outdated
| return nil, nil, fmt.Errorf("exec: unable to parse command, %s", err) | ||
| var split_cmd []string | ||
| var err error | ||
| //cannot use shellquote.Split on Windows as it threats Windows path separator char '\' as a mark for backslashed special char |
There was a problem hiding this comment.
Honestly, I love to remove shellquote completely and use a list of args on all platforms. That said I think this change has a high likelyhood of breaking existing config files.
I think instead we should skip associated failing tests in Windows and when -short is specified.
There was a problem hiding this comment.
I don't understand.
When I had discovered this problem I was wondering how can be that exec plugin actually works for anyone on Windows. Only condition it can work now is that there is no path in the command.
How this fix would break existing config files?
There was a problem hiding this comment.
How this fix would break existing config files?
It come down to:
I was wondering how can be that exec plugin actually works for anyone on Windows
Anyone on Windows using this probably has a very precise command string here with unix style quoting. If the behavior is changed in anyway, it will break their config. The only way this wouldn't be true is if this 100% can't work at all in Windows.
Separate from this PR, we could add a new array based command option, similar to the exec output.
testutil/testutil.go
Outdated
|
|
||
| func init() { | ||
| if runtime.GOOS == "windows" { | ||
| LineSeparator = "\r\n" |
There was a problem hiding this comment.
This isn't really a Windows vs Unix thing, it's more about file encoding or terminal setup. I'd like to fix this more close to the tests themselves, not have this a package level item. I'll try to give more explanation by the instances where it is used.
There was a problem hiding this comment.
In tests, it is the matter of git checkout behavior. Default setting on Windows is that text files are converted.
What about adding this line the .gitattributes:
**/testdata/** test eol=lf
I tested that and it works smooth. I could just revert all related changes. It seems to be the best solution for this.
Only downside is that people, mainly Windows developers, have to aware of this and do not count with CRLF. Luckily, there is just a few pure Windows tests and they don't deal with line endings.
internal/config/config_test.go
Outdated
| assert.Equal(t, internal.Size{Size: 1024 * 1024}, inputHTTPListener.MaxBodySize) | ||
| // Tests toml multiline basic strings. | ||
| assert.Equal(t, "/path/to/my/cert\n", inputHTTPListener.TLSCert) | ||
| assert.Equal(t, "/path/to/my/cert"+testutil.LineSeparator, inputHTTPListener.TLSCert) |
There was a problem hiding this comment.
We don't know what the line separator is, it depends on how git checked out the code. We should update this test to trim the string and then do the comparison. Elsewhere we should test that we can load a cert with either line ending.
There was a problem hiding this comment.
Actually I originally did trimming here. But than I encountered the one bellow and changed that this way.
internal/internal_test.go
Outdated
|
|
||
| assert.NoError(t, err) | ||
| assert.Equal(t, "foo\n", string(out)) | ||
| assert.Equal(t, "foo"+testutil.LineSeparator, string(out)) |
There was a problem hiding this comment.
I've mixed feelings on if these tests should just be deleted, but I see testing it proper would be a fair bit of work. We could instead run a command using the GO_WANT_HELPER_PROCESS method and then we can determine the line separator.
| hasMeta: hasMeta(path), | ||
| HasSuperMeta: hasSuperMeta(path), | ||
| path: filepath.FromSlash(path), | ||
| path: path, |
There was a problem hiding this comment.
Will this change the style of the paths returned? If so this could be a breaking change and we need to be very careful. Please double and triple check the changes in this file.
There was a problem hiding this comment.
With fixing other test I had to make additional changes. All the fixes lead to the state where paths are always compared in the same form (forward slash as a path separator). It will not change any path returned
…paths must be in the same form (with slash as a path separator)
…nting also CR char
…o CR char and comparing different MD5 sum
… dir and composing sock path using OS specific path separator char
…host by filtering IPv4 address
… OS specific error message
…s not for Windows
…l comparision as it can happen very fast
…ng pre-created sock file and skipping unixgram test as unixgram is not support on Windows
…Windows path to file URL
…th for file URL always to slash separated and skipping chmod on Windows
|
I continued fixing rest of the tests to know what issues are there, still without a clean way how to properly deal with line and paths separators. |
…ash forward separator
…command line split method for Windows" This reverts commit 046ed44
|
Can you also update the appveyor.yml to run more of the tests? |
|
Done. All the short tests run now. After discovering that Appveyor environment is bit different, mainly git is probably configured to do not convert line ending, I pushed proposed solution using a rule in main |
|
After #8414 has been closed, I think this can now be closed as well. |
Creating PR with intermediate fixes for various tests on Windows, reported in #3747, to validate fixes.
Required for all PRs: