forked from influxdata/kapacitor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: HttpPost AlertTemplateFile and RowTemplateFile work with either …
…unix- or windows-like paths (influxdata#2767)
- Loading branch information
1 parent
2fbf7f1
commit e07d6bb
Showing
3 changed files
with
145 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
//go:build !windows | ||
|
||
package httppost | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func Test_Validate_ShouldNotReturnError_WhenAlertTemplateFileIsUnixLikePath(t *testing.T) { | ||
testCases := []struct { | ||
config Config | ||
err error | ||
}{ | ||
{ | ||
config: Config{ | ||
Endpoint: "test", | ||
URLTemplate: "http://localhost:8080/alert", | ||
AlertTemplateFile: "/etc/kapacitor/templates/alert_template.json", | ||
}, | ||
err: nil, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
validationErr := tc.config.Validate() | ||
|
||
if validationErr != nil { | ||
if tc.err == nil { | ||
t.Errorf("unexpected error: got %v", validationErr) | ||
} else if tc.err.Error() != validationErr.Error() { | ||
t.Errorf("unexpected error message: got %q exp %q", validationErr.Error(), tc.err.Error()) | ||
} | ||
} else { | ||
if tc.err != nil { | ||
t.Errorf("expected error: %q got nil", tc.err.Error()) | ||
} | ||
} | ||
} | ||
} | ||
|
||
func Test_Validate_ShouldNotReturnError_WhenRowTemplateFileIsUnixLikePath(t *testing.T) { | ||
testCases := []struct { | ||
config Config | ||
err error | ||
}{ | ||
{ | ||
config: Config{ | ||
Endpoint: "test", | ||
URLTemplate: "http://localhost:8080/alert", | ||
RowTemplateFile: "/etc/kapacitor/templates/row_template.json", | ||
}, | ||
err: nil, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
validationErr := tc.config.Validate() | ||
|
||
if validationErr != nil { | ||
if tc.err == nil { | ||
t.Errorf("unexpected error: got %v", validationErr) | ||
} else if tc.err.Error() != validationErr.Error() { | ||
t.Errorf("unexpected error message: got %q exp %q", validationErr.Error(), tc.err.Error()) | ||
} | ||
} else { | ||
if tc.err != nil { | ||
t.Errorf("expected error: %q got nil", tc.err.Error()) | ||
} | ||
} | ||
} | ||
} |
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,71 @@ | ||
//go:build windows | ||
|
||
package httppost | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func Test_Validate_ShouldNotReturnError_WhenAlertTemplateFileIsWindowsLikePath(t *testing.T) { | ||
testCases := []struct { | ||
config Config | ||
err error | ||
}{ | ||
{ | ||
config: Config{ | ||
Endpoint: "test", | ||
URLTemplate: "http://localhost:8080/alert", | ||
AlertTemplateFile: "C:\\InfluxData\\kapacitor\\templates\\alert_template.json", | ||
}, | ||
err: nil, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
validationErr := tc.config.Validate() | ||
|
||
if validationErr != nil { | ||
if tc.err == nil { | ||
t.Errorf("unexpected error: got %v", validationErr) | ||
} else if tc.err.Error() != validationErr.Error() { | ||
t.Errorf("unexpected error message: got %q exp %q", validationErr.Error(), tc.err.Error()) | ||
} | ||
} else { | ||
if tc.err != nil { | ||
t.Errorf("expected error: %q got nil", tc.err.Error()) | ||
} | ||
} | ||
} | ||
} | ||
|
||
func Test_Validate_ShouldNotReturnError_WhenRowTemplateFileIsWindowsLikePath(t *testing.T) { | ||
testCases := []struct { | ||
config Config | ||
err error | ||
}{ | ||
{ | ||
config: Config{ | ||
Endpoint: "test", | ||
URLTemplate: "http://localhost:8080/alert", | ||
RowTemplateFile: "C:\\InfluxData\\kapacitor\\templates\\row_template.json", | ||
}, | ||
err: nil, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
validationErr := tc.config.Validate() | ||
|
||
if validationErr != nil { | ||
if tc.err == nil { | ||
t.Errorf("unexpected error: got %v", validationErr) | ||
} else if tc.err.Error() != validationErr.Error() { | ||
t.Errorf("unexpected error message: got %q exp %q", validationErr.Error(), tc.err.Error()) | ||
} | ||
} else { | ||
if tc.err != nil { | ||
t.Errorf("expected error: %q got nil", tc.err.Error()) | ||
} | ||
} | ||
} | ||
} |