-
Notifications
You must be signed in to change notification settings - Fork 1
/
health_test.go
41 lines (35 loc) · 949 Bytes
/
health_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
package main
import (
"net/http"
"testing"
"github.com/mjslabs/auth-plug/auth"
"github.com/mjslabs/auth-plug/internal/testlib"
"github.com/stretchr/testify/assert"
)
func TestMainHealth(t *testing.T) {
t.Run("Success", testMainHealthSuccess)
t.Run("Failure", testMainHealthFailure)
}
func testMainHealthSuccess(t *testing.T) {
setAuthCfgWithLDAPHost("success.com")
c, rec := testlib.EchoSetup(http.MethodPost, "/health", "")
err := healthGet(c)
assert.NoError(t, err)
assert.Equal(t, http.StatusOK, rec.Code)
}
func testMainHealthFailure(t *testing.T) {
setAuthCfgWithLDAPHost(testlib.LDAPHostFail)
c, rec := testlib.EchoSetup(http.MethodPost, "/health", "")
err := healthGet(c)
assert.Equal(t, http.StatusServiceUnavailable, rec.Code)
assert.NoError(t, err)
}
func setAuthCfgWithLDAPHost(host string) {
auth.Cfg = auth.Configuration{
Serv: auth.ServerAttributes{
Conn: testlib.MockLDAP{
Host: host,
},
},
}
}