99 lines
2.0 KiB
Go
99 lines
2.0 KiB
Go
package integration
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"gitea.pena/PenaDevops/smtpbiz-exporter/internal/client"
|
|
"gitea.pena/PenaDevops/smtpbiz-exporter/internal/models"
|
|
"testing"
|
|
)
|
|
|
|
const apiUrl = "https://api.smtp.bz/v1"
|
|
const apiKey = "8tv2xcsfCMBX3TCQxzgeeEwAEYyQrPUp0ggw"
|
|
|
|
func TestUserData(t *testing.T) {
|
|
smtp := client.NewSMTPClient(apiUrl, apiKey)
|
|
|
|
resp, err := smtp.UseGetMethod(models.UserDataEndpoint, map[string]interface{}{})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
fmt.Println(string(resp))
|
|
}
|
|
|
|
func TestUserStats(t *testing.T) {
|
|
smtp := client.NewSMTPClient(apiUrl, apiKey)
|
|
|
|
resp, err := smtp.UseGetMethod(models.UserStatsEndpoint, map[string]interface{}{})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
fmt.Println(string(resp))
|
|
}
|
|
|
|
func TestUserDomains(t *testing.T) {
|
|
smtp := client.NewSMTPClient(apiUrl, apiKey)
|
|
|
|
resp, err := smtp.UseGetMethod(models.UserDomainsEndpoint, map[string]interface{}{})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
fmt.Println(string(resp))
|
|
}
|
|
|
|
func TestUserIPs(t *testing.T) {
|
|
smtp := client.NewSMTPClient(apiUrl, apiKey)
|
|
|
|
resp, err := smtp.UseGetMethod(models.UserIPsEndpoint, map[string]interface{}{})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
fmt.Println(string(resp))
|
|
}
|
|
|
|
// todo рейтлимитер нужен я думаю
|
|
func TestLogMsg(t *testing.T) {
|
|
smtp := client.NewSMTPClient(apiUrl, apiKey)
|
|
|
|
limit := 50
|
|
offset := 0
|
|
var maxCount int64
|
|
|
|
for {
|
|
resp, err := smtp.UseGetMethod(models.LogMsgEndpoint, map[string]interface{}{
|
|
"limit": limit,
|
|
"offset": offset,
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
var result models.LogMsgResponse
|
|
err = json.Unmarshal(resp, &result)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
fmt.Println(result)
|
|
|
|
if maxCount == 0 {
|
|
maxCount = result.TotalCount
|
|
}
|
|
|
|
if int64(offset+limit) >= maxCount {
|
|
break
|
|
}
|
|
offset += limit
|
|
fmt.Println(offset)
|
|
}
|
|
}
|
|
|
|
func TestUnsubscribe(t *testing.T) {
|
|
smtp := client.NewSMTPClient(apiUrl, apiKey)
|
|
|
|
resp, err := smtp.UseGetMethod(models.UnsubscribeEndpoint, map[string]interface{}{})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
fmt.Println(string(resp))
|
|
}
|