2022-03-31 07:56:22 -04:00
|
|
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
2019-03-27 05:33:00 -04:00
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package git
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2022-03-31 07:56:22 -04:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
2019-03-27 05:33:00 -04:00
|
|
|
|
2022-03-31 07:56:22 -04:00
|
|
|
func TestRunWithContextStd(t *testing.T) {
|
2022-02-06 14:01:47 -05:00
|
|
|
cmd := NewCommand(context.Background(), "--version")
|
2022-03-31 07:56:22 -04:00
|
|
|
stdout, stderr, err := cmd.RunWithContextString(&RunContext{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Empty(t, stderr)
|
|
|
|
assert.Contains(t, stdout, "git version")
|
2019-03-27 05:33:00 -04:00
|
|
|
|
2022-03-31 07:56:22 -04:00
|
|
|
cmd = NewCommand(context.Background(), "--no-such-arg")
|
|
|
|
stdout, stderr, err = cmd.RunWithContextString(&RunContext{})
|
|
|
|
if assert.Error(t, err) {
|
|
|
|
assert.Equal(t, stderr, err.Stderr())
|
|
|
|
assert.Contains(t, err.Stderr(), "unknown option:")
|
|
|
|
assert.Contains(t, err.Error(), "exit status 129 - unknown option:")
|
|
|
|
assert.Empty(t, stdout)
|
2019-03-27 05:33:00 -04:00
|
|
|
}
|
|
|
|
}
|