Browse code
refactor answer tests
Greg Wiley authored on 20/04/2017 22:15:00
Showing 1 changed files
Showing 1 changed files
... | ... |
@@ -115,87 +115,47 @@ conversation make_conversation(pam_handle *expected_handle, const std::string &a |
115 | 115 |
|
116 | 116 |
} |
117 | 117 |
|
118 |
-bool returns_user_and_token() |
|
119 |
-{ |
|
120 |
- |
|
118 |
+bool check_conversation_response(const std::string &answer, const std::string &expected_user, const std::string &expected_token) { |
|
121 | 119 |
// given |
122 | 120 |
pam_handle *handle = reinterpret_cast<pam_handle *> (29039); |
123 |
- std::string user ("user"); |
|
124 |
- std::string token ("token"); |
|
125 |
- conversation conversation (make_conversation(handle, user + ":" + token)); |
|
121 |
+ conversation conversation (make_conversation(handle, answer)); |
|
126 | 122 |
pam_request request (handle, 0, 0, 0); |
127 | 123 |
|
128 | 124 |
// when |
129 | 125 |
conversation_result actual = conversation.initiate (request); |
130 | 126 |
|
131 | 127 |
// then |
132 |
- check (actual.user_name == user, "user name does not match"); |
|
133 |
- check (actual.token == token, "token does not match"); |
|
128 |
+ check (actual.user_name == expected_user, "user name does not match"); |
|
129 |
+ check (actual.token == expected_token, "token does not match"); |
|
134 | 130 |
|
135 | 131 |
succeed(); |
136 | 132 |
} |
137 | 133 |
|
138 |
-int returns_empty_user_and_token_when_no_colon() { |
|
139 |
- |
|
140 |
- // given |
|
141 |
- pam_handle *handle = reinterpret_cast<pam_handle *> (29039); |
|
142 |
- conversation conversation (make_conversation(handle, "nocolon")); |
|
143 |
- pam_request request (handle, 0, 0, 0); |
|
144 |
- |
|
145 |
- // when |
|
146 |
- conversation_result actual = conversation.initiate (request); |
|
134 |
+bool returns_user_and_token() |
|
135 |
+{ |
|
136 |
+ std::string user ("user"); |
|
137 |
+ std::string token ("token"); |
|
138 |
+ return check_conversation_response(user + ":" + token, user, token); |
|
139 |
+} |
|
147 | 140 |
|
148 |
- // then |
|
149 |
- check (actual.user_name == "", "user name does not match"); |
|
150 |
- check (actual.token == "", "token does not match"); |
|
151 |
- succeed(); |
|
141 |
+int returns_empty_user_and_token_when_no_colon() { |
|
142 |
+ return check_conversation_response("nocolon", "", ""); |
|
152 | 143 |
} |
153 | 144 |
|
154 | 145 |
int returns_empty_user_and_token_when_empty_answer() { |
155 |
- // given |
|
156 |
- pam_handle *handle = reinterpret_cast<pam_handle *> (29039); |
|
157 |
- conversation conversation (make_conversation(handle, "")); |
|
158 |
- pam_request request (handle, 0, 0, 0); |
|
159 |
- |
|
160 |
- // when |
|
161 |
- conversation_result actual = conversation.initiate (request); |
|
162 |
- |
|
163 |
- // then |
|
164 |
- check (actual.user_name == "", "user name does not match"); |
|
165 |
- check (actual.token == "", "token does not match"); |
|
166 |
- succeed(); |
|
146 |
+ return check_conversation_response("", "", ""); |
|
167 | 147 |
} |
168 | 148 |
|
169 | 149 |
int returns_empty_token_when_colon_end() { |
170 |
- // given |
|
171 |
- pam_handle *handle = reinterpret_cast<pam_handle *> (29039); |
|
172 |
- std::string user("user"); |
|
173 |
- conversation conversation (make_conversation(handle, user + ":")); |
|
174 |
- pam_request request (handle, 0, 0, 0); |
|
175 |
- |
|
176 |
- // when |
|
177 |
- conversation_result actual = conversation.initiate (request); |
|
178 |
- |
|
179 |
- // then |
|
180 |
- check (actual.user_name == user, "user name does not match"); |
|
181 |
- check (actual.token == "", "token should be empty"); |
|
182 |
- succeed(); |
|
150 |
+ std::string user ("user"); |
|
151 |
+ std::string token (""); |
|
152 |
+ return check_conversation_response(user + ":" + token, user, token); |
|
183 | 153 |
} |
184 | 154 |
|
185 | 155 |
int returns_empty_user_when_colon_start() { |
186 |
- // given |
|
187 |
- pam_handle *handle = reinterpret_cast<pam_handle *> (29039); |
|
188 |
- std::string token("token"); |
|
189 |
- conversation conversation (make_conversation(handle, ":" + token)); |
|
190 |
- pam_request request (handle, 0, 0, 0); |
|
191 |
- |
|
192 |
- // when |
|
193 |
- conversation_result actual = conversation.initiate (request); |
|
194 |
- |
|
195 |
- // then |
|
196 |
- check (actual.user_name == "", "user name does not match"); |
|
197 |
- check (actual.token == token, "token should be empty"); |
|
198 |
- succeed(); |
|
156 |
+ std::string user (""); |
|
157 |
+ std::string token ("token"); |
|
158 |
+ return check_conversation_response(user + ":" + token, user, token); |
|
199 | 159 |
} |
200 | 160 |
|
201 | 161 |
RESET_VARS_START |