-
Notifications
You must be signed in to change notification settings - Fork 448
Expand file tree
/
Copy pathcodemod_engine_max_runs_test.go
More file actions
94 lines (79 loc) · 2.02 KB
/
Copy pathcodemod_engine_max_runs_test.go
File metadata and controls
94 lines (79 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//go:build !integration
package cli
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestEngineMaxRunsToTopLevelCodemod_Metadata(t *testing.T) {
codemod := getEngineMaxRunsToTopLevelCodemod()
assert.Equal(t, "engine-max-runs-to-top-level", codemod.ID)
assert.Equal(t, "Move engine.max-runs to top-level max-runs", codemod.Name)
assert.NotEmpty(t, codemod.Description)
assert.Equal(t, "0.17.0", codemod.IntroducedIn)
require.NotNil(t, codemod.Apply)
}
func TestEngineMaxRunsToTopLevelCodemod_NoOp(t *testing.T) {
codemod := getEngineMaxRunsToTopLevelCodemod()
content := `---
on: push
engine:
id: copilot
---
`
frontmatter := map[string]any{
"on": "push",
"engine": map[string]any{
"id": "copilot",
},
}
result, applied, err := codemod.Apply(content, frontmatter)
require.NoError(t, err)
assert.False(t, applied)
assert.Equal(t, content, result)
}
func TestEngineMaxRunsToTopLevelCodemod_MigratesField(t *testing.T) {
codemod := getEngineMaxRunsToTopLevelCodemod()
content := `---
on: push
engine:
id: copilot
max-runs: 42
---
# Body`
frontmatter := map[string]any{
"on": "push",
"engine": map[string]any{
"id": "copilot",
"max-runs": 42,
},
}
result, applied, err := codemod.Apply(content, frontmatter)
require.NoError(t, err)
assert.True(t, applied)
assert.Contains(t, result, "\nmax-runs: 42\nengine:")
assert.NotContains(t, result, "\n max-runs:")
}
func TestEngineMaxRunsToTopLevelCodemod_RespectsExistingTopLevel(t *testing.T) {
codemod := getEngineMaxRunsToTopLevelCodemod()
content := `---
max-runs: 10
engine:
id: copilot
max-runs: 42
---
`
frontmatter := map[string]any{
"max-runs": 10,
"engine": map[string]any{
"id": "copilot",
"max-runs": 42,
},
}
result, applied, err := codemod.Apply(content, frontmatter)
require.NoError(t, err)
assert.True(t, applied)
assert.Contains(t, result, "max-runs: 10")
assert.NotContains(t, result, "max-runs: 42")
assert.NotContains(t, result, "\n max-runs:")
}