Skip to content

Commit 0ed708d

Browse files
committed
fix the platform line end related issues
1 parent ed93682 commit 0ed708d

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

.claude/settings.local.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(go test:*)",
5+
"Bash(go doc:*)",
6+
"WebSearch",
7+
"Bash(go env:*)"
8+
]
9+
}
10+
}

cmd/run_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ import (
2727
"time"
2828

2929
"github.com/h2non/gock"
30-
"github.com/linuxsuren/api-testing/pkg/limit"
3130
atest "github.com/linuxsuren/api-testing/pkg/testing"
3231
"github.com/linuxsuren/api-testing/pkg/util"
3332
"github.com/spf13/cobra"
3433
"github.com/stretchr/testify/assert"
34+
"golang.org/x/time/rate"
3535
)
3636

3737
func TestRunSuite(t *testing.T) {
@@ -71,7 +71,7 @@ func TestRunSuite(t *testing.T) {
7171
ctx := getDefaultContext()
7272
opt := newDiscardRunOption()
7373
opt.requestTimeout = 30 * time.Second
74-
opt.limiter = limit.NewDefaultRateLimiter(0, 0)
74+
opt.limiter = rate.NewLimiter(rate.Limit(0), 0)
7575
stopSingal := make(chan struct{}, 1)
7676

7777
loader := atest.NewFileLoader()

pkg/runner/writer_markdown_test.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,19 @@ package runner_test
1818

1919
import (
2020
"bytes"
21+
"strings"
2122
"testing"
2223

2324
"github.com/linuxsuren/api-testing/pkg/apispec"
2425
"github.com/linuxsuren/api-testing/pkg/runner"
2526
"github.com/stretchr/testify/assert"
2627
)
2728

29+
const (
30+
winLineEnd = "\r\n"
31+
unixLineEnd = "\n"
32+
)
33+
2834
func TestMarkdownWriter(t *testing.T) {
2935
sample := runner.ReportResult{
3036
Name: "api",
@@ -51,12 +57,15 @@ func TestMarkdownWriter(t *testing.T) {
5157
writer.WithAPICoverage(nil)
5258
err := writer.Output(createSlice(sample, 2))
5359
assert.Nil(t, err)
60+
// Normalize line endings for Windows compatibility
61+
actual := buf.String()
62+
actual = normalizeLineEndings(actual)
5463
assert.Equal(t, `There are 2 test cases, failed count 0:
5564
5665
| Name | Average | Max | Min | Count | Error |
5766
|---|---|---|---|---|---|
5867
| api | 3ns | 4ns | 2ns | 3 | 0 |
59-
| api | 3ns | 4ns | 2ns | 3 | 0 |`, buf.String())
68+
| api | 3ns | 4ns | 2ns | 3 | 0 |`, actual)
6069
})
6170

6271
t.Run("long", func(t *testing.T) {
@@ -65,6 +74,7 @@ func TestMarkdownWriter(t *testing.T) {
6574
writer.WithAPICoverage(nil)
6675
err := writer.Output(createSlice(sample, 8))
6776
assert.Nil(t, err)
77+
actual := normalizeLineEndings(buf.String())
6878
assert.Equal(t, `There are 8 test cases, failed count 0:
6979
7080
<details>
@@ -80,7 +90,7 @@ func TestMarkdownWriter(t *testing.T) {
8090
| api | 3ns | 4ns | 2ns | 3 | 0 |
8191
| api | 3ns | 4ns | 2ns | 3 | 0 |
8292
| api | 3ns | 4ns | 2ns | 3 | 0 |
83-
</details>`, buf.String())
93+
</details>`, actual)
8494
})
8595

8696
t.Run("long, there are error cases", func(t *testing.T) {
@@ -89,6 +99,7 @@ func TestMarkdownWriter(t *testing.T) {
8999
writer.WithAPICoverage(nil)
90100
err := writer.Output(append(createSlice(sample, 8), errSample))
91101
assert.Nil(t, err)
102+
actual := normalizeLineEndings(buf.String())
92103
assert.Equal(t, `There are 9 test cases, failed count 1:
93104
94105
| Name | Average | Max | Min | Count | Error |
@@ -109,7 +120,7 @@ func TestMarkdownWriter(t *testing.T) {
109120
| api | 3ns | 4ns | 2ns | 3 | 0 |
110121
| api | 3ns | 4ns | 2ns | 3 | 0 |
111122
| foo | 3ns | 4ns | 2ns | 3 | 1 |
112-
</details>`, buf.String())
123+
</details>`, actual)
113124
})
114125

115126
t.Run("with resource usage", func(t *testing.T) {
@@ -122,6 +133,7 @@ func TestMarkdownWriter(t *testing.T) {
122133
}})
123134
err := writer.Output(createSlice(sample, 2))
124135
assert.Nil(t, err)
136+
actual := normalizeLineEndings(buf.String())
125137
assert.Equal(t, `There are 2 test cases, failed count 0:
126138
127139
| Name | Average | Max | Min | Count | Error |
@@ -131,7 +143,7 @@ func TestMarkdownWriter(t *testing.T) {
131143
132144
Resource usage:
133145
* CPU: 1
134-
* Memory: 1`, buf.String())
146+
* Memory: 1`, actual)
135147
})
136148

137149
t.Run("have error message", func(t *testing.T) {
@@ -142,6 +154,7 @@ Resource usage:
142154
result.LastErrorMessage = "error happend"
143155
err := writer.Output(createSlice(result, 2))
144156
assert.Nil(t, err)
157+
actual := normalizeLineEndings(buf.String())
145158
assert.Equal(t, `There are 2 test cases, failed count 0:
146159
147160
| Name | Average | Max | Min | Count | Error |
@@ -153,7 +166,7 @@ Resource usage:
153166
<summary><b>See the error message</b></summary>
154167
* error happend
155168
* error happend
156-
</details>`, buf.String())
169+
</details>`, actual)
157170
})
158171

159172
t.Run("with api converage", func(t *testing.T) {
@@ -164,17 +177,22 @@ Resource usage:
164177
}}))
165178
err := writer.Output(createSlice(sample, 2))
166179
assert.Nil(t, err)
180+
actual := normalizeLineEndings(buf.String())
167181
assert.Equal(t, `There are 2 test cases, failed count 0:
168182
169183
| Name | Average | Max | Min | Count | Error |
170184
|---|---|---|---|---|---|
171185
| api | 3ns | 4ns | 2ns | 3 | 0 |
172186
| api | 3ns | 4ns | 2ns | 3 | 0 |
173187
174-
API Coverage: 1/1`, buf.String())
188+
API Coverage: 1/1`, actual)
175189
})
176190
}
177191

192+
func normalizeLineEndings(s string) string {
193+
return strings.ReplaceAll(s, winLineEnd, unixLineEnd)
194+
}
195+
178196
func createSlice(sample runner.ReportResult, count int) (result []runner.ReportResult) {
179197
for i := 0; i < count; i++ {
180198
result = append(result, sample)

0 commit comments

Comments
 (0)