Merge pull request #67 from yxxhero/add_unittest_for_ValidateConfig
add unittest for ValidateConfig
This commit is contained in:
		
						commit
						85671c4dc1
					
				|  | @ -2349,6 +2349,7 @@ type applyConfig struct { | ||||||
| 	showSecrets            bool | 	showSecrets            bool | ||||||
| 	suppressDiff           bool | 	suppressDiff           bool | ||||||
| 	noColor                bool | 	noColor                bool | ||||||
|  | 	color                  bool | ||||||
| 	context                int | 	context                int | ||||||
| 	diffOutput             string | 	diffOutput             string | ||||||
| 	concurrency            int | 	concurrency            int | ||||||
|  | @ -2429,7 +2430,7 @@ func (a applyConfig) SuppressDiff() bool { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (a applyConfig) Color() bool { | func (a applyConfig) Color() bool { | ||||||
| 	return false | 	return a.color | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (a applyConfig) NoColor() bool { | 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