Skip to content

Commit

Permalink
Add installation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ghokun committed Jul 14, 2024
1 parent f269a22 commit f0cfad3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ permissions:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
os: [macos-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: Homebrew/actions/setup-homebrew@master
- uses: actions/checkout@v4
with:
fetch-depth: 0
Expand Down
27 changes: 25 additions & 2 deletions coyote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,26 @@ func InitializeTestSuite(ctx *godog.TestSuiteContext) {
}

func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Given(`^coyote is present$`, coyoteIsPresent)
ctx.Given(`^coyote is present locally$`, coyoteIsPresentLocally)
ctx.Given(`^brew is present$`, brewIsPresent)

ctx.When(`^coyote is run with help option$`, coyoteIsRunWithHelpOption)
ctx.When(`^"(.+)" is installed using brew$`, formulaIsInstalledUsingBrew)

ctx.Then(`^help message is printed$`, helpMessageIsPrinted)
ctx.Then(`^coyote is installed$`, coyoteIsInstalled)
}

func coyoteIsPresent() error {
func coyoteIsPresentLocally() error {
_, err := os.Stat("coyote")
return err
}

func brewIsPresent() error {
_, err := exec.LookPath("brew")
return err
}

func coyoteIsRunWithHelpOption(ctx context.Context) (context.Context, error) {
out, err := exec.Command("./coyote", "-h").Output()
if err != nil {
Expand All @@ -63,6 +73,14 @@ func coyoteIsRunWithHelpOption(ctx context.Context) (context.Context, error) {
return context.WithValue(ctx, ctxKey{}, string(out)), nil
}

func formulaIsInstalledUsingBrew(formula string) error {
cmd := exec.Command("brew", "install", formula)
if err := cmd.Run(); err != nil {
return err
}
return nil
}

func helpMessageIsPrinted(ctx context.Context) error {
actualOutput := ctx.Value(ctxKey{}).(string)

Expand All @@ -72,6 +90,11 @@ func helpMessageIsPrinted(ctx context.Context) error {
return fmt.Errorf("Result not as expected:\n%v", diff.LineDiff(expectedOutput, actualOutput))
}

func coyoteIsInstalled() error {
_, err := exec.LookPath("coyote")
return err
}

const expectedOutput = `NAME:
coyote - Coyote is a RabbitMQ message sink.
Expand Down
6 changes: 0 additions & 6 deletions features/coyote.feature

This file was deleted.

6 changes: 6 additions & 0 deletions features/help.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: Run coyote

Scenario: Coyote displays help message
Given coyote is present locally
When coyote is run with help option
Then help message is printed
6 changes: 6 additions & 0 deletions features/install.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: Install coyote

Scenario: Homebrew installs coyote
Given brew is present
When "ghokun/tap/coyote" is installed using brew
Then coyote is installed

0 comments on commit f0cfad3

Please sign in to comment.