diff --git a/cmd/assignment-get/main_test.go b/cmd/assignment-get/main_test.go index 1bdec263..7f9d2242 100644 --- a/cmd/assignment-get/main_test.go +++ b/cmd/assignment-get/main_test.go @@ -29,7 +29,6 @@ func TestAssignmentGetBase(test *testing.T) { CommonCMDTestCase: cmd.CommonCMDTestCase{ ExpectedExitCode: 1, ExpectedStderrSubstring: `Could not find course: 'ZZZ'.`, - ExpectEmptyStdout: true, }, courseID: "ZZZ", assignmentID: "hw0", @@ -38,7 +37,6 @@ func TestAssignmentGetBase(test *testing.T) { CommonCMDTestCase: cmd.CommonCMDTestCase{ ExpectedExitCode: 1, ExpectedStderrSubstring: `Could not find assignment: 'zzz'.`, - ExpectEmptyStdout: true, }, courseID: "course101", assignmentID: "zzz", diff --git a/cmd/assignments-list/main_test.go b/cmd/assignments-list/main_test.go index a040579a..ecd32c53 100644 --- a/cmd/assignments-list/main_test.go +++ b/cmd/assignments-list/main_test.go @@ -27,7 +27,6 @@ func TestAssignmentListBase(test *testing.T) { CommonCMDTestCase: cmd.CommonCMDTestCase{ ExpectedExitCode: 1, ExpectedStderrSubstring: `Could not find course: 'ZZZ'`, - ExpectEmptyStdout: true, }, courseID: "ZZZ", }, diff --git a/cmd/call-api-endpoint/main.go b/cmd/call-api-endpoint/main.go index b4aeb3a2..ca6be487 100644 --- a/cmd/call-api-endpoint/main.go +++ b/cmd/call-api-endpoint/main.go @@ -52,7 +52,7 @@ func main() { // Split the parameter into it's key and value. parts := strings.SplitN(arg, ":", 2) if len(parts) != 2 { - log.Fatal("Invalid parameter format: missing a colon. Expected format is 'key:value', e.g., 'target-email:bob@test.edulinq.org'.", log.NewAttr("parameter", parts)) + log.Fatal("Invalid parameter format: missing a colon. Expected format is 'key:value', e.g., 'id:123'.", log.NewAttr("parameter", parts)) // Return to prevent further execution after log.Fatal(). return diff --git a/cmd/call-api-endpoint/main_test.go b/cmd/call-api-endpoint/main_test.go index 3834e95c..4199322b 100644 --- a/cmd/call-api-endpoint/main_test.go +++ b/cmd/call-api-endpoint/main_test.go @@ -23,21 +23,13 @@ func TestCallApiEndpointBase(test *testing.T) { CommonCMDTestCase: cmd.CommonCMDTestCase{ ExpectedStderrSubstring: `Failed to find the endpoint. | {"endpoint":"ZZZ"}`, ExpectedExitCode: 1, - ExpectEmptyStdout: true, }, endpoint: "ZZZ", - parameters: []string{ - "target-email:course-student@test.edulinq.org", - "course-id:course101", - "assignment-id:hw0", - "target-submission:1697406256", - }, }, { CommonCMDTestCase: cmd.CommonCMDTestCase{ - ExpectedStderrSubstring: `Invalid parameter format: missing a colon. Expected format is 'key:value', e.g., 'target-email:bob@test.edulinq.org'. | {"parameter":["course-idcourse101"]}`, + ExpectedStderrSubstring: `Invalid parameter format: missing a colon. Expected format is 'key:value', e.g., 'id:123'. | {"parameter":["course-idcourse101"]}`, ExpectedExitCode: 1, - ExpectEmptyStdout: true, }, endpoint: "courses/assignments/submissions/fetch/user/peek", parameters: []string{ @@ -50,6 +42,9 @@ func TestCallApiEndpointBase(test *testing.T) { // Base functionality for each supported endpoint. { + CommonCMDTestCase: cmd.CommonCMDTestCase{ + IgnoreStdout: true, + }, endpoint: "courses/assignments/get", parameters: []string{ "course-id:course101", @@ -57,12 +52,18 @@ func TestCallApiEndpointBase(test *testing.T) { }, }, { + CommonCMDTestCase: cmd.CommonCMDTestCase{ + IgnoreStdout: true, + }, endpoint: "courses/assignments/list", parameters: []string{ "course-id:course101", }, }, { + CommonCMDTestCase: cmd.CommonCMDTestCase{ + IgnoreStdout: true, + }, endpoint: "courses/users/drop", parameters: []string{ "target-email:course-student@test.edulinq.org", @@ -70,6 +71,9 @@ func TestCallApiEndpointBase(test *testing.T) { }, }, { + CommonCMDTestCase: cmd.CommonCMDTestCase{ + IgnoreStdout: true, + }, endpoint: "courses/users/get", parameters: []string{ "target-email:course-student@test.edulinq.org", @@ -77,12 +81,62 @@ func TestCallApiEndpointBase(test *testing.T) { }, }, { + CommonCMDTestCase: cmd.CommonCMDTestCase{ + IgnoreStdout: true, + }, endpoint: "courses/users/list", parameters: []string{ "course-id:course101", }, }, { + CommonCMDTestCase: cmd.CommonCMDTestCase{ + IgnoreStdout: true, + }, + endpoint: "courses/assignments/submissions/fetch/course/attempts", + parameters: []string{ + "course-id:course101", + "assignment-id:hw0", + }, + }, + { + CommonCMDTestCase: cmd.CommonCMDTestCase{ + IgnoreStdout: true, + }, + endpoint: "courses/assignments/submissions/fetch/course/scores", + parameters: []string{ + "course-id:course101", + "assignment-id:hw0", + }, + }, + { + CommonCMDTestCase: cmd.CommonCMDTestCase{ + IgnoreStdout: true, + }, + endpoint: "courses/assignments/submissions/fetch/user/attempt", + parameters: []string{ + "target-email:course-student@test.edulinq.org", + "course-id:course101", + "assignment-id:hw0", + "target-submission:1697406256", + }, + }, + { + CommonCMDTestCase: cmd.CommonCMDTestCase{ + IgnoreStdout: true, + }, + endpoint: "courses/assignments/submissions/fetch/user/history", + parameters: []string{ + "target-email:course-student@test.edulinq.org", + "course-id:course101", + "assignment-id:hw0", + "target-submission:1697406256", + }, + }, + { + CommonCMDTestCase: cmd.CommonCMDTestCase{ + IgnoreStdout: true, + }, endpoint: "courses/assignments/submissions/fetch/user/peek", parameters: []string{ "target-email:course-student@test.edulinq.org", @@ -92,15 +146,58 @@ func TestCallApiEndpointBase(test *testing.T) { }, }, { + CommonCMDTestCase: cmd.CommonCMDTestCase{ + IgnoreStdout: true, + }, + endpoint: "courses/assignments/submissions/remove", + parameters: []string{ + "target-email:course-student@test.edulinq.org", + "course-id:course101", + "assignment-id:hw0", + "target-submission:1697406256", + }, + }, + { + CommonCMDTestCase: cmd.CommonCMDTestCase{ + IgnoreStdout: true, + }, + endpoint: "lms/user/get", + parameters: []string{ + "target-email:course-student@test.edulinq.org", + "course-id:course101", + }, + }, + { + CommonCMDTestCase: cmd.CommonCMDTestCase{ + IgnoreStdout: true, + }, + endpoint: "logs/query", + }, + { + CommonCMDTestCase: cmd.CommonCMDTestCase{ + IgnoreStdout: true, + }, + endpoint: "metadata/describe", + }, + { + CommonCMDTestCase: cmd.CommonCMDTestCase{ + IgnoreStdout: true, + }, endpoint: "users/get", parameters: []string{ "target-email:course-student@test.edulinq.org", }, }, { + CommonCMDTestCase: cmd.CommonCMDTestCase{ + IgnoreStdout: true, + }, endpoint: "users/list", }, { + CommonCMDTestCase: cmd.CommonCMDTestCase{ + IgnoreStdout: true, + }, endpoint: "users/remove", parameters: []string{ "target-email:course-student@test.edulinq.org", diff --git a/cmd/course-user-drop/main_test.go b/cmd/course-user-drop/main_test.go index d3fa6c48..d693bf14 100644 --- a/cmd/course-user-drop/main_test.go +++ b/cmd/course-user-drop/main_test.go @@ -36,7 +36,6 @@ func TestCourseUserDropBase(test *testing.T) { CommonCMDTestCase: cmd.CommonCMDTestCase{ ExpectedExitCode: 1, ExpectedStderrSubstring: `Could not find course: 'ZZZ'.`, - ExpectEmptyStdout: true, }, targetEmail: "course-student@test.edulinq.org", courseID: "ZZZ", diff --git a/cmd/course-user-get/main_test.go b/cmd/course-user-get/main_test.go index 62fa2d12..263aa6e8 100644 --- a/cmd/course-user-get/main_test.go +++ b/cmd/course-user-get/main_test.go @@ -43,7 +43,6 @@ func TestCourseUserGetBase(test *testing.T) { CommonCMDTestCase: cmd.CommonCMDTestCase{ ExpectedExitCode: 1, ExpectedStderrSubstring: `Could not find course: 'ZZZ'."`, - ExpectEmptyStdout: true, }, targetEmail: "course-student@test.edulinq.org", courseID: "ZZZ", diff --git a/cmd/course-user-list/main_test.go b/cmd/course-user-list/main_test.go index c58965bc..5052f78b 100644 --- a/cmd/course-user-list/main_test.go +++ b/cmd/course-user-list/main_test.go @@ -35,7 +35,6 @@ func TestCourseUserListBase(test *testing.T) { CommonCMDTestCase: cmd.CommonCMDTestCase{ ExpectedExitCode: 1, ExpectedStderrSubstring: `Could not find course: 'ZZZ'.`, - ExpectEmptyStdout: true, }, courseID: "ZZZ", }, @@ -43,7 +42,6 @@ func TestCourseUserListBase(test *testing.T) { CommonCMDTestCase: cmd.CommonCMDTestCase{ ExpectedExitCode: 1, ExpectedStderrSubstring: `Could not find course: 'ZZZ'.`, - ExpectEmptyStdout: true, }, table: true, courseID: "ZZZ", diff --git a/cmd/peek-submission/main_test.go b/cmd/peek-submission/main_test.go index 6a22222a..c94b73f9 100644 --- a/cmd/peek-submission/main_test.go +++ b/cmd/peek-submission/main_test.go @@ -67,7 +67,6 @@ func TestPeekBase(test *testing.T) { CommonCMDTestCase: cmd.CommonCMDTestCase{ ExpectedExitCode: 1, ExpectedStderrSubstring: `Could not find course: 'ZZZ'.`, - ExpectEmptyStdout: true, }, targetEmail: "course-student@test.edulinq.org", courseID: "ZZZ", @@ -77,7 +76,6 @@ func TestPeekBase(test *testing.T) { CommonCMDTestCase: cmd.CommonCMDTestCase{ ExpectedExitCode: 1, ExpectedStderrSubstring: `Could not find assignment: 'zzz'.`, - ExpectEmptyStdout: true, }, targetEmail: "course-student@test.edulinq.org", courseID: "course101", diff --git a/internal/cmd/test.go b/internal/cmd/test.go index c55459b0..8b1b3173 100644 --- a/internal/cmd/test.go +++ b/internal/cmd/test.go @@ -27,7 +27,7 @@ const ( type CommonCMDTestCase struct { ExpectedExitCode int ExpectedStdout string - ExpectEmptyStdout bool + IgnoreStdout bool ExpectedStderrSubstring string LogLevel log.LogLevel } @@ -180,13 +180,8 @@ func RunCommonCMDTests(test *testing.T, mainFunc func(), args []string, commonTe return "", "", -1, false } - if commonTestCase.ExpectEmptyStdout && len(stdout) > 0 { - test.Errorf("%sUnexpected output. Expected no output, but received '%s'.", prefix, stdout) - return "", "", -1, false - } - - if !commonTestCase.ExpectEmptyStdout && len(stdout) == 0 { - test.Errorf("%sExpected output but received no output.", prefix) + if commonTestCase.ExpectedStdout != stdout && !commonTestCase.IgnoreStdout { + test.Errorf("%sUnexpected output. Expected: \n'%s', \n Actual: \n'%s'.", prefix, commonTestCase.ExpectedStdout, stdout) return "", "", -1, false }