Skip to content

Commit afa717d

Browse files
author
jmccormick2001
committed
clean up code, add quotes around labels
1 parent f044446 commit afa717d

File tree

5 files changed

+34
-19
lines changed

5 files changed

+34
-19
lines changed

internal/scorecard/plugins/basic_tests.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
v1 "k8s.io/api/core/v1"
2626
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
27+
"k8s.io/apimachinery/pkg/labels"
2728
"k8s.io/apimachinery/pkg/types"
2829
"sigs.k8s.io/controller-runtime/pkg/client"
2930
)
@@ -33,6 +34,8 @@ type BasicTestConfig struct {
3334
Client client.Client
3435
CR *unstructured.Unstructured
3536
ProxyPod *v1.Pod
37+
Version string
38+
Selector labels.Selector
3639
}
3740

3841
// Test Defintions
@@ -105,6 +108,10 @@ func NewBasicTestSuite(conf BasicTestConfig) *schelpers.TestSuite {
105108
ts.AddTest(NewCheckStatusTest(conf), 1)
106109
ts.AddTest(NewWritingIntoCRsHasEffectTest(conf), 1)
107110

111+
if schelpers.IsV1alpha2(conf.Version) {
112+
ts.ApplySelector(conf.Selector)
113+
}
114+
108115
return ts
109116
}
110117

internal/scorecard/plugins/olm_tests.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
v1 "k8s.io/api/core/v1"
2929
apiextv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
3030
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
31+
"k8s.io/apimachinery/pkg/labels"
3132
"k8s.io/apimachinery/pkg/runtime/schema"
3233
"k8s.io/apimachinery/pkg/types"
3334
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -40,6 +41,8 @@ type OLMTestConfig struct {
4041
CSV *olmapiv1alpha1.ClusterServiceVersion
4142
CRDsDir string
4243
ProxyPod *v1.Pod
44+
Selector labels.Selector
45+
Version string
4346
}
4447

4548
// Test Defintions
@@ -166,6 +169,10 @@ func NewOLMTestSuite(conf OLMTestConfig) *schelpers.TestSuite {
166169
ts.AddTest(NewSpecDescriptorsTest(conf), 1)
167170
ts.AddTest(NewStatusDescriptorsTest(conf), 1)
168171

172+
if schelpers.IsV1alpha2(conf.Version) {
173+
ts.ApplySelector(conf.Selector)
174+
}
175+
169176
return ts
170177
}
171178

internal/scorecard/plugins/plugin_runner.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,11 @@ func RunInternalPlugin(pluginType PluginType, config BasicAndOLMPluginConfig, lo
292292
Client: runtimeClient,
293293
CR: obj,
294294
ProxyPod: proxyPodGlobal,
295+
Version: config.Version,
296+
Selector: config.Selector,
295297
}
296298
basicTests := NewBasicTestSuite(conf)
297-
if schelpers.IsV1alpha2(config.Version) {
298-
basicTests.ApplySelector(config.Selector)
299-
}
299+
300300
basicTests.Run(context.TODO())
301301
logs, err := ioutil.ReadAll(logReadWriter)
302302
if err != nil {
@@ -313,11 +313,11 @@ func RunInternalPlugin(pluginType PluginType, config BasicAndOLMPluginConfig, lo
313313
CSV: csv,
314314
CRDsDir: config.CRDsDir,
315315
ProxyPod: proxyPodGlobal,
316+
Version: config.Version,
317+
Selector: config.Selector,
316318
}
317319
olmTests := NewOLMTestSuite(conf)
318-
if schelpers.IsV1alpha2(config.Version) {
319-
olmTests.ApplySelector(config.Selector)
320-
}
320+
321321
olmTests.Run(context.TODO())
322322
logs, err := ioutil.ReadAll(logReadWriter)
323323
if err != nil {
@@ -352,12 +352,13 @@ func RunInternalPlugin(pluginType PluginType, config BasicAndOLMPluginConfig, lo
352352
func ListInternalPlugin(pluginType PluginType, config BasicAndOLMPluginConfig) (scapiv1alpha1.ScorecardOutput, error) {
353353
var suites []schelpers.TestSuite
354354

355-
if pluginType == BasicOperator {
356-
conf := BasicTestConfig{}
357-
basicTests := NewBasicTestSuite(conf)
358-
if schelpers.IsV1alpha2(config.Version) {
359-
basicTests.ApplySelector(config.Selector)
355+
switch pluginType {
356+
case BasicOperator:
357+
conf := BasicTestConfig{
358+
Version: config.Version,
359+
Selector: config.Selector,
360360
}
361+
basicTests := NewBasicTestSuite(conf)
361362

362363
basicTests.TestResults = make([]schelpers.TestResult, 0)
363364
for i := 0; i < len(basicTests.Tests); i++ {
@@ -368,13 +369,13 @@ func ListInternalPlugin(pluginType PluginType, config BasicAndOLMPluginConfig) (
368369
basicTests.TestResults = append(basicTests.TestResults, result)
369370
}
370371
suites = append(suites, *basicTests)
371-
}
372-
if pluginType == OLMIntegration {
373-
conf := OLMTestConfig{}
374-
olmTests := NewOLMTestSuite(conf)
375-
if schelpers.IsV1alpha2(config.Version) {
376-
olmTests.ApplySelector(config.Selector)
372+
case OLMIntegration:
373+
conf := OLMTestConfig{
374+
Version: config.Version,
375+
Selector: config.Selector,
377376
}
377+
olmTests := NewOLMTestSuite(conf)
378+
378379
olmTests.TestResults = make([]schelpers.TestResult, 0)
379380
for i := 0; i < len(olmTests.Tests); i++ {
380381
result := schelpers.TestResult{}

pkg/apis/scorecard/v1alpha2/formatter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (s ScorecardOutput) MarshalText() (string, error) {
5858

5959
sb.WriteString("\tLabels: \n")
6060
for labelKey, labelValue := range result.Labels {
61-
sb.WriteString(fmt.Sprintf("\t\t%s:%s\n", labelKey, labelValue))
61+
sb.WriteString(fmt.Sprintf("\t\t%q:%q\n", labelKey, labelValue))
6262
}
6363

6464
if len(result.Suggestions) > 0 {

pkg/apis/scorecard/v1alpha2/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type State string
2323

2424
const (
2525
// NotRun occurs when a user specifies the --list flag
26-
NotRunState State = "not run"
26+
NotRunState State = ""
2727
// PassState occurs when a Test's ExpectedPoints == MaximumPoints.
2828
PassState State = "pass"
2929
// FailState occurs when a Test's ExpectedPoints == 0.

0 commit comments

Comments
 (0)