summaryrefslogtreecommitdiff
path: root/internal/logger/logger_test.go
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2020-03-07 00:46:26 -0800
committerStan Hu <stanhu@gmail.com>2020-03-10 00:41:24 -0700
commit488102039cb5e79114954ad91663ce28c99153c8 (patch)
tree808256b23022449477aa8e17ad3865ba6a3213b6 /internal/logger/logger_test.go
parentb920520599142435ce06ad155099544adc923618 (diff)
downloadgitlab-shell-sh-log-http-requests.tar.gz
Log internal HTTP requestssh-log-http-requests
This restores the previous behavior of logging the success and failures of internal HTTP requests. Part of https://gitlab.com/gitlab-org/gitlab/issues/207916
Diffstat (limited to 'internal/logger/logger_test.go')
-rw-r--r--internal/logger/logger_test.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/internal/logger/logger_test.go b/internal/logger/logger_test.go
new file mode 100644
index 0000000..e14d01c
--- /dev/null
+++ b/internal/logger/logger_test.go
@@ -0,0 +1,42 @@
+package logger
+
+import (
+ "io/ioutil"
+ "os"
+ "strings"
+ "testing"
+ "time"
+
+ log "github.com/sirupsen/logrus"
+ "github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitlab-shell/internal/config"
+)
+
+func TestConfigure(t *testing.T) {
+ tmpFile, err := ioutil.TempFile(os.TempDir(), "logtest-")
+ require.NoError(t, err)
+ defer tmpFile.Close()
+
+ config := config.Config{
+ LogFile: tmpFile.Name(),
+ LogFormat: "json",
+ }
+
+ err = Configure(&config)
+
+ require.NoError(t, err)
+
+ log.Info("this is a test")
+
+ tmpFile.Close()
+
+ data, err := ioutil.ReadFile(tmpFile.Name())
+ require.NoError(t, err)
+ require.True(t, strings.Contains(string(data), `msg":"this is a test"`))
+}
+
+func TestElapsedTime(t *testing.T) {
+ start := time.Now()
+ start = start.Add(1234567800 * time.Nanosecond)
+ require.InDelta(t, -1234.568, ElapsedTime(start), 0.01)
+}