github.com/stakater/IngressMonitorController@v1.0.103/pkg/monitors/gcloud/gcloud-monitor_test.go (about) 1 package gcloud 2 3 import ( 4 "testing" 5 6 log "github.com/sirupsen/logrus" 7 8 "github.com/stakater/IngressMonitorController/pkg/config" 9 "github.com/stakater/IngressMonitorController/pkg/models" 10 "github.com/stakater/IngressMonitorController/pkg/util" 11 ) 12 13 func TestAddMonitorWithCorrectValues(t *testing.T) { 14 config := config.GetControllerConfig() 15 16 service := MonitorService{} 17 provider := util.GetProviderWithName(config, "gcloud") 18 if provider == nil { 19 // TODO: Currently forcing to pass the test as we dont have gcloud account to test 20 // Fail this case in future when have a valid gcloud account 21 log.Error("Failed to find provider") 22 return 23 } 24 service.Setup(*provider) 25 m := models.Monitor{Name: "google-test", URL: "https://google1.com/"} 26 service.Add(m) 27 28 mRes, err := service.GetByName("google-test") 29 30 if err != nil { 31 t.Error("Error: " + err.Error()) 32 } 33 if mRes.Name != m.Name || mRes.URL != m.URL { 34 t.Error("URL and name should be the same") 35 } 36 37 var inList = false 38 for _, monitorInList := range service.GetAll() { 39 if monitorInList.Name != m.Name { 40 continue 41 } 42 inList = true 43 } 44 if !inList { 45 t.Error("Monitor should've been in list ") 46 } 47 48 service.Remove(*mRes) 49 monitor, err := service.GetByName(mRes.Name) 50 51 if monitor != nil { 52 t.Error("Monitor should've been deleted ", monitor, err) 53 } 54 } 55 56 func TestUpdateMonitorWithCorrectValues(t *testing.T) { 57 config := config.GetControllerConfig() 58 59 service := MonitorService{} 60 61 provider := util.GetProviderWithName(config, "gcloud") 62 if provider == nil { 63 // TODO: Currently forcing to pass the test as we dont have gcloud account to test 64 // Fail this case in future when have a valid gcloud account 65 log.Error("Failed to find provider") 66 return 67 } 68 service.Setup(*provider) 69 70 m := models.Monitor{Name: "google-test", URL: "https://google.com/"} 71 service.Add(m) 72 73 mRes, err := service.GetByName("google-test") 74 75 if err != nil { 76 t.Error("Error: " + err.Error()) 77 } 78 if mRes.Name != m.Name || mRes.URL != m.URL { 79 t.Error("URL and name should be the same") 80 } 81 82 mRes.Name = "google-test2" 83 mRes.URL = "https://google.com/test" 84 85 service.Update(*mRes) 86 87 mRes, err = service.GetByName("google-test2") 88 89 if err != nil { 90 t.Error("Error: " + err.Error()) 91 } 92 if mRes.URL != "https://google.com/test" { 93 t.Error("URL and name should be the same") 94 } 95 96 service.Remove(*mRes) 97 98 monitor, err := service.GetByName(mRes.Name) 99 100 if monitor != nil { 101 t.Error("Monitor should've been deleted ", monitor, err) 102 } 103 }