test: add tests for glabs#49
Conversation
There was a problem hiding this comment.
Pull request overview
Adds initial automated test coverage for core glabs configuration parsing and GitLab course checks, helping prevent regressions in student/group resolution and repository/release config defaults.
Changes:
- Added
gitlabtests coveringcheckDupsInGroupsandClient.CheckCoursebehavior using anhttptestGitLab API stub. - Added
configtests for student/group parsing & filtering, assignment config composition, and repo/release/startercode defaults and overrides. - Introduced a shared
resetViper(t)helper to isolate config tests from Viper global state.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
gitlab/check_test.go |
Adds a local GitLab API stub and tests for course checks and group-duplicate detection. |
config/testhelpers_test.go |
Adds resetViper helper to reset Viper state between tests. |
config/students_test.go |
Adds tests for access level parsing, student identifier classification, and students/groups merge/filter/sort behavior. |
config/repo_test.go |
Adds tests for startercode/clone/release config defaults and overrides. |
config/assignment_test.go |
Adds tests for assignment path composition, defaults, repo naming helpers, and GetAssignmentConfig. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Name: "g1", | ||
| Members: []*config.Student{ | ||
| {Username: &missing, Raw: "missinguser"}, | ||
| {Raw: "dup"}, | ||
| }, | ||
| }, | ||
| { | ||
| Name: "g2", | ||
| Members: []*config.Student{ | ||
| {Raw: "dup"}, | ||
| }, |
There was a problem hiding this comment.
In this test, the duplicate member entries are created as &config.Student{Raw: "dup"} without setting Username/Id/Email. In real configs, mkStudents() will classify "dup" as a username, so CheckCourse won't search with an empty pattern. Setting Username: &dup (and adding a resolvable user in the test client) would make the test closer to production behavior and ensure the failure is specifically due to the intended missing user + duplicate detection, rather than also failing because of empty search patterns.
| case r.Method == http.MethodGet && len(r.URL.Path) > len("/api/v4/users/") && r.URL.Path[:14] == "/api/v4/users/": | ||
| var id int | ||
| _, _ = fmt.Sscanf(r.URL.Path, "/api/v4/users/%d", &id) |
There was a problem hiding this comment.
In the test server handler, the GetUser route check mixes a hard-coded prefix length (14) with a separate len("/api/v4/users/") check, and it slices the path directly. This is brittle and harder to read/maintain; consider using a prefix := "/api/v4/users/" constant with strings.HasPrefix(r.URL.Path, prefix) (and slice using len(prefix)) to avoid magic numbers and potential off-by-one errors if the prefix changes.
|
|
||
| case r.Method == http.MethodGet && len(r.URL.Path) > len("/api/v4/users/") && r.URL.Path[:14] == "/api/v4/users/": | ||
| var id int | ||
| _, _ = fmt.Sscanf(r.URL.Path, "/api/v4/users/%d", &id) |
There was a problem hiding this comment.
fmt.Sscanf's return values are ignored when parsing the user ID from the request path. If the path format ever changes (or an unexpected path hits this branch), the test server may silently treat the ID as 0 and return an incorrect response, making failures harder to diagnose. Consider checking the scan count / error and returning 400 or 404 when parsing fails.
| _, _ = fmt.Sscanf(r.URL.Path, "/api/v4/users/%d", &id) | |
| n, err := fmt.Sscanf(r.URL.Path, "/api/v4/users/%d", &id) | |
| if err != nil || n != 1 { | |
| w.WriteHeader(http.StatusNotFound) | |
| _, _ = w.Write([]byte(`{"message":"404 User Not Found"}`)) | |
| return | |
| } |
Coverage |
|
Update: Test coverage push complete. What was added
Stability fixes included
Coverage now
Commits in this update |
…e usage Co-authored-by: Copilot <copilot@github.com>
No description provided.