-
Notifications
You must be signed in to change notification settings - Fork 32
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
accept UTF8-BOM when reading dashboard or monitor from JSON file #622
Changes from all commits
0a1a890
c348e24
0783434
05275c4
9455db9
8df6538
3295eed
db949f8
c401adc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -200,3 +200,37 @@ func TestDiffMonitorsWithScopes(t *testing.T) { | |
t.Errorf("expected:\n%s\n, output:\n%s\n", expected, diff) | ||
} | ||
} | ||
|
||
func TestMonitorLoadRulesWithBOM(t *testing.T) { | ||
// XXX: t.TempDir is better, but it will cause "TempDir RemoveAll cleanup: remove C:\...\monitors.json: The process cannot access the file because it is being used by another process." error on Windows | ||
tmpFile, err := os.CreateTemp("", "") | ||
if err != nil { | ||
t.Errorf("should not raise error: %v", err) | ||
} | ||
defer os.Remove(tmpFile.Name()) | ||
Comment on lines
+206
to
+210
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. testing.T.TempDir is useful. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had tried it on 8df6538 , 3295eed , and db949f8 but all of them went failed on Windows (I saw golang/go#50510 ) |
||
|
||
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" | ||
_, err = tmpFile.Seek(0, 0) | ||
if err != nil { | ||
t.Errorf("should not raise error: %v", err) | ||
} | ||
_, 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") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do like it a lot!