osutil_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2020 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package osutil
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestIsFile(t *testing.T) {
  10. tests := []struct {
  11. path string
  12. expVal bool
  13. }{
  14. {
  15. path: "osutil.go",
  16. expVal: true,
  17. }, {
  18. path: "../osutil",
  19. expVal: false,
  20. }, {
  21. path: "not_found",
  22. expVal: false,
  23. },
  24. }
  25. for _, test := range tests {
  26. t.Run("", func(t *testing.T) {
  27. assert.Equal(t, test.expVal, IsFile(test.path))
  28. })
  29. }
  30. }
  31. func TestIsDir(t *testing.T) {
  32. tests := []struct {
  33. path string
  34. expVal bool
  35. }{
  36. {
  37. path: "osutil.go",
  38. expVal: false,
  39. }, {
  40. path: "../osutil",
  41. expVal: true,
  42. }, {
  43. path: "not_found",
  44. expVal: false,
  45. },
  46. }
  47. for _, test := range tests {
  48. t.Run("", func(t *testing.T) {
  49. assert.Equal(t, test.expVal, IsDir(test.path))
  50. })
  51. }
  52. }
  53. func TestIsExist(t *testing.T) {
  54. tests := []struct {
  55. path string
  56. expVal bool
  57. }{
  58. {
  59. path: "osutil.go",
  60. expVal: true,
  61. }, {
  62. path: "../osutil",
  63. expVal: true,
  64. }, {
  65. path: "not_found",
  66. expVal: false,
  67. },
  68. }
  69. for _, test := range tests {
  70. t.Run("", func(t *testing.T) {
  71. assert.Equal(t, test.expVal, IsExist(test.path))
  72. })
  73. }
  74. }
  75. func TestCurrentUsername(t *testing.T) {
  76. // Make sure it does not blow up
  77. CurrentUsername()
  78. }