Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sleep in UptimeRobot tests to get over free tier #594

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 39 additions & 29 deletions pkg/monitors/uptimerobot/uptime-monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package uptimerobot
import (
"strconv"
"testing"
"time"

endpointmonitorv1alpha1 "github.com/stakater/IngressMonitorController/v2/api/v1alpha1"
"github.com/stakater/IngressMonitorController/v2/pkg/config"
Expand Down Expand Up @@ -57,6 +58,7 @@ func TestAddMonitorWithCorrectValues(t *testing.T) {
m := models.Monitor{Name: "google-test", URL: "https://google.com"}
service.Add(m)

time.Sleep(time.Second * 20)
mRes, err := service.GetByName("google-test")

if err != nil {
Expand Down Expand Up @@ -84,6 +86,7 @@ func TestUpdateMonitorWithCorrectValues(t *testing.T) {
m := models.Monitor{Name: "google-test", URL: "https://google.com"}
service.Add(m)

time.Sleep(time.Second * 20)
mRes, err := service.GetByName("google-test")

if err != nil {
Expand Down Expand Up @@ -129,6 +132,7 @@ func TestAddMonitorWithInterval(t *testing.T) {
m := models.Monitor{Name: "google-test", URL: "https://google.com", Config: configInterval}
service.Add(m)

time.Sleep(time.Second * 20)
mRes, err := service.GetByName("google-test")

if err != nil {
Expand Down Expand Up @@ -165,6 +169,7 @@ func TestUpdateMonitorInterval(t *testing.T) {
m := models.Monitor{Name: "google-test", URL: "https://google.com", Config: configInterval}
service.Add(m)

time.Sleep(time.Second * 20)
mRes, err := service.GetByName("google-test")

if err != nil {
Expand Down Expand Up @@ -332,6 +337,7 @@ func TestAddMonitorWithMonitorType(t *testing.T) {
m := models.Monitor{Name: "google-test", URL: "https://google.com", Config: configKeyword}
service.Add(m)

time.Sleep(time.Second * 20)
mRes, err := service.GetByName("google-test")

if err != nil {
Expand Down Expand Up @@ -376,6 +382,7 @@ func TestAddMonitorWithIncorrectValues(t *testing.T) {
m := models.Monitor{Name: "google-test", URL: "https://google.com"}
service.Add(m)

time.Sleep(time.Second * 20)
mRes, err := service.GetByName("google-test")

if err != nil {
Expand All @@ -387,39 +394,42 @@ func TestAddMonitorWithIncorrectValues(t *testing.T) {
}
}

func TestAddMonitorWithAlertContacts(t *testing.T) {
config := config.GetControllerConfigTest()
// disabling this test since Free Tier UptimeRobot doesnt allow to add Alert Contacts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should have it as a toggle instead, depending on what version of UptimeRobot we use?

Copy link
Contributor Author

@MuneebAijaz MuneebAijaz May 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should have it as a toggle instead, depending on what version of UptimeRobot we use?

Actually, that cannot be verified because token is checked on runtime by the UptimeRobot website, about the access/tier the token has. so we will have to comment this test out for now


service := UpTimeMonitorService{}
provider := util.GetProviderWithName(config, "UptimeRobot")
if provider == nil {
return
}
service.Setup(*provider)
// func TestAddMonitorWithAlertContacts(t *testing.T) {
// config := config.GetControllerConfigTest()

configAlertContacts := &endpointmonitorv1alpha1.UptimeRobotConfig{
AlertContacts: "2628365_0_0",
}
// service := UpTimeMonitorService{}
// provider := util.GetProviderWithName(config, "UptimeRobot")
// if provider == nil {
// return
// }
// service.Setup(*provider)

m := models.Monitor{Name: "google-test", URL: "https://google.com", Config: configAlertContacts}
service.Add(m)
// configAlertContacts := &endpointmonitorv1alpha1.UptimeRobotConfig{
// AlertContacts: "2628365_0_0",
// }

mRes, err := service.GetByName("google-test")
// time.Sleep(time.Second * 20)
// m := models.Monitor{Name: "google-test", URL: "https://google.com", Config: configAlertContacts}
// service.Add(m)

if err != nil {
t.Error("Error: " + err.Error())
}
if mRes.Name != m.Name {
t.Error("The name is incorrect, expected: " + m.Name + ", but was: " + mRes.Name)
}
if mRes.URL != m.URL {
t.Error("The URL is incorrect, expected: " + m.URL + ", but was: " + mRes.URL)
}
// mRes, err := service.GetByName("google-test")

providerConfig, _ := mRes.Config.(*endpointmonitorv1alpha1.UptimeRobotConfig)
// if err != nil {
// t.Error("Error: " + err.Error())
// }
// if mRes.Name != m.Name {
// t.Error("The name is incorrect, expected: " + m.Name + ", but was: " + mRes.Name)
// }
// if mRes.URL != m.URL {
// t.Error("The URL is incorrect, expected: " + m.URL + ", but was: " + mRes.URL)
// }

if "2628365_0_0" != providerConfig.AlertContacts {
t.Error("The alert-contacts is incorrect, expected: 2628365_0_0, but was: " + providerConfig.AlertContacts)
}
service.Remove(*mRes)
}
// providerConfig, _ := mRes.Config.(*endpointmonitorv1alpha1.UptimeRobotConfig)

// if "2628365_0_0" != providerConfig.AlertContacts {
// t.Error("The alert-contacts is incorrect, expected: 2628365_0_0, but was: " + providerConfig.AlertContacts)
// }
// service.Remove(*mRes)
// }
Loading