annotate mrjunejune/test/integration_test.c @ 279:b3b547563ec7

Add Google connector service and agent wiki Implement the C/Seobeo Google Drive and Gmail connector with encrypted OAuth storage, Zenbu authentication, browser testing, AI tool discovery, chunked HTTP decoding, and Bazel coverage. Consolidate repository guidance into progressive wiki documentation and enforce arena-first allocation for new first-party C code. Co-authored-by: Copilot <[email protected]> Copilot-Session: 84c338fd-0939-4bb3-b7f3-1062eb213e5d
author MrJuneJune <me@mrjunejune.com>
date Mon, 17 Aug 2026 22:22:36 -0700
parents 1f9877b637e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
128
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
1 #include "mrjunejune/test/test.h"
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
3 // Test case structure
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
4 typedef struct {
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
5 const char *path;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
6 int expected_status;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
7 const char *expected_content; // Loaded from file
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
8 char *expected_file_path; // Path to expected snapshot file
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
9 char *actual_response;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
10 size_t response_len;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
11 } TestCase;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
12
128
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
13 void debug_diff(const char *expected, const char *actual)
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
14 {
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
15 printf("\n--- DIFF (Expected vs Actual) ---\n");
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
16
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
17 // Create copies to use with strtok (strtok modifies the string)
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
18 char *exp_copy = strdup(expected);
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
19 char *act_copy = strdup(actual);
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
20
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
21 char *exp_line = strtok(exp_copy, "\n");
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
22 char *act_line = strtok(act_copy, "\n");
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
23
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
24 int line_num = 1;
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
25 while (exp_line != NULL || act_line != NULL) {
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
26 if (exp_line && act_line && strcmp(exp_line, act_line) == 0) {
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
27 // Lines match - optional: print nothing or a dot
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
28 } else {
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
29 printf("Line %d mismatch:\n", line_num);
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
30 printf(" EXP: [%s]\n", exp_line ? exp_line : "(end of string)");
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
31 printf(" ACT: [%s]\n", act_line ? act_line : "(end of string)");
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
32 printf(" -----------------------------------\n");
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
33 }
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
34
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
35 exp_line = strtok(NULL, "\n");
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
36 act_line = strtok(NULL, "\n");
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
37 line_num++;
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
38 }
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
39
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
40 free(exp_copy);
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
41 free(act_copy);
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
42 }
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
43
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
44 // Helper: Convert URL path to filename
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
45 // "/" -> "root.snapshot"
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
46 // "/index.html" -> "index.html.snapshot"
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
47 // "/api/users" -> "api_users.snapshot"
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
48 void path_to_filename(const char *path, char *filename, size_t max_len)
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
49 {
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
50 if (strcmp(path, "/") == 0)
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
51 {
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
52 snprintf(filename, max_len, "root.snapshot");
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
53 return;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
54 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
55
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
56 // Remove leading slash and convert remaining slashes to underscores
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
57 const char *p = path;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
58 if (*p == '/')
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
59 {
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
60 p++;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
61 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
62
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
63 char *out = filename;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
64 size_t remaining = max_len - 1;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
65
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
66 while (*p && remaining > 0)
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
67 {
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
68 if (*p == '/')
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
69 {
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
70 *out++ = '_';
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
71 remaining--;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
72 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
73 else
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
74 {
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
75 *out++ = *p;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
76 remaining--;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
77 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
78 p++;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
79 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
80
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
81 // Add .snapshot extension
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
82 snprintf(out, remaining, ".snapshot");
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
83 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
84
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
85 // Helper: Read file contents into buffer
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
86 char* read_file(const char *filepath, size_t *size_out)
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
87 {
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
88 FILE *f = fopen(filepath, "rb");
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
89 if (!f)
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
90 {
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
91 return NULL;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
92 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
93
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
94 fseek(f, 0, SEEK_END);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
95 long fsize = ftell(f);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
96 fseek(f, 0, SEEK_SET);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
97
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
98 char *buffer = malloc(fsize + 1);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
99 if (!buffer)
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
100 {
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
101 fclose(f);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
102 return NULL;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
103 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
104
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
105 size_t read_size = fread(buffer, 1, fsize, f);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
106 buffer[read_size] = '\0';
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
107 fclose(f);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
108
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
109 if (size_out)
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
110 {
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
111 *size_out = read_size;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
112 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
113
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
114 return buffer;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
115 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
116
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
117 // Helper: Load expected content for a test case
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
118 int load_expected_content(TestCase *test)
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
119 {
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
120 if (!test->expected_file_path)
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
121 {
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
122 return -1;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
123 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
124
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
125 size_t size;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
126 test->expected_content = read_file(test->expected_file_path, &size);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
127
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
128 if (!test->expected_content)
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
129 {
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
130 return -1;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
131 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
132
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
133 return 0;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
134 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
135
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
136 int execute_test_case(TestCase *test, pid_t server_pid)
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
137 {
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
138 printf(" Testing: GET %s (expecting %d)\n", test->path, test->expected_status);
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
139
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
140 int32 max_url_length = 1024*3;
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
141 char *url = malloc(sizeof(char)*max_url_length);
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
142 snprintf(url, max_url_length, "%s%s", TEST_URL, test->path);
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
143 Seobeo_Client_Request *p_req = Seobeo_Client_Request_Create(url);
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
144 if (!p_req)
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
145 {
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
146 printf("Can't create requests");
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
147 return -1;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
148 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
149
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
150 Seobeo_Client_Response *p_resp = Seobeo_Client_Request_Execute(p_req);
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
151 if (!p_resp)
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
152 {
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
153 printf("No response");
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
154 return -1;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
155 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
156
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
157 if (p_resp->status_code != test->expected_status)
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
158 {
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
159 printf(" ✗ Status mismatch: expected %d, got %d\n",
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
160 test->expected_status, p_resp->status_code);
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
161 Seobeo_Client_Response_Destroy(p_resp);
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
162 Seobeo_Client_Request_Destroy(p_req);
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
163 return -1;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
164 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
165
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
166 printf(" ✓ Status code: %d\n", p_resp->status_code);
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
167
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
168 if (p_resp->status_code == 200)
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
169 {
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
170 if (!test->expected_content)
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
171 {
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
172 printf(" ✗ No expected snapshot found: %s\n", test->expected_file_path);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
173 printf(" → Run: bazel run //mrjunejune:create_snapshots\n");
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
174 Seobeo_Client_Response_Destroy(p_resp);
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
175 Seobeo_Client_Request_Destroy(p_req);
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
176 return -1;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
177 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
178
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
179 if (strcmp(p_resp->body, test->expected_content) != 0)
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
180 {
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
181 printf(" ✗ Response does not match expected snapshot\n");
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
182 printf(" Expected file: %s\n", test->expected_file_path);
128
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
183 debug_diff(p_resp->body, test->expected_content);
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
184 Seobeo_Client_Response_Destroy(p_resp);
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
185 Seobeo_Client_Request_Destroy(p_req);
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
186 return -1;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
187 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
188
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
189 printf(" ✓ Response matches snapshot (%zu bytes)\n", p_resp->body_length);
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
190 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
191
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
192 Seobeo_Client_Response_Destroy(p_resp);
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
193 Seobeo_Client_Request_Destroy(p_req);
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
194 return 0;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
195 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
196
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
197 int send_post_file(Seobeo_Handle *p_req, const char *path, const char *file_data, size_t file_size)
94
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
198 {
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
199 char request_buffer[8192];
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
200 int header_len = snprintf(
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
201 request_buffer, sizeof(request_buffer),
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
202 "POST %s HTTP/1.1\r\n"
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
203 "Host: %s\r\n"
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
204 "Content-Type: application/octet-stream\r\n"
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
205 "Content-Length: %zu\r\n"
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
206 "Connection: close\r\n"
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
207 "\r\n",
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
208 path, TEST_HOST, file_size
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
209 );
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
210
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
211 if (header_len < 0 || header_len >= sizeof(request_buffer))
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
212 {
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
213 fprintf(stderr, "Request header too large\n");
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
214 return -1;
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
215 }
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
216
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
217 // Send headers
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
218 Seobeo_Handle_Queue(p_req, (uint8*)request_buffer, (uint32)header_len);
94
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
219
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
220 // Send file data in chunks if needed
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
221 size_t remaining = file_size;
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
222 const char *ptr = file_data;
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
223 while (remaining > 0)
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
224 {
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
225 size_t chunk_size = remaining > 4096 ? 4096 : remaining;
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
226 Seobeo_Handle_Queue(p_req, (uint8*)ptr, (uint32)chunk_size);
94
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
227 ptr += chunk_size;
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
228 remaining -= chunk_size;
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
229 }
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
230
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
231 return Seobeo_Handle_Flush(p_req);
94
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
232 }
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
233
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
234 char* extract_json_field(const char *json, const char *field, char *buffer, size_t buffer_size)
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
235 {
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
236 char search_pattern[256];
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
237 snprintf(search_pattern, sizeof(search_pattern), "\"%s\":\"", field);
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
238
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
239 const char *start = strstr(json, search_pattern);
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
240 if (!start)
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
241 {
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
242 return NULL;
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
243 }
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
244
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
245 start += strlen(search_pattern);
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
246 const char *end = strchr(start, '"');
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
247 if (!end)
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
248 {
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
249 return NULL;
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
250 }
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
251
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
252 size_t len = end - start;
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
253 if (len >= buffer_size)
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
254 {
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
255 len = buffer_size - 1;
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
256 }
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
257
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
258 memcpy(buffer, start, len);
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
259 buffer[len] = '\0';
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
260
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
261 return buffer;
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
262 }
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
263
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
264 int test_file_conversion(const char *endpoint, const char *test_file_path,
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
265 const char *expected_format, pid_t server_pid)
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
266 {
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
267 printf(" Testing: POST %s\n", endpoint);
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
268
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
269 // Read test file
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
270 size_t file_size;
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
271 char *file_data = read_file(test_file_path, &file_size);
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
272 if (!file_data) {
94
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
273 printf(" ✗ Failed to read test file: %s\n", test_file_path);
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
274 return -1;
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
275 }
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
276
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
277 char url[1024];
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
278 snprintf(url, sizeof(url), "%s%s", TEST_URL, endpoint);
94
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
279
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
280 Seobeo_Client_Request *p_req = Seobeo_Client_Request_Create(url);
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
281 Seobeo_Client_Request_Set_Method(p_req, "POST");
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
282 Seobeo_Client_Request_Set_Body(p_req, (uint8*)file_data, (uint32)file_size);
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
283 Seobeo_Client_Request_Add_Header_Array(p_req, "Content-Type: application/octet-stream");
94
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
284
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
285 Seobeo_Client_Response *p_resp = Seobeo_Client_Request_Execute(p_req);
94
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
286 free(file_data);
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
287
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
288 if (!p_resp || p_resp->status_code != 200) {
168
f3084bca7317 [Misc] Fixed all errors and all tests should pass now.
MrJuneJune <me@mrjunejune.com>
parents: 128
diff changeset
289 printf(" ✗ Conversion failed with status: %d, %s\n", p_resp ? p_resp->status_code : 0, p_resp->body);
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
290 if (p_resp) Seobeo_Client_Response_Destroy(p_resp);
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
291 Seobeo_Client_Request_Destroy(p_req);
94
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
292 return -1;
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
293 }
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
294
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
295 // Extract download URL from JSON body
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
296 char download_url_path[512];
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
297 if (!extract_json_field((char*)p_resp->body, "download_url", download_url_path, sizeof(download_url_path))) {
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
298 printf(" ✗ Failed to extract download_url\n");
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
299 Seobeo_Client_Response_Destroy(p_resp);
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
300 Seobeo_Client_Request_Destroy(p_req);
94
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
301 return -1;
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
302 }
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
303
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
304 printf(" ✓ Conversion succeeded. Download URL: %s\n", download_url_path);
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
305 Seobeo_Client_Response_Destroy(p_resp);
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
306 Seobeo_Client_Request_Destroy(p_req);
94
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
307
168
f3084bca7317 [Misc] Fixed all errors and all tests should pass now.
MrJuneJune <me@mrjunejune.com>
parents: 128
diff changeset
308 usleep(100000);
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
309 printf(" → Testing download: GET %s\n", download_url_path);
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
310 char full_download_url[1024];
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
311 snprintf(full_download_url, sizeof(full_download_url), "%s%s", TEST_URL, download_url_path);
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
312
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
313 p_req = Seobeo_Client_Request_Create(full_download_url);
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
314 p_resp = Seobeo_Client_Request_Execute(p_req);
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
315
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
316 if (!p_resp || p_resp->status_code != 200)
94
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
317 {
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
318 printf(" ✗ Download failed\n");
168
f3084bca7317 [Misc] Fixed all errors and all tests should pass now.
MrJuneJune <me@mrjunejune.com>
parents: 128
diff changeset
319 printf("%s\n", p_resp->body);
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
320 if (p_resp) Seobeo_Client_Response_Destroy(p_resp);
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
321 Seobeo_Client_Request_Destroy(p_req);
94
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
322 return -1;
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
323 }
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
324
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
325 printf(" ✓ Downloaded converted file (%u bytes)\n", p_resp->body_length);
94
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
326
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
327 Seobeo_Client_Response_Destroy(p_resp);
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
328 Seobeo_Client_Request_Destroy(p_req);
94
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
329 return 0;
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
330 }
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
331
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
332 // Helper: Initialize test case with snapshot file
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
333 void init_test_case(TestCase *test)
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
334 {
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
335 char filename[256];
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
336 path_to_filename(test->path, filename, sizeof(filename));
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
337
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
338 test->expected_file_path = malloc(512);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
339 snprintf(test->expected_file_path, 512, "%s/%s", SNAPSHOT_DIR, filename);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
340
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
341 // Load expected content from snapshot file
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
342 load_expected_content(test);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
343 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
344
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
345 // Helper: Cleanup test case
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
346 void cleanup_test_case(TestCase *test)
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
347 {
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
348 if (test->actual_response)
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
349 {
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
350 free(test->actual_response);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
351 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
352 if (test->expected_file_path)
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
353 {
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
354 free(test->expected_file_path);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
355 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
356 if (test->expected_content)
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
357 {
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
358 free((void*)test->expected_content);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
359 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
360 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
361
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
362 // Main integration test
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
363 int test_server_client_integration(const char *server_binary)
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
364 {
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
365 printf("=== Server-p_req Integration Test ===\n");
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
366 printf("MODE: Verifying Against Snapshots\n\n");
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
367
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
368 char cwd[1024];
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
369 if (getcwd(cwd, sizeof(cwd)) != NULL)
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
370 printf("Working directory: %s\n", cwd);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
371
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
372 if (access(server_binary, X_OK) != 0)
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
373 {
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
374 printf("Server binary not found: %s\n", server_binary);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
375 perror("access");
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
376 return -1;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
377 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
378 printf("Server binary: %s\n", server_binary);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
379 printf("Snapshot directory: %s\n\n", SNAPSHOT_DIR);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
380
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
381 pid_t server_pid = start_test_server(server_binary);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
382 if (server_pid < 0)
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
383 return -1;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
384
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
385 int failed_tests = 0;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
386 int passed_tests = 0;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
387
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
388 TestCase success_tests[] = {
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
389 {"/", 200, NULL, NULL, NULL, 0},
94
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
390 {"/resume", 200, NULL, NULL, NULL, 0},
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
391 {"/tools", 200, NULL, NULL, NULL, 0},
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
392 {"/tools/markdown_to_html", 200, NULL, NULL, NULL, 0},
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
393 {"/tools/file_converter", 200, NULL, NULL, NULL, 0},
242
543df0fe7168 [tools] Add full HLS player support
MrJuneJune <me@mrjunejune.com>
parents: 168
diff changeset
394 {"/tools/hls_player", 200, NULL, NULL, NULL, 0},
244
b8aa08503378 [tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents: 242
diff changeset
395 {"/tools/latex_editor", 200, NULL, NULL, NULL, 0},
128
7eb79fd91c7e [Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents: 126
diff changeset
396 {"/talk", 200, NULL, NULL, NULL, 0},
260
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 259
diff changeset
397 {"/jrpg", 200, NULL, NULL, NULL, 0},
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
398 };
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
399 int num_success_tests = sizeof(success_tests) / sizeof(success_tests[0]);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
400
94
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
401 TestCase redirect_tests[] = {
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
402 {"/index.html", 301, NULL, NULL, NULL, 0},
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
403 {"/resume/index.html", 301, NULL, NULL, NULL, 0},
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
404 {"/tools/index.html", 301, NULL, NULL, NULL, 0},
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
405 {"/tools/markdown_to_html/index.html", 301, NULL, NULL, NULL, 0},
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
406 {"/tools/file_converter/index.html", 301, NULL, NULL, NULL, 0},
242
543df0fe7168 [tools] Add full HLS player support
MrJuneJune <me@mrjunejune.com>
parents: 168
diff changeset
407 {"/tools/hls_player/index.html", 301, NULL, NULL, NULL, 0},
244
b8aa08503378 [tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents: 242
diff changeset
408 {"/tools/latex_editor/index.html", 301, NULL, NULL, NULL, 0},
260
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 259
diff changeset
409 {"/jrpg/index.html", 301, NULL, NULL, NULL, 0},
94
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
410 };
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
411 int num_redirect_tests = sizeof(redirect_tests) / sizeof(redirect_tests[0]);
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
412
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
413 TestCase failure_tests[] = {
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
414 {"/nonexistent", 404, NULL, NULL, NULL, 0},
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
415 {"/does/not/exist", 404, NULL, NULL, NULL, 0},
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
416 {"/missing.html", 404, NULL, NULL, NULL, 0},
260
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 259
diff changeset
417 {"/api/inference/health", 503, NULL, NULL, NULL, 0},
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
418 };
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
419 int num_failure_tests = sizeof(failure_tests) / sizeof(failure_tests[0]);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
420
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
421 for (int i = 0; i < num_success_tests; i++)
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
422 init_test_case(&success_tests[i]);
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
423
94
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
424 for (int i = 0; i < num_redirect_tests; i++)
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
425 init_test_case(&redirect_tests[i]);
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
426
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
427 for (int i = 0; i < num_failure_tests; i++)
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
428 init_test_case(&failure_tests[i]);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
429
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
430 printf("Running tests for paths that should succeed:\n");
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
431 for (int i = 0; i < num_success_tests; i++)
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
432 {
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
433 if (execute_test_case(&success_tests[i], server_pid) == 0)
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
434 passed_tests++;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
435 else
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
436 failed_tests++;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
437 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
438
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
439 printf("\n");
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
440
94
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
441 printf("Running tests for paths that should redirect:\n");
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
442 for (int i = 0; i < num_redirect_tests; i++)
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
443 {
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
444 if (execute_test_case(&redirect_tests[i], server_pid) == 0)
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
445 passed_tests++;
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
446 else
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
447 failed_tests++;
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
448 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
449
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
450 printf("\n");
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
451
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
452 printf("Running tests for paths that should fail:\n");
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
453 for (int i = 0; i < num_failure_tests; i++)
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
454 {
126
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
455 if (execute_test_case(&failure_tests[i], server_pid) == 0)
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
456 passed_tests++;
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
457 else
e7899c93da77 Remove playground.
June Park <parkjune1995@gmail.com>
parents: 122
diff changeset
458 failed_tests++;
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
459 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
460
94
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
461 printf("\n");
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
462
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
463 printf("Running tests for POST conversion endpoints:\n");
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
464 if (test_file_conversion("/api/convert/image-to-webp",
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
465 "mrjunejune/test/shiba.webp",
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
466 "image/webp",
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
467 server_pid) == 0)
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
468 passed_tests++;
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
469 else
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
470 failed_tests++;
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
471
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
472 printf("\n");
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
473
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
474 if (test_file_conversion("/api/convert/video-to-mp4",
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
475 "mrjunejune/test/test_avi.avi",
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
476 "video/mp4",
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
477 server_pid) == 0)
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
478 passed_tests++;
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
479 else
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
480 failed_tests++;
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
481
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
482 for (int i = 0; i < num_success_tests; i++)
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
483 cleanup_test_case(&success_tests[i]);
94
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
484 for (int i = 0; i < num_redirect_tests; i++)
092afa595764 [MrJuneJune] Added Integration tests.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
485 cleanup_test_case(&redirect_tests[i]);
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
486 for (int i = 0; i < num_failure_tests; i++)
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
487 cleanup_test_case(&failure_tests[i]);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
488
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
489 stop_test_server(server_pid);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
490
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
491 printf("\n=== Test Summary ===\n");
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
492 printf("Passed: %d\n", passed_tests);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
493 printf("Failed: %d\n", failed_tests);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
494
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
495 return (failed_tests == 0) ? 0 : -1;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
496 }
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
497
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
498 int main(int argc, char *argv[])
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
499 {
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
500 printf("=== Seobeo Integration Tests ===\n\n");
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
501
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
502 const char *server_binary = "./mrjunejune_server";
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
503 if (argc > 1)
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
504 server_binary = argv[1];
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
505
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
506 int result = test_server_client_integration(server_binary);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
507
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
508 if (result == 0)
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
509 printf("\n✓ All tests passed!\n");
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
510 else
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
511 printf("\n✗ Some tests failed\n");
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
512
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
513 return result;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
514 }