Skip to content
Permalink
Browse files

fixed tests - removed database creds from logs

  • Loading branch information...
hunterlong committed Sep 3, 2019
1 parent ce90d9d commit 50ba485fcdc1d05293308a9fb949955becab1cc6

Some generated files are not rendered by default. Learn more.

@@ -27,7 +27,7 @@

[[constraint]]
name = "github.com/99designs/gqlgen"
branch = "master"
version = "0.9.3"

[[constraint]]
name = "github.com/GeertJohan/go.rice"
@@ -47,15 +47,15 @@

[[constraint]]
name = "github.com/gorilla/mux"
version = "1.7.1"
version = "1.7.3"

[[constraint]]
name = "github.com/gorilla/sessions"
version = "1.1.3"
version = "1.2.0"

[[constraint]]
name = "github.com/jinzhu/gorm"
version = "1.9.4"
version = "1.9.10"

[[constraint]]
name = "github.com/joho/godotenv"
@@ -67,7 +67,7 @@

[[constraint]]
name = "github.com/stretchr/testify"
version = "1.3.0"
version = "1.4.0"

[[constraint]]
branch = "master"
@@ -40,6 +40,7 @@ func checkServices() {
}

// Check will run checkHttp for HTTP services and checkTcp for TCP services
// if record param is set to true, it will add a record into the database.
func (s *Service) Check(record bool) {
switch s.Type {
case "http":
@@ -260,8 +261,8 @@ func recordSuccess(s *Service) {
}
utils.Log(1, fmt.Sprintf("Service %v Successful Response: %0.2f ms | Lookup in: %0.2f ms", s.Name, hit.Latency*1000, hit.PingTime*1000))
s.CreateHit(hit)
notifier.OnSuccess(s.Service)
s.Online = true
notifier.OnSuccess(s.Service)
}

// recordFailure will create a new 'Failure' record in the database for a offline service
@@ -275,7 +276,6 @@ func recordFailure(s *Service, issue string) {
}}
utils.Log(2, fmt.Sprintf("Service %v Failing: %v | Lookup in: %0.2f ms", s.Name, issue, fail.PingTime*1000))
s.CreateFailure(fail)
notifier.OnFailure(s.Service, fail.Failure)
s.Online = false

notifier.OnFailure(s.Service, fail.Failure)
}
@@ -217,7 +217,7 @@ func (db *DbConfig) Connect(retry bool, location string) error {
dbSession, err := gorm.Open(dbType, conn)
if err != nil {
if retry {
utils.Log(1, fmt.Sprintf("Database connection to '%v' is not available, trying again in 5 seconds...", conn))
utils.Log(1, fmt.Sprintf("Database connection to '%v' is not available, trying again in 5 seconds...", Configs.DbHost))
return db.waitForDb()
} else {
return err
@@ -229,7 +229,7 @@ func (db *DbConfig) Connect(retry bool, location string) error {
err = dbSession.DB().Ping()
if err == nil {
DbSession = dbSession
utils.Log(1, fmt.Sprintf("Database %v connection '%v@%v:%v' at %v was successful.", dbType, Configs.DbUser, Configs.DbHost, Configs.DbPort, Configs.DbData))
utils.Log(1, fmt.Sprintf("Database %v connection was successful.", dbType))
}
return err
}
@@ -64,18 +64,15 @@ func TestSelectTCPService(t *testing.T) {

func TestUpdateService(t *testing.T) {
service := SelectService(1)
service2 := SelectService(2)
assert.Equal(t, "Google", service.Name)
assert.Equal(t, "Statping Github", service2.Name)
assert.True(t, service.Online)
assert.True(t, service2.Online)
service.Name = "Updated Google"
service.Interval = 5
err := service.Update(true)
assert.Nil(t, err)
// check if updating pointer array shutdown any other service
service2 = SelectService(2)
assert.True(t, service2.Online)
service = SelectService(1)
assert.Equal(t, "Updated Google", service.Name)
assert.Equal(t, 5, service.Interval)
}

func TestUpdateAllServices(t *testing.T) {
@@ -66,33 +66,16 @@ func TestCommandNotifier(t *testing.T) {
assert.Equal(t, 1, len(command.Queue))
})

t.Run("command OnFailure multiple times", func(t *testing.T) {
for i := 0; i <= 50; i++ {
command.OnFailure(TestService, TestFailure)
}
assert.Equal(t, 52, len(command.Queue))
})

t.Run("command Check Offline", func(t *testing.T) {
assert.False(t, TestService.Online)
})

t.Run("command OnSuccess", func(t *testing.T) {
command.OnSuccess(TestService)
assert.Equal(t, 1, len(command.Queue))
})

t.Run("command Queue after being online", func(t *testing.T) {
assert.True(t, TestService.Online)
assert.Equal(t, 1, len(command.Queue))
})

t.Run("command OnSuccess Again", func(t *testing.T) {
assert.True(t, TestService.Online)
command.OnSuccess(TestService)
assert.Equal(t, 1, len(command.Queue))
go notifier.Queue(command)
time.Sleep(5 * time.Second)
time.Sleep(20 * time.Second)
assert.Equal(t, 0, len(command.Queue))
})

@@ -69,10 +69,6 @@ func TestDiscordNotifier(t *testing.T) {
assert.Equal(t, 1, len(discorder.Queue))
})

t.Run("discord Check Offline", func(t *testing.T) {
assert.False(t, TestService.Online)
})

t.Run("discord OnSuccess", func(t *testing.T) {
discorder.OnSuccess(TestService)
assert.Equal(t, 1, len(discorder.Queue))
@@ -105,10 +105,6 @@ func TestEmailNotifier(t *testing.T) {
assert.Equal(t, 1, len(emailer.Queue))
})

t.Run("email Check Offline", func(t *testing.T) {
assert.False(t, TestService.Online)
})

t.Run("email OnSuccess", func(t *testing.T) {
emailer.OnSuccess(TestService)
assert.Equal(t, 1, len(emailer.Queue))

0 comments on commit 50ba485

Please sign in to comment.
You can’t perform that action at this time.