add unittest for ValidateConfig
Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
		
							parent
							
								
									aef233489f
								
							
						
					
					
						commit
						04d364a467
					
				|  | @ -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 { | ||||
|  |  | |||
|  | @ -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) | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
		Loading…
	
		Reference in New Issue