generated from dart-action/dart_action_template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdart_action_template_test.dart
156 lines (103 loc) · 2.7 KB
/
dart_action_template_test.dart
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import 'package:dio_pull_request_checker/dio_pull_request_checker.dart';
import 'package:dio_pull_request_checker/github.dart';
import 'package:github/github.dart';
import 'package:test/test.dart';
const String _changelog = '''
## Unreleased
*None.*
## 1.0.0
- First release.
## 0.0.1
- Initial version.
''';
/// The changelog changed, and only changed the unreleased version.
const String _passedChangelog = '''
## Unreleased
- Add new feature.
## 1.0.0
- First release.
## 0.0.1
- Initial version.
''';
/// The changelog not change.
const String _noPassChangelog = '''
## Unreleased
*None.*
## 1.0.0
- First release.
## 0.0.1
- Initial version.
''';
/// The changelog is change but not only changed the unreleased version.
const String _noPassChangelog2 = '''
## Unreleased
- Fix bug.
## 1.0.0
- First release.
- Add new feature.
## 0.0.1
- Initial version.
''';
/// The changelog is change the 1.0.0 content.
const String _noPassChangelog3 = '''
## Unreleased
*None.*
## 1.0.0
- First release.
- A change in 1.0.0.
## 0.0.1
- Initial version.
''';
void main() {
test('Test getChangelogMap', () {
final map = getChangelogMap(_changelog);
for (final key in map.keys) {
print('$key: ${map[key]}');
}
expect(map.length, 3);
expect(map['Unreleased'], '*None.*');
expect(map['1.0.0'], '- First release.');
expect(map['0.0.1'], '- Initial version.');
});
test('Test checkChangeLog', () {
final result = checkChangeLog(_changelog, _passedChangelog);
expect(result, isNull);
expect(checkChangeLog(_changelog, _noPassChangelog), isNotNull);
expect(checkChangeLog(_changelog, _noPassChangelog2), isNotNull);
expect(checkChangeLog(_changelog, _noPassChangelog3), isNotNull);
});
test('Test GithubContentExt.', () {
final src1 =
'IyBDSEFOR0VMT0cKCiMjIDEuMC4wCgpzdXBwb3J0IGNoZWNrIHB1bGwgcmVx\ndWV0cwo=\n';
final dst1 = '''# CHANGELOG
## 1.0.0
support check pull requets
''';
expect(src1.decodeHaveNewLineBase64(), dst1);
final src2 = 'IyMgMS4wLjAKCi0gSW5pdGlhbCB2ZXJzaW9uLgo=\n';
final dst2 = '''## 1.0.0
- Initial version.
''';
expect(src2.decodeHaveNewLineBase64(), dst2);
});
test('Get content', () async {
github = GitHub(auth: Authentication.anonymous());
final owner = 'dart-action';
final repo = 'dio-pull-request-checker';
final prNumber = 1;
final path = 'CHANGELOG.md';
final content = await getChangeFileContentWithPullRequest(
owner: owner,
repo: repo,
number: prNumber,
path: path,
);
final currentChangeContent = '''# CHANGELOG
## Unreleased
- support check pull requets
## 0.0.1
Init project
''';
expect(content.after, currentChangeContent);
});
}