Skip to content

Commit

Permalink
Fix student id search
Browse files Browse the repository at this point in the history
Student ID from environment variable now overrides the student ID taken from a file. This makes
checking solutions easier. In addition, student IDs are now converted to upper-case to avoid case
sensitivity issues.
  • Loading branch information
rg0now committed Dec 7, 2023
1 parent b344a77 commit aa5520b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
6 changes: 3 additions & 3 deletions internals/lib/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ const (
// Input is a type alias to the input field of an exercise.
type Input = map[string]any

// GetStudentId returns the student id given in the argument `id`, or in the STUDENT_ID file
// searched upwards from the current directory, or from the environment variable `STUDENT_ID`, or
// an error is no id was found
// GetStudentId returns the student id given in the argument `id`, from the environment variable
// `STUDENT_ID`, or from the STUDENT_ID file searched upwards from the current directory (in that
// order), or an error is no id was found. All student ids are converted to upper case.
func GetStudentId(id *string) (string, error) {
student, err := findStudentId(id)
if err != nil {
Expand Down
18 changes: 8 additions & 10 deletions internals/lib/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ func findFile(dir, name string) (string, error) {
}
}

// findStudentId returns the raw student id given in the argument `id`, or in the STUDENT_ID file
// searched upwards from the current directory, or from the environment variable `STUDENT_ID`, or
// an error is no id was found or the student id is set as the default
func findStudentId(id *string) (string, error) {
if id != nil && *id != "" {
return *id, nil
return strings.ToUpper(*id), nil
}

// env overrides stundent-id file
env := os.Getenv(StudentEnvVar)
if env != "" {
return strings.ToUpper(strings.TrimSpace(env)), nil
}

dir, err := os.Getwd()
Expand All @@ -46,12 +49,7 @@ func findStudentId(id *string) (string, error) {
return "", fmt.Errorf("internal error: could not find student-id file %q returned by findFile",
StudentIdFile)
}
return strings.TrimSpace(string(dat)), nil
}

env := os.Getenv(StudentEnvVar)
if env != "" {
return strings.TrimSpace(env), nil
return strings.ToUpper(strings.TrimSpace(string(dat))), nil
}

return "", fmt.Errorf("no student id file found searhing up from %q", dir)
Expand Down

0 comments on commit aa5520b

Please sign in to comment.