aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Loibl <mail@matthiasloibl.com>2016-11-06 09:47:25 +0100
committerSandro Santilli <strk@kbt.io>2016-11-06 09:47:25 +0100
commitd318f612a9101625cba575a44428ced9d2aafa84 (patch)
tree0de17710686c9c4c49556d8c53596f917a768bdd
parent1cb5b0e2f608aa107b6a4d1fd7545268d85a643e (diff)
downloadgitea-d318f612a9101625cba575a44428ced9d2aafa84.tar.gz
gitea-d318f612a9101625cba575a44428ced9d2aafa84.zip
Add tests for CurrentUsername() (#88)
-rw-r--r--modules/user/user.go4
-rw-r--r--modules/user/user_test.go22
2 files changed, 23 insertions, 3 deletions
diff --git a/modules/user/user.go b/modules/user/user.go
index 4415632ee9..972629eae3 100644
--- a/modules/user/user.go
+++ b/modules/user/user.go
@@ -4,9 +4,7 @@
package user
-import (
- "os"
-)
+import "os"
func CurrentUsername() string {
curUserName := os.Getenv("USER")
diff --git a/modules/user/user_test.go b/modules/user/user_test.go
new file mode 100644
index 0000000000..d7df151531
--- /dev/null
+++ b/modules/user/user_test.go
@@ -0,0 +1,22 @@
+package user
+
+import (
+ "os"
+ "testing"
+)
+
+func TestCurrentUsername(t *testing.T) {
+ os.Setenv("USER", "")
+ os.Setenv("USERNAME", "foobar")
+
+ user := CurrentUsername()
+ if user != "foobar" {
+ t.Errorf("expected foobar as user, got: %s", user)
+ }
+
+ os.Setenv("USER", "gitea")
+ user = CurrentUsername()
+ if user != "gitea" {
+ t.Errorf("expected gitea as user, got: %s", user)
+ }
+}