-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: rework passive tests into native go tests
this commit re-works the basic.t tests and administers them using go's native testing suite. Signed-off-by: ldelossa <[email protected]>
- Loading branch information
Showing
11 changed files
with
1,271 additions
and
21 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,22 @@ | ||
--- | ||
name: CI | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
tests: | ||
name: Tests | ||
runs-on: ubuntu-latest | ||
container: docker.io/library/golang:${{ matrix.go }} | ||
strategy: | ||
matrix: | ||
go: ['1.13', '1.14'] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: add gox | ||
run: go install github.com/mitchellh/gox | ||
- name: make binaries | ||
run: make all | ||
- name: perform tests | ||
run: go test -v ./... |
This file was deleted.
Oops, something went wrong.
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,49 @@ | ||
config: | ||
stop: true | ||
endpoint: https://go-jira.atlassian.net | ||
password-source: stdin | ||
user: gojira | ||
login: [email protected] | ||
|
||
project: BASIC | ||
|
||
queries: | ||
todo: >- | ||
resolution = unresolved {{if .project}}AND project = '{{.project}}'{{end}} AND status = 'To Do' | ||
custom-commands: | ||
- name: env | ||
help: print the JIRA environment variables available to custom commands | ||
script: |- | ||
env | sort | grep JIRA | ||
- name: print-project | ||
help: print the name of the configured project | ||
script: "echo $JIRA_PROJECT" | ||
- name: jira-path | ||
help: print the path the jira command that is running this alias | ||
script: |- | ||
echo {{jira}} | ||
- name: mine | ||
help: display issues assigned to me | ||
script: |- | ||
if [ -n "$JIRA_PROJECT" ]; then | ||
# if `project: ...` configured just list the issues for current project | ||
{{jira}} list --template table --query "resolution = unresolved and assignee=currentuser() and project = $JIRA_PROJECT ORDER BY priority asc, created" | ||
else | ||
# otherwise list issues for all project | ||
{{jira}} list --template table --query "resolution = unresolved and assignee=currentuser() ORDER BY priority asc, created" | ||
fi | ||
- name: argtest | ||
help: testing passing args | ||
script: |- | ||
echo {{args.ARG}} | ||
args: | ||
- name: ARG | ||
help: string to echo for testing | ||
- name: opttest | ||
help: testing passing option flags | ||
script: |- | ||
echo {{options.OPT}} | ||
options: | ||
- name: OPT | ||
help: string to echo for testing |
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 @@ | ||
template: list |
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,56 @@ | ||
package test | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io" | ||
"os" | ||
"os/exec" | ||
) | ||
|
||
// withApiLogin is a hack to provide an api token on every command, this means keyring | ||
// and gpg is not necessary to run the testing suite. | ||
// | ||
// a buffer containing stdout will be returned to the caller if no error is encountered. | ||
// this still expects a config file is in a parent where the test runs for project | ||
// and endpoint details. | ||
func withApiLogin(login string, token string, cmd *exec.Cmd) (bytes.Buffer, error) { | ||
var buf bytes.Buffer | ||
|
||
cmd.Args = append(cmd.Args, "--login", login) | ||
|
||
diag := fmt.Sprintf("--- running command: %+v ---\n", cmd.Args) | ||
io.WriteString(os.Stdout, diag) | ||
|
||
// write to stdout and also to our buffer | ||
out := io.MultiWriter(&buf, os.Stdout) | ||
cmd.Stdout = out | ||
|
||
e := io.MultiWriter(&buf, os.Stderr) | ||
cmd.Stderr = e | ||
|
||
in, err := cmd.StdinPipe() | ||
if err != nil { | ||
return buf, err | ||
} | ||
|
||
err = cmd.Start() | ||
if err != nil { | ||
return buf, err | ||
} | ||
|
||
_, err = io.WriteString(in, token) | ||
if err != nil { | ||
return buf, err | ||
} | ||
in.Close() | ||
|
||
err = cmd.Wait() | ||
if err != nil { | ||
return buf, err | ||
} | ||
|
||
diag = fmt.Sprintf("--- finished command: %+v ---\n\n", cmd.Args) | ||
io.WriteString(os.Stdout, diag) | ||
return buf, nil | ||
} |
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,98 @@ | ||
package test | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func checkDiff(t *testing.T, buf bytes.Buffer, expect string, formats ...interface{}) { | ||
expect = fmt.Sprintf(expect, formats...) | ||
if !cmp.Equal(expect, buf.String()) { | ||
t.Fatal( | ||
cmp.Diff( | ||
buf.String(), | ||
expect, | ||
), | ||
) | ||
} | ||
} | ||
|
||
func checkCreateIssue(t *testing.T, buf bytes.Buffer, endpoint string) string { | ||
out := strings.Split(buf.String(), " ") | ||
if len(out) < 3 { | ||
t.Fatalf("unexpected split count on create output: %v", buf.String()) | ||
} | ||
issue := out[1] | ||
expect := fmt.Sprintf("OK %s %s/browse/%s\n", issue, endpoint, issue) | ||
if !cmp.Equal(expect, buf.String()) { | ||
t.Fatal( | ||
cmp.Diff( | ||
buf.String(), | ||
expect, | ||
), | ||
) | ||
} | ||
return issue | ||
} | ||
|
||
func checkEditIssue(t *testing.T, buf bytes.Buffer, issue, endpoint string) { | ||
out := strings.Split(buf.String(), " ") | ||
if len(out) < 3 { | ||
t.Fatalf("unexpected split count on create output: %v", buf.String()) | ||
} | ||
editedIssue := out[1] | ||
expect := fmt.Sprintf("OK %s %s/browse/%s\n", issue, endpoint, issue) | ||
if !cmp.Equal(expect, buf.String()) { | ||
t.Fatal( | ||
cmp.Diff( | ||
buf.String(), | ||
expect, | ||
), | ||
) | ||
} | ||
if !cmp.Equal(editedIssue, issue) { | ||
t.Fatal( | ||
cmp.Diff( | ||
editedIssue, | ||
issue, | ||
), | ||
) | ||
} | ||
} | ||
|
||
func checkIssueInOutput(t *testing.T, buf bytes.Buffer, issue string) { | ||
if !strings.Contains(buf.String(), issue) { | ||
t.Fatalf("issue %s not located in stdout: %s", issue, buf.String()) | ||
} | ||
} | ||
|
||
func checkIssueNotInOutput(t *testing.T, buf bytes.Buffer, issue string) { | ||
if strings.Contains(buf.String(), issue) { | ||
t.Fatalf("issue %s not located in stdout: %s", issue, buf.String()) | ||
} | ||
} | ||
|
||
func checkBlockIssue(t *testing.T, buf bytes.Buffer, issue, blocker, endpoint string) { | ||
checkDualIssues(t, buf, blocker, issue, endpoint) | ||
} | ||
|
||
func checkDupIssue(t *testing.T, buf bytes.Buffer, issue, duplicate, endpoint string) { | ||
checkDualIssues(t, buf, issue, duplicate, endpoint) | ||
} | ||
|
||
func checkDualIssues(t *testing.T, buf bytes.Buffer, first, second, endpoint string) { | ||
lines := strings.Split(buf.String(), "\n") | ||
if len(lines) < 2 { | ||
t.Fatalf("unexpected split count on create output: %v", buf.String()) | ||
} | ||
|
||
testBuf := bytes.NewBuffer([]byte(lines[0] + "\n")) | ||
checkEditIssue(t, *testBuf, first, endpoint) | ||
|
||
testBuf = bytes.NewBuffer([]byte(lines[1] + "\n")) | ||
checkEditIssue(t, *testBuf, second, endpoint) | ||
} |
Oops, something went wrong.