Skip to content

Commit 26c2ecd

Browse files
Merge pull request #38 from dynatrace-wwse/revamp
Revamp
2 parents a11e960 + 3a28ee9 commit 26c2ecd

File tree

8 files changed

+322
-62
lines changed

8 files changed

+322
-62
lines changed

.devcontainer/test/integration.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ assertRunningPod dynatrace oneagent
1313
assertRunningPod todoapp todoapp
1414

1515
assertRunningApp 30100
16+
17+
assertBugsAndRedeployment

.devcontainer/util/my_functions.sh

Lines changed: 210 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ redeployApp(){
5050
}
5151

5252

53+
_check_bug1(){
54+
55+
addTask '{"title":"Clear completed task","completed":true}'
56+
57+
clearCompletedTasks
58+
59+
}
60+
5361
is_bug1_there(){
5462

5563
kubectl logs -l app=todoapp -c todoapp -n todoapp | grep 'completed=true' > /dev/null
@@ -62,16 +70,18 @@ is_bug1_there(){
6270
printInfo "🪲 Bug 'Clear completed' is there! Thanks for adding tasks and trying to clear them."
6371
return 0
6472
else
65-
printInfo " ⚠️ Please add a couple of task, mark them completed and then click on the 'clear completed' button in order to see if the 🪲 bug is there..."
73+
printWarn " ⚠️ Please add a couple of task, mark them completed and then click on the 'clear completed' button in order to see if the 🪲 bug is there..."
6674
return 1
6775
fi
6876

6977
}
7078

79+
7180
is_bug1_solved(){
72-
addCompletedTask
7381

74-
clearCompletedTasks
82+
printInfoSection "Verifying if the 🪲 Bug 'Clear completed' is gone"
83+
84+
_check_bug1
7585

7686
kubectl logs -l app=todoapp -c todoapp -n todoapp | grep 'Removed Todo record.*completed=true' > /dev/null
7787
found_removed=$?
@@ -80,32 +90,145 @@ is_bug1_solved(){
8090
printInfo "✅ Bug clear completed is gone."
8191
return 0
8292
else
83-
printInfo "⚠️ Bug clear completed is still there, tip: check the Arrays"
93+
printWarn "⚠️ Bug clear completed is still there, tip: check the Arrays"
8494
return 1
8595
fi
8696

8797
}
8898

99+
is_bug2_solved(){
100+
printInfoSection "Verifying if the 🪲 Bug 'Special Characters' is gone"
101+
RC=0
102+
103+
addTask '{"title":"Exciting validation!?#","completed":false}'
104+
105+
printInfo "Retrieving todos to verify the title..."
106+
107+
response=$(curl -s -X GET $APPLICATION_URL/todos)
108+
109+
# Check if special characters are preserved
110+
if echo "$response" | grep -q '"title":"Exciting validation!?#"'; then
111+
printInfo "✅ Bug special characters is gone. Title preserved correctly."
112+
RC=0
113+
elif echo "$response" | grep -q '"title":"Exciting validation"'; then
114+
printWarn "⚠️ Bug special characters is still there. Special characters were stripped from the title. Tip: Less is more ;)"
115+
RC=1
116+
fi
117+
118+
# Delete taskId
119+
#deleteTask $response
120+
return $RC
121+
}
122+
123+
is_bug3_solved(){
124+
printInfoSection "Verifying if the 🪲 Bug 'Duplicate Task' is gone"
125+
RC=0
126+
127+
# Generate a random 6-character ID
128+
random_id=$(head /dev/urandom | LC_ALL=C tr -dc 'a-zA-Z0-9' | head -c 6)
129+
title="Duplicated task with ID $random_id"
130+
131+
addTask '{"title":"'"$title"'","completed":false}'
132+
133+
response=$(curl -s -X GET $APPLICATION_URL/todos)
134+
task_id=$(echo "$response" | grep -o '"title":"'"$title"'","id":"[^"]*"' | grep -o '"id":"[^"]*"' | cut -d'"' -f4)
135+
136+
if [ -n "$task_id" ]; then
137+
printInfo "Duplicating task with ID: $task_id"
138+
dup_response=$(curl -s -X POST $APPLICATION_URL/todos/dup/$task_id)
139+
140+
if echo "$dup_response" | grep -q '"status":"ok"'; then
141+
# Get todos again to verify the duplicate
142+
response=$(curl -s -X GET $APPLICATION_URL/todos)
143+
144+
# Count how many tasks have the correct title
145+
count=$(echo "$response" | grep -o '"title":"'"$title"'"' | wc -l)
146+
147+
# Verify original task still exists with the same ID
148+
original_exists=$(echo "$response" | grep -q '"title":"'"$title"'","id":"'"$task_id"'"' && echo "yes" || echo "no")
149+
150+
# Check if we have 2 tasks with the correct title and the original still exists
151+
if [ "$count" -eq 2 ] && [ "$original_exists" = "yes" ]; then
152+
printInfo "✅ Bug duplicate task is gone. Found 2 tasks with correct title '$title', including original with ID: $task_id"
153+
RC=0
154+
else
155+
printWarn "⚠️ Bug duplicate task is still there. Expected 2 tasks with title '$title', found: $count. Tip: Check the setter methods in duplicateTodo."
156+
RC=1
157+
fi
158+
else
159+
printInfo "❌ Failed to execute duplicate"
160+
RC=1
161+
fi
162+
else
163+
printInfo "❌ Could not find the task to duplicate"
164+
RC=1
165+
fi
166+
167+
return $RC
168+
}
169+
170+
deleteTask(){
171+
response="$1"
172+
# might need it later
173+
task_id=$(echo "$response" | grep -o '"title":"Exciting validation[^"]*","id":"[^"]*"' | grep -o '"id":"[^"]*"' | cut -d'"' -f4)
174+
if [ -n "$task_id" ]; then
175+
printInfo "Deleting task ID: $task_id"
176+
delete_response=$(curl -s -X DELETE $APPLICATION_URL/todos/$task_id)
177+
if echo "$delete_response" | grep -q '"status":"ok"'; then
178+
printInfo "Task deleted successfully"
179+
else
180+
printInfo "Failed to delete task"
181+
fi
182+
fi
183+
}
184+
89185
solve_bug1(){
90186

91-
printInfoSection "Solving the Bug Clear Completed"
187+
printInfoSection "Solving the 🪲 Bug Clear Completed"
188+
189+
_solve_bug "solution/bug1"
190+
191+
printInfo "Now add some tasks, mark them completed and click on 'clear completed'"
192+
printInfo "You can assert that the bug is gone also by typing 'is_bug1_solved'"
193+
}
194+
195+
solve_bug2(){
196+
197+
printInfoSection "Solving the 🪲 Bug Special Characters"
198+
_solve_bug "solution/bug2"
199+
200+
printInfo "Now add some tasks with special characters and see if they are added correctly"
201+
printInfo "You can assert that the bug is gone also by typing 'is_bug2_solved'"
202+
}
203+
204+
solve_bug3(){
205+
206+
printInfoSection "Solving the 🪲 Bug Duplicated Task"
207+
_solve_bug "solution/bug3"
208+
209+
printInfo "Now duplicate a record and see if the duplicate is correct"
210+
printInfo "You can assert that the bug is gone also by typing 'is_bug3_solved'"
211+
}
212+
213+
_solve_bug(){
214+
215+
solution_branch=$1
92216

93-
printInfo "we change to the branch solution/bug1 where the developer already added the solution for us"
217+
printInfo "Changing to the branch $solution_branch where the developer already added the solution for us"
94218

95-
printInfo "git checkout solution/bug1"
219+
printInfo "git checkout $solution_branch"
96220

97-
git checkout solution/bug1
221+
git checkout $solution_branch
98222

99223
printInfo "then we compile the application and redeploy it to the Kubernetes Cluster using the function 'redeployApp'"
100224

101225
redeployApp
102226

103-
setVersionControl "solution/bug1"
227+
setVersionControl "$solution_branch"
104228

105-
printInfo "Now add some tasks, mark them completed and click on 'clear completed'"
106-
printInfo "You can assert that the bug is gone also by typing 'is_bug1_solved'"
107229
}
108230

231+
109232
setVersionControl(){
110233
printInfo "Setting version control in the DEPLOYMENT_NAME=$DEPLOYMENT_NAME to point to '$1' "
111234
updateVersionControl "$1"
@@ -161,13 +284,14 @@ EOF
161284
}
162285

163286

164-
165-
# Testing Methods
166-
167-
addCompletedTask(){
168-
printInfo "adding completed Task"
287+
addTask(){
288+
jsontask="$1"
289+
if [ -z "$jsontask" ]; then
290+
jsontask='{"title":"Completed task","completed":true}'
291+
fi
292+
printInfo "adding task $jsontask"
169293
response=$(curl -s -X POST $APPLICATION_URL/todos \
170-
-H "Content-Type: application/json" -d '{"title":"Completed task","completed":true}')
294+
-H "Content-Type: application/json" -d "$jsontask")
171295

172296
if echo "$response" | grep -q '"status":"ok"'; then
173297
printInfo "✅ Task added successfully"
@@ -186,4 +310,73 @@ clearCompletedTasks(){
186310
printInfo "❌ Failed to execute Clear completed"
187311
fi
188312

313+
}
314+
315+
316+
317+
assertBugsAndRedeployment(){
318+
printInfoSection "Verifying if the Bug 1 is there..."
319+
320+
_check_bug1
321+
322+
if is_bug1_solved; then
323+
exit 1
324+
fi
325+
326+
printInfo "Bugs are there! now solving 1, 2 and 3 with the TodoController from solution/bug3"
327+
328+
replaceTodoController "solution/bug3"
329+
330+
redeployApp
331+
332+
waitAppCanHandleRequests
333+
334+
if ! is_bug1_solved; then
335+
exit 1
336+
fi
337+
338+
if ! is_bug2_solved; then
339+
exit 1
340+
fi
341+
342+
if ! is_bug3_solved; then
343+
exit 1
344+
fi
345+
346+
}
347+
348+
replaceTodoController(){
349+
350+
solution_branch="$1"
351+
352+
printInfoSection "Replacing the TodoController from branch $solution_branch"
353+
354+
if [ -z "$solution_branch" ]; then
355+
printError "No solution branch specified"
356+
return 1
357+
fi
358+
359+
printInfo "Downloading TodoController.java from $solution_branch branch"
360+
361+
curl -s -o app/src/main/java/com/dynatrace/todoapp/TodoController.java \
362+
"https://raw.githubusercontent.com/dynatrace-wwse/enablement-live-debugger-bug-hunting/refs/heads/$solution_branch/app/src/main/java/com/dynatrace/todoapp/TodoController.java"
363+
364+
if [ $? -eq 0 ]; then
365+
printInfo "✅ TodoController.java downloaded successfully from $solution_branch"
366+
else
367+
printError "❌ Failed to download TodoController.java from $solution_branch"
368+
return 1
369+
fi
370+
371+
}
372+
373+
assertBug2isThere(){
374+
printInfoSection "Verifying if the Bug 2 is there..."
375+
376+
is_bug2_solved
377+
378+
if ! is_bug1_solved; then
379+
exit 1
380+
fi
381+
189382
}

docs/1-bug-hunt-via-k8s.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,22 +143,24 @@ is_bug1_solved
143143
<summary>🛠️ The code changes </summary>
144144

145145

146-
The `TodoController.clearCompletedTodos` changes from trying to remove items from a newly created List, logging an obvious error...
146+
The `TodoController.clearCompletedTodos` you just need to change one variable, replace `todoStore` to `todos` in the if clause on line 81.
147147

148148
```javascript
149149
150150
if (todosStore.remove(todoRecord)) {
151151
152152
```
153153

154-
to removing the correct item and validating the size of the array after the changes with the correct logging message.
154+
this way when iterating in the `todos` array, when the `todoRecord.isCompleted()` then we remove it from the correct list.
155155

156156
```javascript
157157
158158
if (todos.remove(todoRecord)) {
159159
160-
161160
```
161+
When the removal succeeds, then the correct log record will be printed out.
162+
163+
162164
</details>
163165

164166

@@ -167,7 +169,8 @@ is_bug1_solved
167169
More on this in the section "Version Control" of this tutorial.
168170

169171

170-
Verify the bug is gone! add more tasks and click on `clear completed` see how the tasks disappear gracefully now! Amazing!
172+
173+
Verify the bug is gone! add more tasks and click on `clear completed` see how the tasks disappear gracefully now! Amazing!
171174

172175

173176
<div class="grid cards" markdown>

0 commit comments

Comments
 (0)