From 5fc117e2c24c579af00c4cdfbfa81115069bc24c Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 3 Dec 2024 14:48:28 -0800 Subject: [PATCH] Removed CMDs that the general API CMD supports. --- cmd/assignment-get/expected_output_test.go | 9 -- cmd/assignment-get/main.go | 41 --------- cmd/assignment-get/main_test.go | 54 ----------- cmd/assignments-list/expected_output_test.go | 11 --- cmd/assignments-list/main.go | 37 -------- cmd/assignments-list/main_test.go | 40 -------- cmd/course-user-drop/expected_output_test.go | 11 --- cmd/course-user-drop/main.go | 41 --------- cmd/course-user-drop/main_test.go | 53 ----------- cmd/course-user-get/expected_output_test.go | 19 ---- cmd/course-user-get/main.go | 43 --------- cmd/course-user-get/main_test.go | 60 ------------ cmd/describe-api/main.go | 36 -------- cmd/lms-fetch-user/main.go | 47 ---------- cmd/logs-query/main.go | 61 ------------- cmd/peek-submission/expected_output_test.go | 61 ------------- cmd/peek-submission/main.go | 49 ---------- cmd/peek-submission/main_test.go | 96 -------------------- cmd/user-get/expected_output_test.go | 19 ---- cmd/user-get/main.go | 39 -------- cmd/user-get/main_test.go | 39 -------- cmd/user-remove/expected_output_test.go | 11 --- cmd/user-remove/main.go | 37 -------- cmd/user-remove/main_test.go | 41 --------- 24 files changed, 955 deletions(-) delete mode 100644 cmd/assignment-get/expected_output_test.go delete mode 100644 cmd/assignment-get/main.go delete mode 100644 cmd/assignment-get/main_test.go delete mode 100644 cmd/assignments-list/expected_output_test.go delete mode 100644 cmd/assignments-list/main.go delete mode 100644 cmd/assignments-list/main_test.go delete mode 100644 cmd/course-user-drop/expected_output_test.go delete mode 100644 cmd/course-user-drop/main.go delete mode 100644 cmd/course-user-drop/main_test.go delete mode 100644 cmd/course-user-get/expected_output_test.go delete mode 100644 cmd/course-user-get/main.go delete mode 100644 cmd/course-user-get/main_test.go delete mode 100644 cmd/describe-api/main.go delete mode 100644 cmd/lms-fetch-user/main.go delete mode 100644 cmd/logs-query/main.go delete mode 100644 cmd/peek-submission/expected_output_test.go delete mode 100644 cmd/peek-submission/main.go delete mode 100644 cmd/peek-submission/main_test.go delete mode 100644 cmd/user-get/expected_output_test.go delete mode 100644 cmd/user-get/main.go delete mode 100644 cmd/user-get/main_test.go delete mode 100644 cmd/user-remove/expected_output_test.go delete mode 100644 cmd/user-remove/main.go delete mode 100644 cmd/user-remove/main_test.go diff --git a/cmd/assignment-get/expected_output_test.go b/cmd/assignment-get/expected_output_test.go deleted file mode 100644 index 32b6ca54..00000000 --- a/cmd/assignment-get/expected_output_test.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -const COURSE_ASSIGNMENT_FOUND = `{ - "assignment": { - "id": "hw0", - "name": "Homework 0" - } -} -` diff --git a/cmd/assignment-get/main.go b/cmd/assignment-get/main.go deleted file mode 100644 index 1d081a9d..00000000 --- a/cmd/assignment-get/main.go +++ /dev/null @@ -1,41 +0,0 @@ -package main - -import ( - "github.com/alecthomas/kong" - - "github.com/edulinq/autograder/internal/api/core" - "github.com/edulinq/autograder/internal/api/courses/assignments" - "github.com/edulinq/autograder/internal/cmd" - "github.com/edulinq/autograder/internal/config" - "github.com/edulinq/autograder/internal/log" -) - -var args struct { - config.ConfigArgs - cmd.CommonOptions - - CourseID string `help:"ID of the course." arg:""` - AssignmentID string `help:"ID of the assignment." arg:""` -} - -func main() { - kong.Parse(&args, - kong.Description("Get the information for a course assignment."), - ) - - err := config.HandleConfigArgs(args.ConfigArgs) - if err != nil { - log.Fatal("Failed to load config options.", err) - } - - request := assignments.GetRequest{ - APIRequestAssignmentContext: core.APIRequestAssignmentContext{ - APIRequestCourseUserContext: core.APIRequestCourseUserContext{ - CourseID: args.CourseID, - }, - AssignmentID: args.AssignmentID, - }, - } - - cmd.MustHandleCMDRequestAndExitFull(`courses/assignments/get`, request, assignments.GetResponse{}, args.CommonOptions, nil) -} diff --git a/cmd/assignment-get/main_test.go b/cmd/assignment-get/main_test.go deleted file mode 100644 index 7f9d2242..00000000 --- a/cmd/assignment-get/main_test.go +++ /dev/null @@ -1,54 +0,0 @@ -package main - -import ( - "fmt" - "testing" - - "github.com/edulinq/autograder/internal/cmd" -) - -// Use the common main for all tests in this package. -func TestMain(suite *testing.M) { - cmd.CMDServerTestingMain(suite) -} - -func TestAssignmentGetBase(test *testing.T) { - testCases := []struct { - cmd.CommonCMDTestCase - courseID string - assignmentID string - }{ - { - CommonCMDTestCase: cmd.CommonCMDTestCase{ - ExpectedStdout: COURSE_ASSIGNMENT_FOUND, - }, - courseID: "course101", - assignmentID: "hw0", - }, - { - CommonCMDTestCase: cmd.CommonCMDTestCase{ - ExpectedExitCode: 1, - ExpectedStderrSubstring: `Could not find course: 'ZZZ'.`, - }, - courseID: "ZZZ", - assignmentID: "hw0", - }, - { - CommonCMDTestCase: cmd.CommonCMDTestCase{ - ExpectedExitCode: 1, - ExpectedStderrSubstring: `Could not find assignment: 'zzz'.`, - }, - courseID: "course101", - assignmentID: "zzz", - }, - } - - for i, testCase := range testCases { - args := []string{ - testCase.courseID, - testCase.assignmentID, - } - - cmd.RunCommonCMDTests(test, main, args, testCase.CommonCMDTestCase, fmt.Sprintf("Case %d: ", i)) - } -} diff --git a/cmd/assignments-list/expected_output_test.go b/cmd/assignments-list/expected_output_test.go deleted file mode 100644 index 749df335..00000000 --- a/cmd/assignments-list/expected_output_test.go +++ /dev/null @@ -1,11 +0,0 @@ -package main - -const EXPECTED_ASSIGNMENT_LIST = `{ - "assignments": [ - { - "id": "hw0", - "name": "Homework 0" - } - ] -} -` diff --git a/cmd/assignments-list/main.go b/cmd/assignments-list/main.go deleted file mode 100644 index 20189cc4..00000000 --- a/cmd/assignments-list/main.go +++ /dev/null @@ -1,37 +0,0 @@ -package main - -import ( - "github.com/alecthomas/kong" - - "github.com/edulinq/autograder/internal/api/core" - "github.com/edulinq/autograder/internal/api/courses/assignments" - "github.com/edulinq/autograder/internal/cmd" - "github.com/edulinq/autograder/internal/config" - "github.com/edulinq/autograder/internal/log" -) - -var args struct { - config.ConfigArgs - cmd.CommonOptions - - CourseID string `help:"ID of the course." arg:""` -} - -func main() { - kong.Parse(&args, - kong.Description("List the assignments from the course."), - ) - - err := config.HandleConfigArgs(args.ConfigArgs) - if err != nil { - log.Fatal("Could not load config options.", err) - } - - request := assignments.ListRequest{ - APIRequestCourseUserContext: core.APIRequestCourseUserContext{ - CourseID: args.CourseID, - }, - } - - cmd.MustHandleCMDRequestAndExitFull(`courses/assignments/list`, request, assignments.ListResponse{}, args.CommonOptions, nil) -} diff --git a/cmd/assignments-list/main_test.go b/cmd/assignments-list/main_test.go deleted file mode 100644 index ecd32c53..00000000 --- a/cmd/assignments-list/main_test.go +++ /dev/null @@ -1,40 +0,0 @@ -package main - -import ( - "fmt" - "testing" - - "github.com/edulinq/autograder/internal/cmd" -) - -// Use the common main for all tests in this package. -func TestMain(suite *testing.M) { - cmd.CMDServerTestingMain(suite) -} - -func TestAssignmentListBase(test *testing.T) { - testCases := []struct { - CommonCMDTestCase cmd.CommonCMDTestCase - courseID string - }{ - { - CommonCMDTestCase: cmd.CommonCMDTestCase{ - ExpectedStdout: EXPECTED_ASSIGNMENT_LIST, - }, - courseID: "course101", - }, - { - CommonCMDTestCase: cmd.CommonCMDTestCase{ - ExpectedExitCode: 1, - ExpectedStderrSubstring: `Could not find course: 'ZZZ'`, - }, - courseID: "ZZZ", - }, - } - - for i, testCase := range testCases { - args := []string{testCase.courseID} - - cmd.RunCommonCMDTests(test, main, args, testCase.CommonCMDTestCase, fmt.Sprintf("Case %d: ", i)) - } -} diff --git a/cmd/course-user-drop/expected_output_test.go b/cmd/course-user-drop/expected_output_test.go deleted file mode 100644 index 8f216892..00000000 --- a/cmd/course-user-drop/expected_output_test.go +++ /dev/null @@ -1,11 +0,0 @@ -package main - -const USER_FOUND = `{ - "found-user": true -} -` - -const USER_NOT_FOUND = `{ - "found-user": false -} -` diff --git a/cmd/course-user-drop/main.go b/cmd/course-user-drop/main.go deleted file mode 100644 index c406b628..00000000 --- a/cmd/course-user-drop/main.go +++ /dev/null @@ -1,41 +0,0 @@ -package main - -import ( - "github.com/alecthomas/kong" - - "github.com/edulinq/autograder/internal/api/core" - "github.com/edulinq/autograder/internal/api/courses/users" - "github.com/edulinq/autograder/internal/cmd" - "github.com/edulinq/autograder/internal/config" - "github.com/edulinq/autograder/internal/log" -) - -var args struct { - config.ConfigArgs - cmd.CommonOptions - - TargetEmail string `help:"Email of the user to drop." arg:""` - CourseID string `help:"ID of the course." arg:""` -} - -func main() { - kong.Parse(&args, - kong.Description("Drop a user from the course."), - ) - - err := config.HandleConfigArgs(args.ConfigArgs) - if err != nil { - log.Fatal("Failed to load config options.", err) - } - - request := users.DropRequest{ - APIRequestCourseUserContext: core.APIRequestCourseUserContext{ - CourseID: args.CourseID, - }, - TargetCourseUser: core.TargetCourseUser{ - Email: args.TargetEmail, - }, - } - - cmd.MustHandleCMDRequestAndExitFull(`courses/users/drop`, request, users.DropResponse{}, args.CommonOptions, nil) -} diff --git a/cmd/course-user-drop/main_test.go b/cmd/course-user-drop/main_test.go deleted file mode 100644 index d693bf14..00000000 --- a/cmd/course-user-drop/main_test.go +++ /dev/null @@ -1,53 +0,0 @@ -package main - -import ( - "fmt" - "testing" - - "github.com/edulinq/autograder/internal/cmd" -) - -// Use the common main for all tests in this package. -func TestMain(suite *testing.M) { - cmd.CMDServerTestingMain(suite) -} - -func TestCourseUserDropBase(test *testing.T) { - testCases := []struct { - cmd.CommonCMDTestCase - targetEmail string - courseID string - }{ - { - CommonCMDTestCase: cmd.CommonCMDTestCase{ - ExpectedStdout: USER_FOUND, - }, - targetEmail: "course-student@test.edulinq.org", - courseID: "course101", - }, - { - CommonCMDTestCase: cmd.CommonCMDTestCase{ - ExpectedStdout: USER_NOT_FOUND, - }, - targetEmail: "ZZZ", - courseID: "course101", - }, - { - CommonCMDTestCase: cmd.CommonCMDTestCase{ - ExpectedExitCode: 1, - ExpectedStderrSubstring: `Could not find course: 'ZZZ'.`, - }, - targetEmail: "course-student@test.edulinq.org", - courseID: "ZZZ", - }, - } - - for i, testCase := range testCases { - args := []string{ - testCase.targetEmail, - testCase.courseID, - } - - cmd.RunCommonCMDTests(test, main, args, testCase.CommonCMDTestCase, fmt.Sprintf("Case %d: ", i)) - } -} diff --git a/cmd/course-user-get/expected_output_test.go b/cmd/course-user-get/expected_output_test.go deleted file mode 100644 index 2644d0ac..00000000 --- a/cmd/course-user-get/expected_output_test.go +++ /dev/null @@ -1,19 +0,0 @@ -package main - -const USER_COURSE_FOUND = `{ - "found": true, - "user": { - "type": "course", - "email": "course-student@test.edulinq.org", - "name": "course-student", - "role": "student", - "lms-id": "lms-course-student@test.edulinq.org" - } -} -` - -const USER_NOT_FOUND = `{ - "found": false, - "user": null -} -` diff --git a/cmd/course-user-get/main.go b/cmd/course-user-get/main.go deleted file mode 100644 index 8545b53c..00000000 --- a/cmd/course-user-get/main.go +++ /dev/null @@ -1,43 +0,0 @@ -package main - -import ( - "github.com/alecthomas/kong" - - "github.com/edulinq/autograder/internal/api/core" - "github.com/edulinq/autograder/internal/api/courses/users" - "github.com/edulinq/autograder/internal/cmd" - "github.com/edulinq/autograder/internal/config" - "github.com/edulinq/autograder/internal/log" -) - -var args struct { - config.ConfigArgs - cmd.CommonOptions - - TargetEmail string `help:"Email of the course user to get." arg:""` - CourseID string `help:"ID of the course." arg:""` -} - -func main() { - kong.Parse(&args, - kong.Description("Get the information for a course user."), - ) - - err := config.HandleConfigArgs(args.ConfigArgs) - if err != nil { - log.Fatal("Failed to load config options.", err) - } - - request := users.GetRequest{ - APIRequestCourseUserContext: core.APIRequestCourseUserContext{ - CourseID: args.CourseID, - }, - TargetCourseUser: core.TargetCourseUserSelfOrGrader{ - TargetCourseUser: core.TargetCourseUser{ - Email: args.TargetEmail, - }, - }, - } - - cmd.MustHandleCMDRequestAndExitFull(`courses/users/get`, request, users.GetResponse{}, args.CommonOptions, nil) -} diff --git a/cmd/course-user-get/main_test.go b/cmd/course-user-get/main_test.go deleted file mode 100644 index 263aa6e8..00000000 --- a/cmd/course-user-get/main_test.go +++ /dev/null @@ -1,60 +0,0 @@ -package main - -import ( - "fmt" - "testing" - - "github.com/edulinq/autograder/internal/cmd" -) - -// Use the common main for all tests in this package. -func TestMain(suite *testing.M) { - cmd.CMDServerTestingMain(suite) -} - -func TestCourseUserGetBase(test *testing.T) { - testCases := []struct { - cmd.CommonCMDTestCase - targetEmail string - courseID string - }{ - { - CommonCMDTestCase: cmd.CommonCMDTestCase{ - ExpectedStdout: USER_COURSE_FOUND, - }, - targetEmail: "course-student@test.edulinq.org", - courseID: "course101", - }, - { - CommonCMDTestCase: cmd.CommonCMDTestCase{ - ExpectedStdout: USER_NOT_FOUND, - }, - targetEmail: "ZZZ", - courseID: "course101", - }, - { - CommonCMDTestCase: cmd.CommonCMDTestCase{ - ExpectedStdout: USER_NOT_FOUND, - }, - targetEmail: "server-admin@test.edulinq.org", - courseID: "course101", - }, - { - CommonCMDTestCase: cmd.CommonCMDTestCase{ - ExpectedExitCode: 1, - ExpectedStderrSubstring: `Could not find course: 'ZZZ'."`, - }, - targetEmail: "course-student@test.edulinq.org", - courseID: "ZZZ", - }, - } - - for i, testCase := range testCases { - args := []string{ - testCase.targetEmail, - testCase.courseID, - } - - cmd.RunCommonCMDTests(test, main, args, testCase.CommonCMDTestCase, fmt.Sprintf("Case %d: ", i)) - } -} diff --git a/cmd/describe-api/main.go b/cmd/describe-api/main.go deleted file mode 100644 index ad3291fe..00000000 --- a/cmd/describe-api/main.go +++ /dev/null @@ -1,36 +0,0 @@ -package main - -import ( - "fmt" - "os" - - "github.com/alecthomas/kong" - - "github.com/edulinq/autograder/internal/api" - "github.com/edulinq/autograder/internal/config" - "github.com/edulinq/autograder/internal/log" - "github.com/edulinq/autograder/internal/util" -) - -var args struct { - config.ConfigArgs -} - -func main() { - kong.Parse(&args, - kong.Description("Describe all API endpoints."), - ) - - err := config.HandleConfigArgs(args.ConfigArgs) - if err != nil { - log.Fatal("Could not load config options.", err) - } - - os.Exit(run()) -} - -func run() int { - fmt.Print(util.MustToJSONIndent(api.Describe(*api.GetRoutes()))) - - return 0 -} diff --git a/cmd/lms-fetch-user/main.go b/cmd/lms-fetch-user/main.go deleted file mode 100644 index dbb6a845..00000000 --- a/cmd/lms-fetch-user/main.go +++ /dev/null @@ -1,47 +0,0 @@ -package main - -import ( - "fmt" - - "github.com/alecthomas/kong" - - "github.com/edulinq/autograder/internal/config" - "github.com/edulinq/autograder/internal/db" - "github.com/edulinq/autograder/internal/lms" - "github.com/edulinq/autograder/internal/log" -) - -var args struct { - config.ConfigArgs - Course string `help:"ID of the course." arg:""` - Email string `help:"Email of the user to fetch." arg:""` -} - -func main() { - kong.Parse(&args, - kong.Description("Fetch users for a specific LMS course."), - ) - - err := config.HandleConfigArgs(args.ConfigArgs) - if err != nil { - log.Fatal("Could not load config options.", err) - } - - db.MustOpen() - defer db.MustClose() - - course := db.MustGetCourse(args.Course) - - user, err := lms.FetchUser(course, args.Email) - if err != nil { - log.Fatal("Could not fetch user.", err, course) - } - - if user == nil { - fmt.Println("No user found.") - return - } - - fmt.Println("id\temail\tname\trole") - fmt.Printf("%s\t%s\t%s\t%s\n", user.ID, user.Email, user.Name, user.Role.String()) -} diff --git a/cmd/logs-query/main.go b/cmd/logs-query/main.go deleted file mode 100644 index cb1388d0..00000000 --- a/cmd/logs-query/main.go +++ /dev/null @@ -1,61 +0,0 @@ -package main - -import ( - "fmt" - - "github.com/alecthomas/kong" - - "github.com/edulinq/autograder/internal/config" - "github.com/edulinq/autograder/internal/db" - "github.com/edulinq/autograder/internal/log" - "github.com/edulinq/autograder/internal/model" - "github.com/edulinq/autograder/internal/procedures/logs" -) - -var args struct { - config.ConfigArgs - - Level string `help:"Only includes logs from this level or higher." short:"l" default:"info"` - Time string `help:"Only includes logs from this time or later." short:"t"` - - Course string `help:"Only includes logs from this course."` - Assignment string `help:"Only includes logs from this assignment." short:"a"` - User string `help:"Only includes logs from this user." short:"u"` -} - -func main() { - kong.Parse(&args, - kong.Description("Dump all the loaded config and exit."), - ) - - err := config.HandleConfigArgs(args.ConfigArgs) - if err != nil { - log.Fatal("Could not load config options.", err) - } - - db.MustOpen() - defer db.MustClose() - - user := db.MustGetServerUser(model.RootUserEmail) - - query := log.RawLogQuery{ - LevelString: args.Level, - AfterString: args.Time, - CourseID: args.Course, - AssignmentID: args.Assignment, - TargetUser: args.User, - } - - records, locatableErr, err := logs.Query(query, user) - if err != nil { - log.Fatal("Failed to query logs.", err) - } - - if locatableErr != nil { - log.Fatal("Invalid logs query.", locatableErr) - } - - for _, record := range records { - fmt.Println(record.String()) - } -} diff --git a/cmd/peek-submission/expected_output_test.go b/cmd/peek-submission/expected_output_test.go deleted file mode 100644 index 3c63f3df..00000000 --- a/cmd/peek-submission/expected_output_test.go +++ /dev/null @@ -1,61 +0,0 @@ -package main - -const SUBMISSION_1697406272 = `{ - "found-user": true, - "found-submission": true, - "submission-result": { - "id": "course101::hw0::course-student@test.edulinq.org::1697406272", - "short-id": "1697406272", - "course-id": "course101", - "assignment-id": "hw0", - "user": "course-student@test.edulinq.org", - "message": "", - "max_points": 2, - "score": 2, - "name": "HW0", - "questions": [ - { - "name": "Q1", - "max_points": 1, - "score": 1, - "message": "", - "grading_start_time": 1697406273000, - "grading_end_time": 1697406273000 - }, - { - "name": "Q2", - "max_points": 1, - "score": 1, - "message": "", - "grading_start_time": 1697406273000, - "grading_end_time": 1697406273000 - }, - { - "name": "Style", - "max_points": 0, - "score": 0, - "message": "Style is clean!", - "grading_start_time": 1697406273000, - "grading_end_time": 1697406273000 - } - ], - "grading_start_time": 1697406273000, - "grading_end_time": 1697406273000, - "additional-info": null - } -} -` - -const NO_SUBMISSION = `{ - "found-user": true, - "found-submission": false, - "submission-result": null -} -` - -const INCORRECT_SUBMISSION = `{ - "found-user": true, - "found-submission": false, - "submission-result": null -} -` diff --git a/cmd/peek-submission/main.go b/cmd/peek-submission/main.go deleted file mode 100644 index da01b7a2..00000000 --- a/cmd/peek-submission/main.go +++ /dev/null @@ -1,49 +0,0 @@ -package main - -import ( - "github.com/alecthomas/kong" - - "github.com/edulinq/autograder/internal/api/core" - "github.com/edulinq/autograder/internal/api/courses/assignments/submissions" - "github.com/edulinq/autograder/internal/cmd" - "github.com/edulinq/autograder/internal/config" - "github.com/edulinq/autograder/internal/log" -) - -var args struct { - config.ConfigArgs - cmd.CommonOptions - - TargetEmail string `help:"Email of the user to fetch." arg:""` - CourseID string `help:"ID of the course." arg:""` - AssignmentID string `help:"ID of the assignment." arg:""` - TargetSubmission string `help:"ID of the submission. Defaults to the latest submission." arg:"" optional:""` -} - -func main() { - kong.Parse(&args, - kong.Description("Fetch a submission for a specific assignment and user."), - ) - - err := config.HandleConfigArgs(args.ConfigArgs) - if err != nil { - log.Fatal("Failed to load config options.", err) - } - - request := submissions.FetchUserPeekRequest{ - APIRequestAssignmentContext: core.APIRequestAssignmentContext{ - APIRequestCourseUserContext: core.APIRequestCourseUserContext{ - CourseID: args.CourseID, - }, - AssignmentID: args.AssignmentID, - }, - TargetUser: core.TargetCourseUserSelfOrGrader{ - TargetCourseUser: core.TargetCourseUser{ - Email: args.TargetEmail, - }, - }, - TargetSubmission: args.TargetSubmission, - } - - cmd.MustHandleCMDRequestAndExitFull(`courses/assignments/submissions/fetch/user/peek`, request, submissions.FetchUserPeekResponse{}, args.CommonOptions, nil) -} diff --git a/cmd/peek-submission/main_test.go b/cmd/peek-submission/main_test.go deleted file mode 100644 index c94b73f9..00000000 --- a/cmd/peek-submission/main_test.go +++ /dev/null @@ -1,96 +0,0 @@ -package main - -import ( - "fmt" - "testing" - - "github.com/edulinq/autograder/internal/cmd" -) - -// Use the common main for all tests in this package. -func TestMain(suite *testing.M) { - cmd.CMDServerTestingMain(suite) -} - -func TestPeekBase(test *testing.T) { - testCases := []struct { - cmd.CommonCMDTestCase - targetEmail string - courseID string - assignmentID string - targetSubmission string - }{ - { - CommonCMDTestCase: cmd.CommonCMDTestCase{ - ExpectedStdout: SUBMISSION_1697406272, - }, - targetEmail: "course-student@test.edulinq.org", - courseID: "course101", - assignmentID: "hw0", - }, - { - CommonCMDTestCase: cmd.CommonCMDTestCase{ - ExpectedStdout: SUBMISSION_1697406272, - }, - targetEmail: "course-student@test.edulinq.org", - courseID: "course101", - assignmentID: "hw0", - targetSubmission: "1697406272", - }, - { - CommonCMDTestCase: cmd.CommonCMDTestCase{ - ExpectedStdout: SUBMISSION_1697406272, - }, - targetEmail: "course-student@test.edulinq.org", - courseID: "course101", - assignmentID: "hw0", - targetSubmission: "course101::hw0::student@test.com::1697406272", - }, - { - CommonCMDTestCase: cmd.CommonCMDTestCase{ - ExpectedStdout: NO_SUBMISSION, - }, - targetEmail: "course-admin@test.edulinq.org", - courseID: "course101", - assignmentID: "hw0", - }, - { - CommonCMDTestCase: cmd.CommonCMDTestCase{ - ExpectedStdout: INCORRECT_SUBMISSION, - }, - targetEmail: "course-student@test.edulinq.org", - courseID: "course101", - assignmentID: "hw0", - targetSubmission: "ZZZ", - }, - { - CommonCMDTestCase: cmd.CommonCMDTestCase{ - ExpectedExitCode: 1, - ExpectedStderrSubstring: `Could not find course: 'ZZZ'.`, - }, - targetEmail: "course-student@test.edulinq.org", - courseID: "ZZZ", - assignmentID: "hw0", - }, - { - CommonCMDTestCase: cmd.CommonCMDTestCase{ - ExpectedExitCode: 1, - ExpectedStderrSubstring: `Could not find assignment: 'zzz'.`, - }, - targetEmail: "course-student@test.edulinq.org", - courseID: "course101", - assignmentID: "zzz", - }, - } - - for i, testCase := range testCases { - args := []string{ - testCase.targetEmail, - testCase.courseID, - testCase.assignmentID, - testCase.targetSubmission, - } - - cmd.RunCommonCMDTests(test, main, args, testCase.CommonCMDTestCase, fmt.Sprintf("Case %d: ", i)) - } -} diff --git a/cmd/user-get/expected_output_test.go b/cmd/user-get/expected_output_test.go deleted file mode 100644 index 3a9ff168..00000000 --- a/cmd/user-get/expected_output_test.go +++ /dev/null @@ -1,19 +0,0 @@ -package main - -const EXPECTED_SERVER_USER_GET = `{ - "found": true, - "user": { - "type": "server", - "email": "server-user@test.edulinq.org", - "name": "server-user", - "role": "user", - "courses": {} - } -} -` - -const EXPECTED_UNKNOWN_SERVER_USER_GET = `{ - "found": false, - "user": null -} -` diff --git a/cmd/user-get/main.go b/cmd/user-get/main.go deleted file mode 100644 index 1458a4f6..00000000 --- a/cmd/user-get/main.go +++ /dev/null @@ -1,39 +0,0 @@ -package main - -import ( - "github.com/alecthomas/kong" - - "github.com/edulinq/autograder/internal/api/core" - "github.com/edulinq/autograder/internal/api/users" - "github.com/edulinq/autograder/internal/cmd" - "github.com/edulinq/autograder/internal/config" - "github.com/edulinq/autograder/internal/log" -) - -var args struct { - config.ConfigArgs - cmd.CommonOptions - - TargetEmail string `help:"Email of the user to get." arg:""` -} - -func main() { - kong.Parse(&args, - kong.Description("Get the information for a server user."), - ) - - err := config.HandleConfigArgs(args.ConfigArgs) - if err != nil { - log.Fatal("Could not load config options.", err) - } - - request := users.GetRequest{ - TargetUser: core.TargetServerUserSelfOrAdmin{ - TargetServerUser: core.TargetServerUser{ - Email: args.TargetEmail, - }, - }, - } - - cmd.MustHandleCMDRequestAndExitFull(`users/get`, request, users.GetResponse{}, args.CommonOptions, nil) -} diff --git a/cmd/user-get/main_test.go b/cmd/user-get/main_test.go deleted file mode 100644 index 1627037a..00000000 --- a/cmd/user-get/main_test.go +++ /dev/null @@ -1,39 +0,0 @@ -package main - -import ( - "fmt" - "testing" - - "github.com/edulinq/autograder/internal/cmd" -) - -// Use the common main for all tests in this package. -func TestMain(suite *testing.M) { - cmd.CMDServerTestingMain(suite) -} - -func TestServerUserGetBase(test *testing.T) { - testCases := []struct { - CommonCMDTestCase cmd.CommonCMDTestCase - targetEmail string - }{ - { - CommonCMDTestCase: cmd.CommonCMDTestCase{ - ExpectedStdout: EXPECTED_SERVER_USER_GET, - }, - targetEmail: "server-user@test.edulinq.org", - }, - { - CommonCMDTestCase: cmd.CommonCMDTestCase{ - ExpectedStdout: EXPECTED_UNKNOWN_SERVER_USER_GET, - }, - targetEmail: "ZZZ", - }, - } - - for i, testCase := range testCases { - args := []string{testCase.targetEmail} - - cmd.RunCommonCMDTests(test, main, args, testCase.CommonCMDTestCase, fmt.Sprintf("Case %d: ", i)) - } -} diff --git a/cmd/user-remove/expected_output_test.go b/cmd/user-remove/expected_output_test.go deleted file mode 100644 index 8f216892..00000000 --- a/cmd/user-remove/expected_output_test.go +++ /dev/null @@ -1,11 +0,0 @@ -package main - -const USER_FOUND = `{ - "found-user": true -} -` - -const USER_NOT_FOUND = `{ - "found-user": false -} -` diff --git a/cmd/user-remove/main.go b/cmd/user-remove/main.go deleted file mode 100644 index 14df83da..00000000 --- a/cmd/user-remove/main.go +++ /dev/null @@ -1,37 +0,0 @@ -package main - -import ( - "github.com/alecthomas/kong" - - "github.com/edulinq/autograder/internal/api/core" - "github.com/edulinq/autograder/internal/api/users" - "github.com/edulinq/autograder/internal/cmd" - "github.com/edulinq/autograder/internal/config" - "github.com/edulinq/autograder/internal/log" -) - -var args struct { - config.ConfigArgs - cmd.CommonOptions - - TargetEmail string `help:"Email of the user to remove." arg:""` -} - -func main() { - kong.Parse(&args, - kong.Description("Remove a user from the server."), - ) - - err := config.HandleConfigArgs(args.ConfigArgs) - if err != nil { - log.Fatal("Failed to load config options.", err) - } - - request := users.RemoveRequest{ - TargetUser: core.TargetServerUser{ - Email: args.TargetEmail, - }, - } - - cmd.MustHandleCMDRequestAndExitFull(`users/remove`, request, users.RemoveResponse{}, args.CommonOptions, nil) -} diff --git a/cmd/user-remove/main_test.go b/cmd/user-remove/main_test.go deleted file mode 100644 index e3fce883..00000000 --- a/cmd/user-remove/main_test.go +++ /dev/null @@ -1,41 +0,0 @@ -package main - -import ( - "fmt" - "testing" - - "github.com/edulinq/autograder/internal/cmd" -) - -// Use the common main for all tests in this package. -func TestMain(suite *testing.M) { - cmd.CMDServerTestingMain(suite) -} - -func TestServerUserRemoveBase(test *testing.T) { - testCases := []struct { - cmd.CommonCMDTestCase - targetEmail string - }{ - { - CommonCMDTestCase: cmd.CommonCMDTestCase{ - ExpectedStdout: USER_FOUND, - }, - targetEmail: "course-student@test.edulinq.org", - }, - { - CommonCMDTestCase: cmd.CommonCMDTestCase{ - ExpectedStdout: USER_NOT_FOUND, - }, - targetEmail: "ZZZ", - }, - } - - for i, testCase := range testCases { - args := []string{ - testCase.targetEmail, - } - - cmd.RunCommonCMDTests(test, main, args, testCase.CommonCMDTestCase, fmt.Sprintf("Case %d: ", i)) - } -}