-
Notifications
You must be signed in to change notification settings - Fork 11
/
enclave_test.go
64 lines (55 loc) · 1.3 KB
/
enclave_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
package main
import (
"testing"
)
var defaultCfg = Config{
FQDN: "example.com",
ExtPubPort: 50000,
ExtPrivPort: 50001,
IntPort: 50002,
HostProxyPort: 1024,
UseACME: false,
Debug: true,
FdCur: 1024,
FdMax: 4096,
WaitForApp: true,
}
func assertEqual(t *testing.T, is, should interface{}) {
t.Helper()
if should != is {
t.Fatalf("Expected value\n%v\nbut got\n%v", should, is)
}
}
func createEnclave(cfg *Config) *Enclave {
e, err := NewEnclave(cfg)
if err != nil {
panic(err)
}
return e
}
func TestValidateConfig(t *testing.T) {
var err error
var c Config
if err = c.Validate(); err == nil {
t.Fatalf("Validation of invalid config did not return an error.")
}
// Set one required field but leave others unset.
c.FQDN = "example.com"
if err = c.Validate(); err == nil {
t.Fatalf("Validation of invalid config did not return an error.")
}
// Set the remaining required fields.
c.ExtPubPort = 1
c.ExtPrivPort = 1
c.IntPort = 1
c.HostProxyPort = 1
if err = c.Validate(); err != nil {
t.Fatalf("Validation of valid config returned an error.")
}
}
func TestGenSelfSignedCert(t *testing.T) {
e := createEnclave(&defaultCfg)
if err := e.genSelfSignedCert(); err != nil {
t.Fatalf("Failed to create self-signed certificate: %s", err)
}
}