Skip to content

Commit

Permalink
Add test for cmd/conflictless
Browse files Browse the repository at this point in the history
  • Loading branch information
ypjama committed Oct 18, 2023
1 parent 773943c commit 4f4a5f5
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions cmd/conflictless/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"errors"
"os"
"os/exec"
"testing"

"github.com/stretchr/testify/assert"
)

func Test_main(t *testing.T) {
t.Parallel()

if os.Getenv("TEST_MAIN_CLI") == "1" {
main()

return
}

//nolint:gosec // this is a test package so G204 doesn't really matter here.
cmd := exec.Command(os.Args[0], "-test.run=^Test_main$")

cmd.Env = append(os.Environ(), "TEST_MAIN_CLI=1")
err := cmd.Run()

assert.IsType(t, new(exec.ExitError), err)

exitErr := new(*exec.ExitError)
errors.As(err, exitErr)

assert.Equal(t, 2, (*exitErr).ExitCode(), "process ran with err %v, want exit status 2", err)
}

0 comments on commit 4f4a5f5

Please sign in to comment.