-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
65 lines (50 loc) · 1.44 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
56
57
58
59
60
61
62
63
64
65
package auth
import (
"log"
"os"
"testing"
"github.com/surahman/FTeX/pkg/logger"
"go.uber.org/zap"
)
// testAuth is the Authorization object.
var testAuth *authImpl
// authConfigTestData is a map of Authentication configuration test data.
var authConfigTestData = configTestData()
// expirationDuration is the time in seconds that a JWT will be valid for.
var expirationDuration int64 = 10
// refreshThreshold is the time in seconds before expiration that a JWT can be refreshed in.
var refreshThreshold int64 = 99
// zapLogger is the Zap logger used strictly for the test suite in this package.
var zapLogger *logger.Logger
func TestMain(m *testing.M) {
var err error
// Configure logger.
if zapLogger, err = logger.NewTestLogger(); err != nil {
log.Printf("Test suite logger setup failed: %v\n", err)
os.Exit(1)
}
// Setup test space.
if err = setup(); err != nil {
zapLogger.Error("Test suite setup failure", zap.Error(err))
os.Exit(1)
}
// Run test suite.
exitCode := m.Run()
// Cleanup test space.
if err = tearDown(); err != nil {
zapLogger.Error("Test suite teardown failure:", zap.Error(err))
os.Exit(1)
}
os.Exit(exitCode)
}
// setup will configure the auth test object.
//
//nolint:unparam
func setup() error {
testAuth = testConfigurationImpl(zapLogger, expirationDuration, refreshThreshold)
return nil
}
// tearDown will clean up any resources that need manual shutdown/deletion.
func tearDown() error {
return nil
}