Skip to content

test: add tests for glabs#49

Merged
obcode merged 17 commits into
mainfrom
feature/testing
Apr 23, 2026
Merged

test: add tests for glabs#49
obcode merged 17 commits into
mainfrom
feature/testing

Conversation

@obcode

@obcode obcode commented Apr 23, 2026

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings April 23, 2026 06:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 gitlab tests covering checkDupsInGroups and Client.CheckCourse behavior using an httptest GitLab API stub.
  • Added config tests 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.

Comment thread gitlab/check_test.go
Comment on lines +136 to +146
Name: "g1",
Members: []*config.Student{
{Username: &missing, Raw: "missinguser"},
{Raw: "dup"},
},
},
{
Name: "g2",
Members: []*config.Student{
{Raw: "dup"},
},

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread gitlab/check_test.go
Comment on lines +37 to +39
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)

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread gitlab/check_test.go

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)

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
_, _ = 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
}

Copilot uses AI. Check for mistakes.
@github-actions

github-actions Bot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Coverage

github.com/obcode/glabs/cmd/archive.go:12:		init				100.0%
github.com/obcode/glabs/cmd/check.go:10:		init				100.0%
github.com/obcode/glabs/cmd/clone.go:45:		init				100.0%
github.com/obcode/glabs/cmd/delete.go:12:		init				100.0%
github.com/obcode/glabs/cmd/generate.go:12:		init				100.0%
github.com/obcode/glabs/cmd/protect.go:12:		init				100.0%
github.com/obcode/glabs/cmd/report.go:14:		init				100.0%
github.com/obcode/glabs/cmd/root.go:39:			Execute				0.0%
github.com/obcode/glabs/cmd/root.go:43:			init				100.0%
github.com/obcode/glabs/cmd/root.go:51:			er				0.0%
github.com/obcode/glabs/cmd/root.go:56:			initConfig			0.0%
github.com/obcode/glabs/cmd/setaccess.go:12:		init				100.0%
github.com/obcode/glabs/cmd/show.go:8:			init				100.0%
github.com/obcode/glabs/cmd/update.go:12:		init				100.0%
github.com/obcode/glabs/cmd/urls.go:22:			init				100.0%
github.com/obcode/glabs/cmd/version.go:10:		init				100.0%
github.com/obcode/glabs/config/assignment.go:11:	String				100.0%
github.com/obcode/glabs/config/assignment.go:24:	GetAssignmentConfig		85.7%
github.com/obcode/glabs/config/assignment.go:73:	RepoSuffix			100.0%
github.com/obcode/glabs/config/assignment.go:87:	RepoBaseName			100.0%
github.com/obcode/glabs/config/assignment.go:95:	RepoNameWithSuffix		100.0%
github.com/obcode/glabs/config/assignment.go:99:	RepoNameForStudent		100.0%
github.com/obcode/glabs/config/assignment.go:103:	RepoNameForGroup		100.0%
github.com/obcode/glabs/config/assignment.go:107:	assignmentPath			100.0%
github.com/obcode/glabs/config/assignment.go:121:	per				100.0%
github.com/obcode/glabs/config/assignment.go:128:	description			100.0%
github.com/obcode/glabs/config/course.go:14:		GetCourseConfig			50.0%
github.com/obcode/glabs/config/release.go:8:		release				60.0%
github.com/obcode/glabs/config/release.go:22:		mergeRequest			100.0%
github.com/obcode/glabs/config/release.go:46:		dockerImages			100.0%
github.com/obcode/glabs/config/repo.go:8:		startercode			92.6%
github.com/obcode/glabs/config/repo.go:65:		clone				100.0%
github.com/obcode/glabs/config/repo.go:87:		SetBranch			100.0%
github.com/obcode/glabs/config/repo.go:91:		SetProtectToBranch		100.0%
github.com/obcode/glabs/config/repo.go:98:		SetLocalpath			100.0%
github.com/obcode/glabs/config/repo.go:102:		SetForce			100.0%
github.com/obcode/glabs/config/seeder.go:15:		seeder				53.8%
github.com/obcode/glabs/config/show.go:10:		Show				100.0%
github.com/obcode/glabs/config/students.go:14:		SetAccessLevel			100.0%
github.com/obcode/glabs/config/students.go:28:		accessLevel			100.0%
github.com/obcode/glabs/config/students.go:43:		students			100.0%
github.com/obcode/glabs/config/students.go:75:		mkStudents			94.4%
github.com/obcode/glabs/config/students.go:108:		groups				100.0%
github.com/obcode/glabs/config/urls.go:5:		Urls				100.0%
github.com/obcode/glabs/git/auth.go:11:			GetAuth				90.0%
github.com/obcode/glabs/git/clone.go:18:		Clone				80.0%
github.com/obcode/glabs/git/clone.go:38:		cloneurl			100.0%
github.com/obcode/glabs/git/clone.go:44:		localpath			100.0%
github.com/obcode/glabs/git/clone.go:48:		clone				36.1%
github.com/obcode/glabs/git/starterrepo.go:22:		PrepareStartercodeRepo		0.0%
github.com/obcode/glabs/gitlab/archive.go:14:		Archive				77.8%
github.com/obcode/glabs/gitlab/archive.go:32:		archivePerStudent		90.9%
github.com/obcode/glabs/gitlab/archive.go:54:		archivePerGroup			90.9%
github.com/obcode/glabs/gitlab/archive.go:76:		archive				75.6%
github.com/obcode/glabs/gitlab/check.go:9:		CheckCourse			90.6%
github.com/obcode/glabs/gitlab/check.go:67:		checkStudent			100.0%
github.com/obcode/glabs/gitlab/check.go:89:		checkDupsInGroups		100.0%
github.com/obcode/glabs/gitlab/delete.go:11:		Delete				77.8%
github.com/obcode/glabs/gitlab/delete.go:29:		deletePerStudent		100.0%
github.com/obcode/glabs/gitlab/delete.go:40:		deletePerGroup			100.0%
github.com/obcode/glabs/gitlab/delete.go:51:		delete				92.9%
github.com/obcode/glabs/gitlab/generate.go:14:		Generate			38.9%
github.com/obcode/glabs/gitlab/generate.go:51:		generate			0.0%
github.com/obcode/glabs/gitlab/generate.go:213:		generatePerStudent		0.0%
github.com/obcode/glabs/gitlab/generate.go:226:		generatePerGroup		0.0%
github.com/obcode/glabs/gitlab/gitlab.go:13:		NewClient			80.0%
github.com/obcode/glabs/gitlab/groups.go:12:		getGroupIDByFullPath		100.0%
github.com/obcode/glabs/gitlab/groups.go:33:		getGroupID			100.0%
github.com/obcode/glabs/gitlab/groups.go:46:		createGroup			83.3%
github.com/obcode/glabs/gitlab/issues.go:14:		getStartercodeProject		100.0%
github.com/obcode/glabs/gitlab/issues.go:58:		replicateIssue			100.0%
github.com/obcode/glabs/gitlab/projects.go:12:		generateProject			75.0%
github.com/obcode/glabs/gitlab/projects.go:50:		getProjectByName		80.0%
github.com/obcode/glabs/gitlab/protect.go:14:		ProtectToBranch			77.8%
github.com/obcode/glabs/gitlab/protect.go:32:		protectBranch			56.1%
github.com/obcode/glabs/gitlab/protect.go:134:		protectSingleBranch		100.0%
github.com/obcode/glabs/gitlab/protect.go:169:		protectToBranchPerStudent	90.9%
github.com/obcode/glabs/gitlab/protect.go:191:		protectToBranchPerGroup		72.7%
github.com/obcode/glabs/gitlab/report.go:14:		Report				78.9%
github.com/obcode/glabs/gitlab/report.go:51:		ReportHTML			73.7%
github.com/obcode/glabs/gitlab/report.go:86:		ReportJSON			77.8%
github.com/obcode/glabs/gitlab/report_helper.go:17:	report				82.5%
github.com/obcode/glabs/gitlab/report_helper.go:135:	projectReport			85.9%
github.com/obcode/glabs/gitlab/seeder.go:21:		localpath			0.0%
github.com/obcode/glabs/gitlab/seeder.go:25:		runSeeder			0.0%
github.com/obcode/glabs/gitlab/seeder.go:100:		addAndCommit			0.0%
github.com/obcode/glabs/gitlab/seeder.go:121:		push				0.0%
github.com/obcode/glabs/gitlab/setaccess.go:14:		Setaccess			77.8%
github.com/obcode/glabs/gitlab/setaccess.go:32:		setaccess			41.5%
github.com/obcode/glabs/gitlab/setaccess.go:140:	inviteByEmail			100.0%
github.com/obcode/glabs/gitlab/setaccess.go:155:	setaccessPerStudent		100.0%
github.com/obcode/glabs/gitlab/setaccess.go:175:	setaccessPerGroup		80.0%
github.com/obcode/glabs/gitlab/starterrepo.go:14:	pushStartercode			0.0%
github.com/obcode/glabs/gitlab/starterrepo.go:110:	devBranch			0.0%
github.com/obcode/glabs/gitlab/update.go:15:		Update				60.0%
github.com/obcode/glabs/gitlab/update.go:44:		update				31.6%
github.com/obcode/glabs/gitlab/update.go:91:		updatePerStudent		100.0%
github.com/obcode/glabs/gitlab/update.go:111:		updatePerGroup			100.0%
github.com/obcode/glabs/gitlab/users.go:12:		getUser				95.0%
github.com/obcode/glabs/gitlab/users.go:49:		getUserID			100.0%
github.com/obcode/glabs/gitlab/users.go:63:		addMember			94.1%
github.com/obcode/glabs/main.go:18:			main				0.0%
total:							(statements)			64.8%

@obcode

obcode commented Apr 23, 2026

Copy link
Copy Markdown
Owner Author

Update: Test coverage push complete.

What was added

  • Broad contract/unit tests for config, git, and gitlab packages
  • Additional smoke tests for cmd package
  • Additional runtime tests for git clone flows
  • Additional contract tests for gitlab issue replication

Stability fixes included

  • Fixed pagination break behavior in report helper to avoid hanging test loops
  • Stabilized report/issues mock payloads for GitLab client unmarshalling

Coverage now

  • Total: 64.8%
  • cmd: 31.1%
  • config: 92.2%
  • git: 39.0%
  • gitlab: 60.1%

Commits in this update

  • 706072c test: add broad happy-path edge and error coverage
  • 07def9b test: raise coverage for cmd, git clone, and gitlab issues

@obcode obcode merged commit 90503d7 into main Apr 23, 2026
10 checks passed
@obcode obcode deleted the feature/testing branch April 23, 2026 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants