forked from philips-software/logproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
55 lines (47 loc) · 1.48 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"net/http"
"os"
"testing"
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)
func TestMain(t *testing.T) {
assert.Equal(t, buildVersion, "v1.1.0-deadbeaf")
}
func TestListenString(t *testing.T) {
port := os.Getenv("PORT")
defer func() {
os.Setenv("PORT", port)
}()
os.Setenv("PORT", "")
s := listenString()
assert.Equal(t, s, ":8080")
os.Setenv("PORT", "1028")
s = listenString()
assert.Equal(t, s, ":1028")
}
func TestSetupPHLogger(t *testing.T) {
logger := log.New()
sharedKey := os.Getenv("HSDP_LOGINGESTOR_KEY")
sharedSecret := os.Getenv("HSDP_LOGINGESTOR_SECRET")
baseURL := os.Getenv("HSDP_LOGINGESTOR_URL")
productKey := os.Getenv("HSDP_LOGINGESTOR_PRODUCT_KEY")
os.Setenv("HSDP_LOGINGESTOR_KEY", sharedKey)
os.Setenv("HSDP_LOGINGESTOR_SECRET", sharedSecret)
os.Setenv("HSDP_LOGINGESTOR_URL", baseURL)
os.Setenv("HSDP_LOGINGESTOR_PRODUCT_KEY", productKey)
defer func() {
os.Setenv("HSDP_LOGINGESTOR_KEY", sharedKey)
os.Setenv("HSDP_LOGINGESTOR_SECRET", sharedSecret)
os.Setenv("HSDP_LOGINGESTOR_URL", baseURL)
os.Setenv("HSDP_LOGINGESTOR_PRODUCT_KEY", productKey)
}()
os.Setenv("HSDP_LOGINGESTOR_KEY", "foo")
os.Setenv("HSDP_LOGINGESTOR_SECRET", "bar")
os.Setenv("HSDP_LOGINGESTOR_URL", "http://localhost")
os.Setenv("HSDP_LOGINGESTOR_PRODUCT_KEY", "key")
phLogger, err := setupPHLogger(http.DefaultClient, logger)
assert.Nilf(t, err, "Expected setupPHLogger() to succeed: %v", err)
assert.NotNil(t, phLogger)
}