diff options
author | Gabriel A. Giovanini <g.giovanini@gridx.de> | 2023-04-27 11:29:53 +0200 |
---|---|---|
committer | Gabriel A. Giovanini <g.giovanini@gridx.de> | 2023-11-07 11:33:04 +0100 |
commit | 4246ea81d56c93c1df2954e34cc33fb6e6524f49 (patch) | |
tree | f6ce5b4a65648a10897029777f79916f1803ddfd /main_test.go | |
download | workctl-master.tar.gz workctl-master.tar.bz2 workctl-master.zip |
Diffstat (limited to 'main_test.go')
-rw-r--r-- | main_test.go | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..6d0d59f --- /dev/null +++ b/main_test.go @@ -0,0 +1,127 @@ +//go:build unit + +package main + +import ( + "testing" +) + +func TestExtractPR(t *testing.T) { + + testCases := []struct { + name string + mail string + want string + }{ + { + name: "pr created", + want: "https://github.com/grid-x/dploy/pull/9", + mail: `This will allow the change log to directly link the PR making a bit easier to check the summary of those PR. + +Ex.: + + + +You can view, comment on, or merge this pull request online at: + + https://github.com/grid-x/dploy/pull/9 + +-- Commit Summary -- + + * feat(main): allow link pr instead of message + +-- File Changes -- + + M main.go (61) + +-- Patch Links -- + +https://github.com/grid-x/dploy/pull/9.patch +https://github.com/grid-x/dploy/pull/9.diff + +-- +Reply to this email directly or view it on GitHub: +https://github.com/grid-x/dploy/pull/9 +You are receiving this because you are subscribed to this thread. + +Message ID: <grid-x/dploy/pull/9@github.com>`, + }, + { + name: "request review", + want: "https://github.com/grid-x/edge-connector/pull/319", + mail: `@juliusmh requested review from @grid-x/edge-connector-team on: grid-x/edge-connector#319 fix(api/manage): write system controls to response after set as a code owner. + +-- +Reply to this email directly or view it on GitHub: +https://github.com/grid-x/edge-connector/pull/319#event-9104760420 +You are receiving this because your review was requested. + +Message ID: <grid-x/edge-connector/pull/319/issue_event/9104760420@github.com>`, + }, + { + name: "pr merged", + want: "https://github.com/grid-x/edge-connector/pull/319", + mail: `Merged #319 into main. + +-- +Reply to this email directly or view it on GitHub: +https://github.com/grid-x/edge-connector/pull/319#event-9112252051 +You are receiving this because your review was requested. + +Message ID: <grid-x/edge-connector/pull/319/issue_event/9112252051@github.com>`, + }, + { + name: "pr pushed", + want: "https://github.com/grid-x/edge-connector/pull/313", + mail: `@juliusmh pushed 1 commit. + +a0557c770be6d9c2b6070c4fd6a69c68c5e3996f feat(feature/service): accept feature names in kebab-case + +-- +View it on GitHub: +https://github.com/grid-x/edge-connector/pull/313/files/dfdd5081691056150ace71dfb5d11265593c561e..a0557c770be6d9c2b6070c4fd6a69c68c5e3996f +You are receiving this because you are subscribed to this thread. + +Message ID: <grid-x/edge-connector/pull/313/push/13418764381@github.com>`, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + prLink := extractPRLink(tc.mail) + + if prLink != tc.want { + t.Error("Invalid link returned: " + prLink) + } + }) + } +} + +func TestExec(t *testing.T) { + testCases := []struct { + name string + app string + args []string + want string + }{ + { + name: "echo", + app: "echo", + args: []string{"this", "is", "a", "phrase"}, + want: "this is a phrase\n", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + out, err := execCommand(tc.app, tc.args...) + if err != nil { + t.Fatal("Failed " + err.Error()) + } + + if out != tc.want { + t.Error("Invalid stdout returned: " + out) + } + }) + } +} |