-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
70 lines (58 loc) · 1.84 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
66
67
68
69
70
package main
import (
"encoding/json"
"os"
"testing"
"time"
acmetest "github.com/cert-manager/cert-manager/test/acme"
"github.com/stretchr/testify/assert"
"github.com/saturncloud/cert-manager-webhook-httpreq/httpreq"
"github.com/saturncloud/cert-manager-webhook-httpreq/mock"
)
var (
zone = getEnvWithDefault("TEST_ZONE_NAME", "example.com.")
configFile = getEnvWithDefault("TEST_CONFIG_FILE", "testdata/httpreq/config.json")
)
func TestRunsSuite(t *testing.T) {
issuerConfig, err := loadIssuerConfig(configFile)
assert.NoError(t, err, "Exected no error from loading issuer config")
acmeOptions := []acmetest.Option{
acmetest.SetResolvedZone(zone),
acmetest.SetAllowAmbientCredentials(false),
}
if issuerConfig.Endpoint == "" {
mockEndpoint := mock.NewHTTPReqEndpoint()
defer mockEndpoint.Close()
acmeOptions = append(
acmeOptions,
acmetest.SetDNSServer(mockEndpoint.DNS().Addr()),
acmetest.SetUseAuthoritative(false),
acmetest.SetPropagationLimit(5*time.Second),
acmetest.SetPollInterval(200*time.Millisecond),
)
issuerConfig = httpreq.IssuerConfig{
Endpoint: mockEndpoint.URL(),
}
}
acmeOptions = append(acmeOptions, acmetest.SetConfig(issuerConfig))
fixture := acmetest.NewFixture(httpreq.New(), acmeOptions...)
//need to uncomment and RunConformance delete runBasic and runExtended once https://github.com/cert-manager/cert-manager/pull/4835 is merged
//fixture.RunConformance(t)
fixture.RunBasic(t)
fixture.RunExtended(t)
}
func loadIssuerConfig(file string) (issuerConfig httpreq.IssuerConfig, err error) {
f, err := os.Open(file)
if err != nil {
return issuerConfig, err
}
defer f.Close()
err = json.NewDecoder(f).Decode(&issuerConfig)
return issuerConfig, err
}
func getEnvWithDefault(name, defaultVal string) string {
if val, ok := os.LookupEnv(name); ok {
return val
}
return defaultVal
}