Skip to content

Commit

Permalink
test unit for monitorLoadRules. check it accepts a JSON content with BOM
Browse files Browse the repository at this point in the history
  • Loading branch information
kmuto committed Jan 19, 2024
1 parent c348e24 commit 0783434
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions monitors/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,33 @@ func TestDiffMonitorsWithScopes(t *testing.T) {
t.Errorf("expected:\n%s\n, output:\n%s\n", expected, diff)
}
}

func TestMonitorLoadRules(t *testing.T) {
tmpFile, err := os.CreateTemp("", "")
if err != nil {
t.Errorf("should not raise error: %v", err)
}
defer os.Remove(tmpFile.Name())

json := `{"monitors": []}`

_, err = tmpFile.WriteString(json)
if err != nil {
t.Errorf("should not raise error: %v", err)
}
_, err = monitorLoadRules(tmpFile.Name())
if err != nil {
t.Error("should accept JSON content no BOM")
}

utf8bom := "\xef\xbb\xbf"
tmpFile.Seek(0, 0)
_, err = tmpFile.WriteString(utf8bom + json)
if err != nil {
t.Errorf("should not raise error: %v", err)
}
_, err = monitorLoadRules(tmpFile.Name())
if err != nil {
t.Error("should accept JSON content with BOM")
}
}

0 comments on commit 0783434

Please sign in to comment.