Browse Source

osutil: add unit tests

ᴜɴᴋɴᴡᴏɴ 5 years ago
parent
commit
1e7ed6f64f
2 changed files with 35 additions and 0 deletions
  1. 1 0
      go.mod
  2. 34 0
      internal/osutil/osutil_test.go

+ 1 - 0
go.mod

@@ -50,6 +50,7 @@ require (
 	github.com/sergi/go-diff v1.0.0
 	github.com/smartystreets/goconvey v1.6.4
 	github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect
+	github.com/stretchr/testify v1.4.0
 	github.com/unknwon/cae v1.0.0
 	github.com/unknwon/com v1.0.1
 	github.com/unknwon/i18n v0.0.0-20190805065654-5c6446a380b6

+ 34 - 0
internal/osutil/osutil_test.go

@@ -0,0 +1,34 @@
+// Copyright 2020 The Gogs Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package osutil
+
+import (
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func TestIsFile(t *testing.T) {
+	tests := []struct {
+		path   string
+		expVal bool
+	}{
+		{
+			path:   "osutil.go",
+			expVal: true,
+		}, {
+			path:   "../osutil",
+			expVal: false,
+		}, {
+			path:   "not_found",
+			expVal: false,
+		},
+	}
+	for _, test := range tests {
+		t.Run("", func(t *testing.T) {
+			assert.Equal(t, test.expVal, IsFile(test.path))
+		})
+	}
+}