mirror of
https://github.com/qdm12/gluetun.git
synced 2025-12-11 13:56:50 -06:00
56 lines
1009 B
Go
56 lines
1009 B
Go
package command
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
gomock "github.com/golang/mock/gomock"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func Test_run(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
errDummy := errors.New("dummy")
|
|
|
|
testCases := map[string]struct {
|
|
stdout []byte
|
|
cmdErr error
|
|
output string
|
|
err error
|
|
}{
|
|
"no output": {},
|
|
"cmd error": {
|
|
stdout: []byte("'hello \nworld'\n"),
|
|
cmdErr: errDummy,
|
|
output: "hello \nworld",
|
|
err: errDummy,
|
|
},
|
|
}
|
|
|
|
for name, testCase := range testCases {
|
|
testCase := testCase
|
|
t.Run(name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
ctrl := gomock.NewController(t)
|
|
|
|
mockCmd := NewMockexecCmd(ctrl)
|
|
|
|
mockCmd.EXPECT().CombinedOutput().Return(testCase.stdout, testCase.cmdErr)
|
|
|
|
output, err := run(mockCmd)
|
|
|
|
if testCase.err != nil {
|
|
require.Error(t, err)
|
|
assert.Equal(t, testCase.err.Error(), err.Error())
|
|
} else {
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
assert.Equal(t, testCase.output, output)
|
|
})
|
|
}
|
|
}
|