From 04d364a46790e360868d75e48676f12023cefcc0 Mon Sep 17 00:00:00 2001 From: yxxhero Date: Wed, 27 Apr 2022 07:29:39 +0800 Subject: [PATCH] add unittest for ValidateConfig Signed-off-by: yxxhero --- pkg/app/app_test.go | 3 +- pkg/app/validate_config_test.go | 52 +++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 pkg/app/validate_config_test.go diff --git a/pkg/app/app_test.go b/pkg/app/app_test.go index 2227506d..0f905633 100644 --- a/pkg/app/app_test.go +++ b/pkg/app/app_test.go @@ -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 { diff --git a/pkg/app/validate_config_test.go b/pkg/app/validate_config_test.go new file mode 100644 index 00000000..2861e2aa --- /dev/null +++ b/pkg/app/validate_config_test.go @@ -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) + } + } +}