-
Notifications
You must be signed in to change notification settings - Fork 1
/
ssl_test.go
77 lines (67 loc) · 1.74 KB
/
ssl_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
71
72
73
74
75
76
77
package paymail
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestClient_CheckSSL will test the method CheckSSL()
func TestClient_CheckSSL(t *testing.T) {
// t.Parallel() cannot use newTestClient() race condition
// Integration test (requires internet connection)
if testing.Short() {
t.Skip("skipping integration testing in short mode")
}
client := newTestClient(t)
t.Run("valid ssl certs", func(t *testing.T) {
var tests = []struct {
host string
}{
{"google.com"},
{"mrz1818.com"},
}
for _, test := range tests {
t.Run("checking: "+test.host, func(t *testing.T) {
valid, err := client.CheckSSL(test.host)
require.NoError(t, err)
assert.Equal(t, true, valid)
})
}
})
t.Run("invalid ssl certs", func(t *testing.T) {
var tests = []struct {
host string
}{
{"google"},
{""},
{"domaindoesntexistatall101910.co"},
}
for _, test := range tests {
t.Run("checking: "+test.host, func(t *testing.T) {
valid, err := client.CheckSSL(test.host)
require.Error(t, err)
assert.Equal(t, false, valid)
})
}
})
}
// ExampleClient_CheckSSL example using CheckSSL()
//
// See more examples in /examples/
func ExampleClient_CheckSSL() {
client, _ := NewClient()
valid, _ := client.CheckSSL("google.com")
if valid {
fmt.Printf("valid SSL certificate found for: %s", "google.com")
} else {
fmt.Printf("invalid SSL certificate found for: %s", "google.com")
}
// Output:valid SSL certificate found for: google.com
}
// BenchmarkClient_CheckSSL benchmarks the method CheckSSL()
func BenchmarkClient_CheckSSL(b *testing.B) {
client, _ := NewClient(nil, nil, nil)
for i := 0; i < b.N; i++ {
_, _ = client.CheckSSL("google.com")
}
}