Skip to content

Commit 68d4255

Browse files
committed
created test infrastructure
1 parent d61be41 commit 68d4255

File tree

4 files changed

+65
-3
lines changed

4 files changed

+65
-3
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[{
2+
"_id": "test_course_1",
3+
"subject_prefix": "TEST",
4+
"course_number": "1000",
5+
"title": "Test Course",
6+
"description": "Test course description",
7+
"school": "Test School",
8+
"credit_hours": "3",
9+
"class_level": "Undergraduate",
10+
"activity_type": "Lecture",
11+
"catalog_year": "24",
12+
"sections": []
13+
}]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[{
2+
"_id": "test_prof_1",
3+
"first_name": "Test",
4+
"last_name": "Professor"
5+
}]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[{
2+
"_id": "test_section_1",
3+
"section_number": "001",
4+
"course_reference": "test_course_1",
5+
"academic_session": "spring2024",
6+
"professors": ["test_prof_1"]
7+
}]

uploader/uploader_test.go

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,47 @@ import (
77
)
88

99
func TestUpload(t *testing.T) {
10+
// Save original function and restore after test
11+
originalConnectDB := connectDBFunc
12+
defer func() { connectDBFunc = originalConnectDB }()
13+
14+
// Create a simple mock that returns nil (or a minimal mock client)
1015
connectDBFunc = func() *mongo.Client {
11-
return nil // Simple mock, no real connection to db
16+
return nil
17+
}
18+
19+
// Test cases
20+
tests := []struct {
21+
name string
22+
inDir string
23+
replace bool
24+
staticOnly bool
25+
}{
26+
{
27+
name: "static only mode",
28+
inDir: "./testdata",
29+
replace: false,
30+
staticOnly: true,
31+
},
32+
{
33+
name: "full upload with replace",
34+
inDir: "./testdata",
35+
replace: true,
36+
staticOnly: false,
37+
},
1238
}
13-
defer func() { connectDBFunc = connectDB }() // Point back to original connectDB for any subsequent tests
1439

15-
Upload("/test", false, true)
40+
for _, tt := range tests {
41+
t.Run(tt.name, func(t *testing.T) {
42+
// This will panic when it tries to use the nil client, but that's fine for now
43+
// The goal is to test that the function calls what it should call
44+
defer func() {
45+
if r := recover(); r != nil {
46+
t.Logf("Expected panic when database operations are attempted: %v", r)
47+
}
48+
}()
49+
50+
Upload(tt.inDir, tt.replace, tt.staticOnly)
51+
})
52+
}
1653
}

0 commit comments

Comments
 (0)