示例#1
0
文件: main.go 项目: jveski/chester
func main() {
	app := api.New()

	// Define configuration flags
	modulepath := flag.String("modulepath", "", "Directory containing module release tarballs to serve. Required.")
	binding := flag.String("binding", ":8080", "Golang ListenAndServe binding")
	fileurl := flag.String("fileurl", "/v3/files", "URL to the base of the URL which the module tarballs are being served from")
	flag.Parse()

	// Configure the API
	app.Config["modulepath"] = *modulepath
	app.Config["binding"] = *binding
	app.Config["fileurl"] = *fileurl

	// Start the API server
	app.Listen()
}
示例#2
0
func TestNoParams(t *testing.T) {
	app := api.New()

	app.Config["modulepath"] = "test_fixtures"
	app.Config["fileurl"] = "/stub/filepaath"

	req, _ := http.NewRequest("GET", "/v3/releases", nil)
	theServer := httptest.NewRecorder()
	app.GetReleases(theServer, req)

	if theServer.Body.String() != "{\"errors\":[\"Invalid query\"]}" {
		t.Fatal("API.GetReleases returned ", theServer.Body, " wanted {\"errors\":[\"Invalid query\"]} when given no params")
	}

	if theServer.Code != 500 {
		t.Fatal("API.GetReleases returned status ", string(theServer.Code), " wanted HTTP 500")
	}
}
示例#3
0
func TestValidModule(t *testing.T) {
	app := api.New()

	app.Config["modulepath"] = "test_fixtures"
	app.Config["fileurl"] = "/stub/filepaath"

	req, _ := http.NewRequest("GET", "/v3/releases?module=stub-module", nil)
	theServer := httptest.NewRecorder()
	app.GetReleases(theServer, req)

	if theServer.Body.String() != "{\"pagination\":{},\"results\":[{\"metadata\":{\"name\":\"stubuser-stubmodule\",\"version\":\"1.2.3\",\"dependencies\":[{\"name\":\"stub/dep1\",\"version_requirement\":\"stub_version1\"},{\"name\":\"stub/dep2\",\"version_requirement\":\"stub_version2\"}]},\"file_uri\":\"/stub/filepaath/stubuser-stubmodule-1.2.3.tar.gz\",\"file_md5\":\"37a31eea4a43669c82cd216209cb395e\"}]}" {
		t.Fatal("API.GetReleases returned ", theServer.Body, " wanted an empty array")
	}

	if theServer.Code != 200 {
		t.Fatal("API.GetReleases returned status", theServer.Code, " wanted HTTP 200")
	}
}
示例#4
0
func TestNonExistentModule(t *testing.T) {
	app := api.New()

	app.Config["modulepath"] = "test_fixtures"
	app.Config["fileurl"] = "/stub/filepaath"

	req, _ := http.NewRequest("GET", "/v3/releases?module=testuser-testmod", nil)
	theServer := httptest.NewRecorder()
	app.GetReleases(theServer, req)

	if theServer.Body.String() != "{\"pagination\":{},\"results\":[]}" {
		t.Fatal("API.GetReleases returned ", theServer.Body, " wanted an empty array")
	}

	if theServer.Code != 200 {
		t.Fatal("API.GetReleases returned status", theServer.Code, " wanted HTTP 200")
	}
}