mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-24 14:32:33 +00:00
runtime: Optimize func noNeedForOutput and add test cases
Optimize func noNeedForOutput and add test cases for this func. Fixes: #2747 Signed-off-by: bin <bin@hyper.sh>
This commit is contained in:
parent
05995632c3
commit
18bff58487
@ -112,13 +112,5 @@ func getAddress(ctx context.Context, bundlePath, address, id string) (string, er
|
|||||||
}
|
}
|
||||||
|
|
||||||
func noNeedForOutput(detach bool, tty bool) bool {
|
func noNeedForOutput(detach bool, tty bool) bool {
|
||||||
if !detach {
|
return detach && tty
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if !tty {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,9 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
"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)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user