add unittest for ValidateConfig

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero 2022-04-27 07:29:39 +08:00
parent aef233489f
commit 04d364a467
2 changed files with 54 additions and 1 deletions

View File

@ -2349,6 +2349,7 @@ type applyConfig struct {
showSecrets bool
suppressDiff bool
noColor bool
color bool
context int
diffOutput string
concurrency int
@ -2429,7 +2430,7 @@ func (a applyConfig) SuppressDiff() bool {
}
func (a applyConfig) Color() bool {
return false
return a.color
}
func (a applyConfig) NoColor() bool {

View File

@ -0,0 +1,52 @@
package app
import (
"testing"
"github.com/stretchr/testify/require"
)
// Test_ValidateConfig_NoColor_Color tests that ValidateConfig returns an error when both
func TestValidateConfig(t *testing.T) {
tests := []struct {
wantErr bool
noColor bool
color bool
}{
{
wantErr: true,
noColor: true,
color: true,
},
{
wantErr: false,
noColor: false,
color: true,
},
{
wantErr: false,
noColor: true,
color: false,
},
{
wantErr: false,
noColor: false,
color: false,
},
}
for _, tt := range tests {
conf := applyConfig{
noColor: tt.noColor,
color: tt.color,
}
err := ValidateConfig(conf)
if tt.wantErr {
require.Errorf(t, err, "ValidateConfig should return an error when color set to %v and noColor set to %v", tt.color, tt.noColor)
} else {
require.NoErrorf(t, err, "ValidateConfig should not return an error when color set to %v and noColor set to %v", tt.color, tt.noColor)
}
}
}