Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion internal/cmd/calendar/calendar.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,13 @@ func newCmdSet() *cobra.Command {
Short: "Replace calendar section subscriptions",
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if strings.TrimSpace(semesterID) == "" {
return fmt.Errorf("--semester-id is required for calendar set")
}
return runCalendarBatch(cmd, args, openapi.CalendarSubscriptionBatchRequestSchemaActionSet, semesterID)
},
}
cmd.Flags().StringVar(&semesterID, "semester-id", "", "Semester ID to narrow code matches")
cmd.Flags().StringVar(&semesterID, "semester-id", "", "Semester ID whose subscriptions will be replaced")
return cmd
}

Expand Down
29 changes: 29 additions & 0 deletions internal/cmd/calendar/calendar_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package calendar

import (
"strings"
"testing"
)

func TestSetRequiresSemesterID(t *testing.T) {
for _, args := range [][]string{
{"999999"},
{"999999", "--semester-id", " "},
} {
t.Run(strings.Join(args, " "), func(t *testing.T) {
t.Setenv("LIFE_USTC_CONFIG_DIR", t.TempDir())
t.Setenv("LIFE_USTC_SERVER", "http://127.0.0.1:1")

cmd := newCmdSet()
cmd.SetArgs(args)

err := cmd.Execute()
if err == nil {
t.Fatal("expected calendar set without --semester-id to fail")
}
if !strings.Contains(err.Error(), "--semester-id is required") {
t.Fatalf("unexpected error: %v", err)
}
})
}
}
Loading