forked from zerobounce/zerobouncego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
batch_validate_integration_t.go
46 lines (39 loc) · 1.47 KB
/
batch_validate_integration_t.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
package zerobounceindiago
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func EmailsToValidate() []EmailToValidate {
var batchEmails []EmailToValidate
for _, email_test := range emailsToValidate {
batchEmails = append(batchEmails, EmailToValidate{email_test.Email, SANDBOX_IP})
}
return batchEmails
}
// TestInvalidApiKey test expecting one error, relevant to invalid API key
func TestInvalidApiKey(t *testing.T) {
SetApiKey("some_invalid_value")
response, error_ := ValidateBatch(EmailsToValidate())
assert.Nil(t, error_)
assert.Len(t, response.EmailBatch, 0, "no email batch response was expected due to lack of valid API key")
assert.Len(t, response.Errors, 1, "errors were expected in response due to lack of valid API key")
assert.Equal(t, response.Errors[0].EmailAddress, "all")
}
func TestBulkEmailValidation(t *testing.T) {
ImportApiKeyFromEnvFile()
response, error_ := ValidateBatch(EmailsToValidate())
if error_ != nil {
fmt.Println(error_)
assert.Nil(t, error_)
}
emailToTest := make(map[string]SingleTest)
for _, single_test := range emailsToValidate {
emailToTest[single_test.Email] = single_test
}
for _, email_response := range response.EmailBatch {
test_details := emailToTest[email_response.Address]
assert.Equalf(t, email_response.Status, test_details.Status, "failed for email %s", email_response.Address)
assert.Equalf(t, email_response.SubStatus, test_details.SubStatus, "failed for email %s", email_response.Address)
}
}