Merge pull request #2748 from liubin/fix/2747-add-test

runtime: Optimize func noNeedForOutput and add test cases
This commit is contained in:
Chelsea Mafrica 2021-10-06 11:24:57 -07:00 committed by GitHub
commit 6e3fcce2a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 9 deletions

View File

@ -112,13 +112,5 @@ func getAddress(ctx context.Context, bundlePath, address, id string) (string, er
}
func noNeedForOutput(detach bool, tty bool) bool {
if !detach {
return false
}
if !tty {
return false
}
return true
return detach && tty
}

View File

@ -16,6 +16,9 @@ import (
"path"
"path/filepath"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/opencontainers/runtime-spec/specs-go"
@ -326,3 +329,39 @@ func writeOCIConfigFile(spec specs.Spec, configPath string) error {
return ioutil.WriteFile(configPath, bytes, testFileMode)
}
func TestNoNeedForOutput(t *testing.T) {
assert := assert.New(t)
testCases := []struct {
detach bool
tty bool
result bool
}{
{
detach: true,
tty: true,
result: true,
},
{
detach: false,
tty: true,
result: false,
},
{
detach: true,
tty: false,
result: false,
},
{
detach: false,
tty: false,
result: false,
},
}
for i := range testCases {
result := noNeedForOutput(testCases[i].detach, testCases[i].tty)
assert.Equal(testCases[i].result, result)
}
}