Fix LogURI generation-related tests on Windows.
Signed-off-by: Nashwan Azhari <nazhari@cloudbasesolutions.com>
This commit is contained in:
parent
72177ca663
commit
3f3e2b3cce
@ -81,46 +81,27 @@ func TestLogFileFailOnRelativePath(t *testing.T) {
|
|||||||
assert.Error(t, err, "absolute path needed")
|
assert.Error(t, err, "absolute path needed")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLogURIGenerator(t *testing.T) {
|
type LogURIGeneratorTestCase struct {
|
||||||
for _, tc := range []struct {
|
// Arbitrary scheme string (e.g. "binary")
|
||||||
scheme string
|
scheme string
|
||||||
|
// Path to executable/file: (e.g. "/some/path/to/bin.exe")
|
||||||
path string
|
path string
|
||||||
|
// Extra query args expected to be in the URL (e.g. "id=123")
|
||||||
args map[string]string
|
args map[string]string
|
||||||
|
// What the test case is expecting as an output (e.g. "binary:///some/path/to/bin.exe?id=123")
|
||||||
expected string
|
expected string
|
||||||
|
// Error string to be expected:
|
||||||
err string
|
err string
|
||||||
}{
|
}
|
||||||
{
|
|
||||||
scheme: "fifo",
|
func baseTestLogURIGenerator(t *testing.T, testCases []LogURIGeneratorTestCase) {
|
||||||
path: "/full/path/pipe.fifo",
|
for _, tc := range testCases {
|
||||||
expected: "fifo:///full/path/pipe.fifo",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
scheme: "file",
|
|
||||||
path: "/full/path/file.txt",
|
|
||||||
args: map[string]string{
|
|
||||||
"maxSize": "100MB",
|
|
||||||
},
|
|
||||||
expected: "file:///full/path/file.txt?maxSize=100MB",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
scheme: "binary",
|
|
||||||
path: "/full/path/bin",
|
|
||||||
args: map[string]string{
|
|
||||||
"id": "testing",
|
|
||||||
},
|
|
||||||
expected: "binary:///full/path/bin?id=testing",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
scheme: "unknown",
|
|
||||||
path: "nowhere",
|
|
||||||
err: "absolute path needed",
|
|
||||||
},
|
|
||||||
} {
|
|
||||||
uri, err := LogURIGenerator(tc.scheme, tc.path, tc.args)
|
uri, err := LogURIGenerator(tc.scheme, tc.path, tc.args)
|
||||||
if err != nil {
|
if tc.err != "" {
|
||||||
assert.Error(t, err, tc.err)
|
assert.ErrorContains(t, err, tc.err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, tc.expected, uri.String())
|
assert.Equal(t, tc.expected, uri.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,3 +209,40 @@ func initProducers(t *testing.T, producers producers, stdout, stderr string) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Nil(t, producers.Stderr.Close())
|
assert.Nil(t, producers.Stderr.Close())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLogURIGenerator(t *testing.T) {
|
||||||
|
baseTestLogURIGenerator(t, []LogURIGeneratorTestCase{
|
||||||
|
{
|
||||||
|
scheme: "fifo",
|
||||||
|
path: "/full/path/pipe.fifo",
|
||||||
|
expected: "fifo:///full/path/pipe.fifo",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scheme: "file",
|
||||||
|
path: "/full/path/file.txt",
|
||||||
|
args: map[string]string{
|
||||||
|
"maxSize": "100MB",
|
||||||
|
},
|
||||||
|
expected: "file:///full/path/file.txt?maxSize=100MB",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scheme: "binary",
|
||||||
|
path: "/full/path/bin",
|
||||||
|
args: map[string]string{
|
||||||
|
"id": "testing",
|
||||||
|
},
|
||||||
|
expected: "binary:///full/path/bin?id=testing",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scheme: "unknown",
|
||||||
|
path: "nowhere",
|
||||||
|
err: "must be absolute",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scheme: "binary",
|
||||||
|
path: "C:\\path\\to\\binary",
|
||||||
|
// NOTE: Windows paths should not be be parse-able outside of Windows:
|
||||||
|
err: "must be absolute",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -62,3 +62,50 @@ func TestLogFileBackslash(t *testing.T) {
|
|||||||
assert.Equal(t, "file:///C:/foo/bar.log", res.Config().Stdout)
|
assert.Equal(t, "file:///C:/foo/bar.log", res.Config().Stdout)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLogURIGenerator(t *testing.T) {
|
||||||
|
baseTestLogURIGenerator(t, []LogURIGeneratorTestCase{
|
||||||
|
{
|
||||||
|
scheme: "slashes",
|
||||||
|
path: "C:/full/path/pipe.fifo",
|
||||||
|
expected: "slashes:///C:/full/path/pipe.fifo",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scheme: "backslashes",
|
||||||
|
path: "C:\\full\\path\\pipe.fifo",
|
||||||
|
expected: "backslashes:///C:/full/path/pipe.fifo",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scheme: "mixedslashes",
|
||||||
|
path: "C:\\full/path/pipe.fifo",
|
||||||
|
expected: "mixedslashes:///C:/full/path/pipe.fifo",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scheme: "file",
|
||||||
|
path: "C:/full/path/file.txt",
|
||||||
|
args: map[string]string{
|
||||||
|
"maxSize": "100MB",
|
||||||
|
},
|
||||||
|
expected: "file:///C:/full/path/file.txt?maxSize=100MB",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scheme: "binary",
|
||||||
|
path: "C:/full/path/bin",
|
||||||
|
args: map[string]string{
|
||||||
|
"id": "testing",
|
||||||
|
},
|
||||||
|
expected: "binary:///C:/full/path/bin?id=testing",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scheme: "unknown",
|
||||||
|
path: "nowhere",
|
||||||
|
err: "must be absolute",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scheme: "unixpath",
|
||||||
|
path: "/some/unix/path",
|
||||||
|
// NOTE: Unix paths should not be usable on Windows:
|
||||||
|
err: "must be absolute",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user