Skip to content

Commit

Permalink
Merge pull request #827 from Smarticles101/workspace-teams
Browse files Browse the repository at this point in the history
Add teams support to workspace.PotentialExercises
  • Loading branch information
Katrina Owen authored Mar 2, 2019
2 parents b23670e + 61382df commit 1d02944
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
22 changes: 22 additions & 0 deletions workspace/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,28 @@ func (ws Workspace) PotentialExercises() ([]Exercise, error) {
continue
}

if topInfo.Name() == "teams" {
subInfos, err := ioutil.ReadDir(filepath.Join(ws.Dir, "teams"))
if err != nil {
return nil, err
}

for _, subInfo := range subInfos {
teamWs, err := New(filepath.Join(ws.Dir, "teams", subInfo.Name()))
if err != nil {
return nil, err
}

teamExercises, err := teamWs.PotentialExercises()
if err != nil {
return nil, err
}

exercises = append(exercises, teamExercises...)
}
continue
}

subInfos, err := ioutil.ReadDir(filepath.Join(ws.Dir, topInfo.Name()))
if err != nil {
return nil, err
Expand Down
8 changes: 6 additions & 2 deletions workspace/workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ func TestWorkspacePotentialExercises(t *testing.T) {
b1 := filepath.Join(tmpDir, "track-b", "exercise-one")
b2 := filepath.Join(tmpDir, "track-b", "exercise-two")

// It should find teams exercises
team := filepath.Join(tmpDir, "teams", "some-team", "track-c", "exercise-one")

// It should ignore other people's exercises.
alice := filepath.Join(tmpDir, "users", "alice", "track-a", "exercise-one")

// It should ignore nested dirs within exercises.
nested := filepath.Join(a1, "subdir", "deeper-dir", "another-deep-dir")

for _, path := range []string{a1, b1, b2, alice, nested} {
for _, path := range []string{a1, b1, b2, team, alice, nested} {
err := os.MkdirAll(path, os.FileMode(0755))
assert.NoError(t, err)
}
Expand All @@ -36,7 +39,7 @@ func TestWorkspacePotentialExercises(t *testing.T) {

exercises, err := ws.PotentialExercises()
assert.NoError(t, err)
if assert.Equal(t, 3, len(exercises)) {
if assert.Equal(t, 4, len(exercises)) {
paths := make([]string, len(exercises))
for i, e := range exercises {
paths[i] = e.Path()
Expand All @@ -46,6 +49,7 @@ func TestWorkspacePotentialExercises(t *testing.T) {
assert.Equal(t, paths[0], "track-a/exercise-one")
assert.Equal(t, paths[1], "track-b/exercise-one")
assert.Equal(t, paths[2], "track-b/exercise-two")
assert.Equal(t, paths[3], "track-c/exercise-one")
}
}

Expand Down

0 comments on commit 1d02944

Please sign in to comment.