forked from sequelize/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add command to list available assignments
* lists available exercises for a given language and explains how to fetch them * returns error for unknown languages * Resolves issue sequelize#89 * Fetches the track for a specific language using the /tracks/:language endopoint on the XAPI.
- Loading branch information
Showing
5 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package api | ||
|
||
import ( | ||
"io" | ||
"net/http" | ||
"net/http/httptest" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestListTrack(t *testing.T) { | ||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
// check that we correctly built the URI path | ||
assert.Equal(t, "/tracks/clojure", r.RequestURI) | ||
|
||
f, err := os.Open("../fixtures/tracks.json") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
io.Copy(w, f) | ||
f.Close() | ||
})) | ||
defer ts.Close() | ||
|
||
problems, err := List("clojure", ts.URL) | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, len(problems), 34) | ||
assert.Equal(t, problems[0], "bob") | ||
} | ||
|
||
func TestUnknownLanguage(t *testing.T) { | ||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
http.NotFound(w, r) | ||
})) | ||
defer ts.Close() | ||
|
||
_, err := List("rubbbby", ts.URL) | ||
assert.Equal(t, err, UnknownLanguageError) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/codegangsta/cli" | ||
"github.com/exercism/cli/api" | ||
"github.com/exercism/cli/config" | ||
) | ||
|
||
const msgExplainFetch = "In order to fetch a specific assignment, call the fetch command with a specific assignment.\n\nexercism fetch ruby matrix" | ||
|
||
// List returns the full list of assignments for a given language | ||
func List(ctx *cli.Context) { | ||
c, err := config.New(ctx.GlobalString("config")) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
args := ctx.Args() | ||
|
||
if len(args) != 1 { | ||
msg := "Usage: execism list LANGUAGE" | ||
log.Fatal(msg) | ||
} | ||
|
||
language := args[0] | ||
|
||
problems, err := api.List(language, c.XAPI) | ||
if err != nil { | ||
if err == api.UnknownLanguageError { | ||
log.Fatalf("The requested language '%s' is unknown", language) | ||
} | ||
log.Fatal(err) | ||
} | ||
|
||
for _, p := range problems { | ||
fmt.Printf("%s\n", p) | ||
} | ||
fmt.Printf("\n%s\n\n", msgExplainFetch) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"track":{ | ||
"language":"Clojure", | ||
"active":true, | ||
"id":"clojure", | ||
"slug":"clojure", | ||
"problems":[ | ||
"clojure/bob", | ||
"clojure/rna-transcription", | ||
"clojure/word-count", | ||
"clojure/anagram", | ||
"clojure/beer-song", | ||
"clojure/nucleotide-count", | ||
"clojure/point-mutations", | ||
"clojure/phone-number", | ||
"clojure/grade-school", | ||
"clojure/robot-name", | ||
"clojure/leap", | ||
"clojure/etl", | ||
"clojure/meetup", | ||
"clojure/space-age", | ||
"clojure/grains", | ||
"clojure/gigasecond", | ||
"clojure/triangle", | ||
"clojure/scrabble-score", | ||
"clojure/roman-numerals", | ||
"clojure/binary", | ||
"clojure/prime-factors", | ||
"clojure/raindrops", | ||
"clojure/allergies", | ||
"clojure/atbash-cipher", | ||
"clojure/bank-account", | ||
"clojure/crypto-square", | ||
"clojure/kindergarten-garden", | ||
"clojure/robot-simulator", | ||
"clojure/queen-attack", | ||
"clojure/accumulate", | ||
"clojure/binary-search-tree", | ||
"clojure/difference-of-squares", | ||
"clojure/hexadecimal", | ||
"clojure/largest-series-product" | ||
], | ||
"repository":"https://github.com/exercism/xclojure" | ||
} | ||
} |