mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-09-19 09:40:12 +00:00
test(agentcompat): preserve existing CRLF workflow data
Co-authored-by: naiba/CloudCode <hi+cloudcode@nai.ba>
This commit is contained in:
@@ -30,7 +30,7 @@ func TestPolicy_RejectsInvalidRequiredAggregator(t *testing.T) {
|
|||||||
data []byte
|
data []byte
|
||||||
}{
|
}{
|
||||||
{name: "LF", data: workflowData},
|
{name: "LF", data: workflowData},
|
||||||
{name: "CRLF", data: []byte(strings.ReplaceAll(string(workflowData), "\n", "\r\n"))},
|
{name: "CRLF", data: []byte(workflowWithCRLF(string(workflowData)))},
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@@ -108,6 +108,23 @@ func TestPolicy_RejectsInvalidRequiredAggregator(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWorkflowWithCRLF_PreservesExistingCRLF(t *testing.T) {
|
||||||
|
// Given
|
||||||
|
workflow := "first\r\nsecond\r\n"
|
||||||
|
|
||||||
|
// When
|
||||||
|
converted := workflowWithCRLF(workflow)
|
||||||
|
|
||||||
|
// Then
|
||||||
|
require.Equal(t, workflow, converted)
|
||||||
|
}
|
||||||
|
|
||||||
|
func workflowWithCRLF(workflow string) string {
|
||||||
|
// Normalize first so Windows checkouts are not expanded from CRLF to CRCRLF.
|
||||||
|
workflow = strings.ReplaceAll(workflow, "\r\n", "\n")
|
||||||
|
return strings.ReplaceAll(workflow, "\n", "\r\n")
|
||||||
|
}
|
||||||
|
|
||||||
func mutateWorkflow(t *testing.T, data []byte, currentText, invalidText string) string {
|
func mutateWorkflow(t *testing.T, data []byte, currentText, invalidText string) string {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
workflow := string(data)
|
workflow := string(data)
|
||||||
|
|||||||
Reference in New Issue
Block a user