sink_windows_test.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright (c) 2022 Uber Technologies, Inc.
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files (the "Software"), to deal
  5. // in the Software without restriction, including without limitation the rights
  6. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. // copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be included in
  11. // all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. // THE SOFTWARE.
  20. //go:build windows
  21. package zap
  22. import (
  23. "os"
  24. "testing"
  25. "github.com/stretchr/testify/assert"
  26. )
  27. func TestWindowsPaths(t *testing.T) {
  28. // See https://docs.microsoft.com/en-us/dotnet/standard/io/file-path-formats
  29. tests := []struct {
  30. msg string
  31. path string
  32. }{
  33. {
  34. msg: "local path with drive",
  35. path: `c:\log.json`,
  36. },
  37. {
  38. msg: "local path with drive using forward slash",
  39. path: `c:/log.json`,
  40. },
  41. {
  42. msg: "local path without drive",
  43. path: `\Temp\log.json`,
  44. },
  45. {
  46. msg: "unc path",
  47. path: `\\Server2\Logs\log.json`,
  48. },
  49. }
  50. for _, tt := range tests {
  51. t.Run(tt.msg, func(t *testing.T) {
  52. sr := newSinkRegistry()
  53. openFilename := "<not called>"
  54. sr.openFile = func(filename string, _ int, _ os.FileMode) (*os.File, error) {
  55. openFilename = filename
  56. return nil, assert.AnError
  57. }
  58. _, err := sr.newSink(tt.path)
  59. assert.Equal(t, assert.AnError, err, "expect stub error from OpenFile")
  60. assert.Equal(t, tt.path, openFilename, "unexpected path opened")
  61. })
  62. }
  63. }