Skip to content

Commit 26d8211

Browse files
authored
Merge pull request #146 from replicatedhq/remove-invalid-tests
Remove unused code
2 parents 4fca3ff + 6c212e2 commit 26d8211

File tree

5 files changed

+22
-123
lines changed

5 files changed

+22
-123
lines changed

cmd/preflight/cli/run.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ import (
1616
"github.com/pkg/errors"
1717
analyzerunner "github.com/replicatedhq/troubleshoot/pkg/analyze"
1818
troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
19+
troubleshootclientsetscheme "github.com/replicatedhq/troubleshoot/pkg/client/troubleshootclientset/scheme"
1920
"github.com/replicatedhq/troubleshoot/pkg/collect"
2021
"github.com/spf13/viper"
2122
spin "github.com/tj/go-spin"
23+
"k8s.io/client-go/kubernetes/scheme"
2224
)
2325

2426
func runPreflights(v *viper.Viper, arg string) error {
@@ -57,11 +59,15 @@ func runPreflights(v *viper.Viper, arg string) error {
5759
preflightContent = string(body)
5860
}
5961

60-
preflight := troubleshootv1beta1.Preflight{}
61-
if err := json.Unmarshal([]byte(preflightContent), &preflight); err != nil {
62-
return errors.Wrapf(err, "failed to parse %s as a preflight", arg)
62+
troubleshootclientsetscheme.AddToScheme(scheme.Scheme)
63+
decode := scheme.Codecs.UniversalDeserializer().Decode
64+
obj, _, err := decode([]byte(preflightContent), nil, nil)
65+
if err != nil {
66+
return errors.Wrapf(err, "failed to parse %s", arg)
6367
}
6468

69+
preflight := obj.(*troubleshootv1beta1.Preflight)
70+
6571
s := spin.New()
6672
finishedCh := make(chan bool, 1)
6773
progressChan := make(chan interface{}, 0) // non-zero buffer will result in missed messages
@@ -92,7 +98,7 @@ func runPreflights(v *viper.Viper, arg string) error {
9298
close(finishedCh)
9399
}()
94100

95-
allCollectedData, err := runCollectors(v, preflight, progressChan)
101+
allCollectedData, err := runCollectors(v, *preflight, progressChan)
96102
if err != nil {
97103
return err
98104
}

cmd/troubleshoot/cli/run.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ import (
1919
"github.com/mattn/go-isatty"
2020
"github.com/mholt/archiver"
2121
"github.com/pkg/errors"
22-
"github.com/spf13/viper"
23-
spin "github.com/tj/go-spin"
24-
2522
troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
23+
"github.com/replicatedhq/troubleshoot/pkg/client/troubleshootclientset/scheme"
24+
troubleshootclientsetscheme "github.com/replicatedhq/troubleshoot/pkg/client/troubleshootclientset/scheme"
2625
"github.com/replicatedhq/troubleshoot/pkg/collect"
26+
"github.com/spf13/viper"
27+
spin "github.com/tj/go-spin"
2728
)
2829

2930
var (
@@ -47,11 +48,15 @@ func runTroubleshoot(v *viper.Viper, arg string) error {
4748
return errors.Wrap(err, "failed to load collector spec")
4849
}
4950

50-
collector := troubleshootv1beta1.Collector{}
51-
if err := json.Unmarshal(collectorContent, &collector); err != nil {
52-
return errors.Wrapf(err, "failed to parse %s collectors", arg)
51+
troubleshootclientsetscheme.AddToScheme(scheme.Scheme)
52+
decode := scheme.Codecs.UniversalDeserializer().Decode
53+
obj, _, err := decode([]byte(collectorContent), nil, nil)
54+
if err != nil {
55+
return errors.Wrapf(err, "failed to parse %s", arg)
5356
}
5457

58+
collector := obj.(*troubleshootv1beta1.Collector)
59+
5560
s := spin.New()
5661
finishedCh := make(chan bool, 1)
5762
progressChan := make(chan interface{}, 0) // non-zero buffer can result in missed messages
@@ -83,7 +88,7 @@ func runTroubleshoot(v *viper.Viper, arg string) error {
8388
close(finishedCh)
8489
}()
8590

86-
archivePath, err := runCollectors(v, collector, progressChan)
91+
archivePath, err := runCollectors(v, *collector, progressChan)
8792
if err != nil {
8893
return errors.Wrap(err, "run collectors")
8994
}

pkg/apis/troubleshoot/v1beta1/analyzer_shared_test.go

Lines changed: 0 additions & 58 deletions
This file was deleted.

pkg/collect/collector.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package collect
22

33
import (
4-
"encoding/json"
54
"strconv"
65

76
"github.com/pkg/errors"
@@ -190,13 +189,3 @@ func (cs Collectors) CheckRBAC() error {
190189
}
191190
return nil
192191
}
193-
194-
func ParseSpec(specContents string) (*troubleshootv1beta1.Collect, error) {
195-
collect := troubleshootv1beta1.Collect{}
196-
197-
if err := json.Unmarshal([]byte(specContents), &collect); err != nil {
198-
return nil, err
199-
}
200-
201-
return &collect, nil
202-
}

pkg/collect/collector_test.go

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)