-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: better test for notification delay health evaluation
- Loading branch information
1 parent
974e6fd
commit 6787720
Showing
4 changed files
with
82 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package notification | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/flanksource/duty/models" | ||
) | ||
|
||
func TestIsHealthReportable(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
events []string | ||
previousHealth models.Health | ||
currentHealth models.Health | ||
expected bool | ||
}{ | ||
{ | ||
name: "health worsened", | ||
events: []string{"config.warning", "config.healthy"}, | ||
previousHealth: models.HealthHealthy, | ||
currentHealth: models.HealthWarning, | ||
expected: true, | ||
}, | ||
{ | ||
name: "health changed and got better", | ||
events: []string{"config.warning", "config.healthy"}, | ||
previousHealth: models.HealthWarning, | ||
currentHealth: models.HealthHealthy, | ||
expected: false, | ||
}, | ||
{ | ||
name: "Current health not in notification", | ||
events: []string{"config.healthy"}, | ||
previousHealth: models.HealthHealthy, | ||
currentHealth: models.HealthUnhealthy, | ||
expected: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
result := isHealthReportable(tt.events, tt.previousHealth, tt.currentHealth) | ||
if result != tt.expected { | ||
t.Errorf("isHealthReportable(%v, %v, %v) = %v; want %v", | ||
tt.events, tt.previousHealth, tt.currentHealth, result, tt.expected) | ||
} | ||
}) | ||
} | ||
} |