//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.: ![image](https://user-images.githubusercontent.com/4411113/234298782-30d154bd-540c-483f-87d1-0d28fb76f0c2.png) 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: `, }, { 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: `, }, { 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: `, }, } 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) } }) } }