-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #601 from replicatedhq/divolgin/reflect
Use reflection instead of hardcoding all alnalyzers
- Loading branch information
Showing
3 changed files
with
90 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package analyzer | ||
|
||
import ( | ||
"testing" | ||
|
||
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2" | ||
"github.com/replicatedhq/troubleshoot/pkg/multitype" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_GetExcludeFlag(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
analyzer *troubleshootv1beta2.Analyze | ||
want bool | ||
}{ | ||
{ | ||
name: "nil case", | ||
analyzer: nil, | ||
want: false, | ||
}, | ||
{ | ||
name: "true is set", | ||
analyzer: &troubleshootv1beta2.Analyze{ | ||
TextAnalyze: &troubleshootv1beta2.TextAnalyze{ | ||
AnalyzeMeta: troubleshootv1beta2.AnalyzeMeta{ | ||
Exclude: multitype.FromBool(true), | ||
}, | ||
}, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "false is set", | ||
analyzer: &troubleshootv1beta2.Analyze{ | ||
ClusterVersion: &troubleshootv1beta2.ClusterVersion{ | ||
AnalyzeMeta: troubleshootv1beta2.AnalyzeMeta{ | ||
Exclude: multitype.FromBool(false), | ||
}, | ||
}, | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "nothing is set", | ||
analyzer: &troubleshootv1beta2.Analyze{ | ||
Postgres: &troubleshootv1beta2.DatabaseAnalyze{ | ||
AnalyzeMeta: troubleshootv1beta2.AnalyzeMeta{}, | ||
}, | ||
}, | ||
want: false, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
req := require.New(t) | ||
|
||
gotWrapped := GetExcludeFlag(test.analyzer) | ||
got, err := gotWrapped.Bool() | ||
req.NoError(err) | ||
|
||
assert.Equal(t, test.want, got) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters