-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1459967: Add a go implementation
- Loading branch information
Showing
7 changed files
with
290 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"Enable": [ | ||
"deadcode", | ||
"errcheck", | ||
"gas", | ||
"goconst", | ||
"goimports", | ||
"golint", | ||
"gosimple", | ||
"gotype", | ||
"gotypex", | ||
"ineffassign", | ||
"interfacer", | ||
"maligned", | ||
"megacheck", | ||
"misspell", | ||
"nakedret", | ||
"safesql", | ||
"staticcheck", | ||
"structcheck", | ||
"unconvert", | ||
"unparam", | ||
"unused", | ||
"varcheck" | ||
] | ||
} |
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
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,72 @@ | ||
package tcurls | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
const oldRootURL = "https://taskcluster.net" | ||
|
||
// API generates a url for a resource in a taskcluster service | ||
func API(rootURL string, service string, version string, path string) string { | ||
path = strings.TrimLeft(path, "/") | ||
switch r := strings.TrimRight(rootURL, "/"); r { | ||
case oldRootURL: | ||
return fmt.Sprintf("https://%s.taskcluster.net/%s/%s", service, version, path) | ||
default: | ||
return fmt.Sprintf("%s/api/%s/%s/%s", r, service, version, path) | ||
} | ||
} | ||
|
||
// APIReference enerates a url for a taskcluster service reference doc | ||
func APIReference(rootURL string, service string, version string) string { | ||
switch r := strings.TrimRight(rootURL, "/"); r { | ||
case oldRootURL: | ||
return fmt.Sprintf("https://references.taskcluster.net/%s/%s/api.json", service, version) | ||
default: | ||
return fmt.Sprintf("%s/references/%s/%s/api.json", r, service, version) | ||
} | ||
} | ||
|
||
// Docs generates a url for a taskcluster docs-site page | ||
func Docs(rootURL string, path string) string { | ||
path = strings.TrimLeft(path, "/") | ||
switch r := strings.TrimRight(rootURL, "/"); r { | ||
case oldRootURL: | ||
return fmt.Sprintf("https://docs.taskcluster.net/%s", path) | ||
default: | ||
return fmt.Sprintf("%s/docs/%s", r, path) | ||
} | ||
} | ||
|
||
// ExchangeReference generates a url for a taskcluster exchange reference doc | ||
func ExchangeReference(rootURL string, service string, version string) string { | ||
switch r := strings.TrimRight(rootURL, "/"); r { | ||
case oldRootURL: | ||
return fmt.Sprintf("https://references.taskcluster.net/%s/%s/exchanges.json", service, version) | ||
default: | ||
return fmt.Sprintf("%s/references/%s/%s/exchanges.json", r, service, version) | ||
} | ||
} | ||
|
||
// Schema generates a url for a taskcluster schema | ||
func Schema(rootURL string, service string, name string) string { | ||
name = strings.TrimLeft(name, "/") | ||
switch r := strings.TrimRight(rootURL, "/"); r { | ||
case oldRootURL: | ||
return fmt.Sprintf("https://schemas.taskcluster.net/%s/%s", service, name) | ||
default: | ||
return fmt.Sprintf("%s/schemas/%s/%s", r, service, name) | ||
} | ||
} | ||
|
||
// UI generates a url for a page in taskcluster tools site | ||
func UI(rootURL string, path string) string { | ||
path = strings.TrimLeft(path, "/") | ||
switch r := strings.TrimRight(rootURL, "/"); r { | ||
case oldRootURL: | ||
return fmt.Sprintf("https://tools.taskcluster.net/%s", path) | ||
default: | ||
return fmt.Sprintf("%s/%s", r, path) | ||
} | ||
} |
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,92 @@ | ||
package tcurls | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"testing" | ||
|
||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
const rootURL = "https://taskcluster.example.com" | ||
|
||
type spec struct { | ||
FunctionType string `yaml:"type"` | ||
ExpectedURL string `yaml:"expectedUrl"` | ||
OldExpectedURL string `yaml:"oldExpectedUrl"` | ||
ArgSets [][]string `yaml:"argSets"` | ||
} | ||
|
||
type document struct { | ||
Specs []spec `yaml:"specs"` | ||
} | ||
|
||
func testFunc(t *testing.T, functionType string, root string, args ...string) (string, error) { | ||
switch functionType { | ||
case "api": | ||
return API(root, args[0], args[1], args[2]), nil | ||
case "apiReference": | ||
return APIReference(root, args[0], args[1]), nil | ||
case "docs": | ||
return Docs(root, args[0]), nil | ||
case "exchangeReference": | ||
return ExchangeReference(root, args[0], args[1]), nil | ||
case "schema": | ||
return Schema(root, args[0], args[1]), nil | ||
case "ui": | ||
return UI(root, args[0]), nil | ||
default: | ||
return "", fmt.Errorf("Unknown function type: %s", functionType) | ||
} | ||
} | ||
|
||
func TestUrls(t *testing.T) { | ||
data, err := ioutil.ReadFile("specification.yml") | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
var specs document | ||
err = yaml.Unmarshal([]byte(data), &specs) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
for _, test := range specs.Specs { | ||
// First test "new" urls | ||
for _, argSet := range test.ArgSets { | ||
result, err := testFunc(t, test.FunctionType, rootURL, argSet...) | ||
if err != nil { | ||
t.Error(err) | ||
continue | ||
} | ||
if result != test.ExpectedURL { | ||
t.Errorf("Url is not correct. Got %s wanted %s", result, test.ExpectedURL) | ||
continue | ||
} | ||
result, err = testFunc(t, test.FunctionType, fmt.Sprintf("%s/", rootURL), argSet...) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
if result != test.ExpectedURL { | ||
t.Errorf("Url is not correct. Got %s wanted %s", result, test.ExpectedURL) | ||
continue | ||
} | ||
|
||
// Now the old ones | ||
result, err = testFunc(t, test.FunctionType, oldRootURL, argSet...) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
if result != test.OldExpectedURL { | ||
t.Errorf("Url is not correct. Got %s wanted %s", result, test.OldExpectedURL) | ||
} | ||
result, err = testFunc(t, test.FunctionType, fmt.Sprintf("%s/", oldRootURL), argSet...) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
if result != test.OldExpectedURL { | ||
t.Errorf("Url is not correct. Got %s wanted %s", result, test.OldExpectedURL) | ||
} | ||
} | ||
} | ||
} |
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