mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-04-15 07:16:34 +00:00
Merge pull request #146 from replicatedhq/remove-invalid-tests
Remove unused code
This commit is contained in:
@@ -16,9 +16,11 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
analyzerunner "github.com/replicatedhq/troubleshoot/pkg/analyze"
|
||||
troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
|
||||
troubleshootclientsetscheme "github.com/replicatedhq/troubleshoot/pkg/client/troubleshootclientset/scheme"
|
||||
"github.com/replicatedhq/troubleshoot/pkg/collect"
|
||||
"github.com/spf13/viper"
|
||||
spin "github.com/tj/go-spin"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
)
|
||||
|
||||
func runPreflights(v *viper.Viper, arg string) error {
|
||||
@@ -57,11 +59,15 @@ func runPreflights(v *viper.Viper, arg string) error {
|
||||
preflightContent = string(body)
|
||||
}
|
||||
|
||||
preflight := troubleshootv1beta1.Preflight{}
|
||||
if err := json.Unmarshal([]byte(preflightContent), &preflight); err != nil {
|
||||
return errors.Wrapf(err, "failed to parse %s as a preflight", arg)
|
||||
troubleshootclientsetscheme.AddToScheme(scheme.Scheme)
|
||||
decode := scheme.Codecs.UniversalDeserializer().Decode
|
||||
obj, _, err := decode([]byte(preflightContent), nil, nil)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to parse %s", arg)
|
||||
}
|
||||
|
||||
preflight := obj.(*troubleshootv1beta1.Preflight)
|
||||
|
||||
s := spin.New()
|
||||
finishedCh := make(chan bool, 1)
|
||||
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 {
|
||||
close(finishedCh)
|
||||
}()
|
||||
|
||||
allCollectedData, err := runCollectors(v, preflight, progressChan)
|
||||
allCollectedData, err := runCollectors(v, *preflight, progressChan)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -19,11 +19,12 @@ import (
|
||||
"github.com/mattn/go-isatty"
|
||||
"github.com/mholt/archiver"
|
||||
"github.com/pkg/errors"
|
||||
troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
|
||||
"github.com/replicatedhq/troubleshoot/pkg/client/troubleshootclientset/scheme"
|
||||
troubleshootclientsetscheme "github.com/replicatedhq/troubleshoot/pkg/client/troubleshootclientset/scheme"
|
||||
"github.com/replicatedhq/troubleshoot/pkg/collect"
|
||||
"github.com/spf13/viper"
|
||||
spin "github.com/tj/go-spin"
|
||||
|
||||
troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
|
||||
"github.com/replicatedhq/troubleshoot/pkg/collect"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -47,11 +48,15 @@ func runTroubleshoot(v *viper.Viper, arg string) error {
|
||||
return errors.Wrap(err, "failed to load collector spec")
|
||||
}
|
||||
|
||||
collector := troubleshootv1beta1.Collector{}
|
||||
if err := json.Unmarshal(collectorContent, &collector); err != nil {
|
||||
return errors.Wrapf(err, "failed to parse %s collectors", arg)
|
||||
troubleshootclientsetscheme.AddToScheme(scheme.Scheme)
|
||||
decode := scheme.Codecs.UniversalDeserializer().Decode
|
||||
obj, _, err := decode([]byte(collectorContent), nil, nil)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to parse %s", arg)
|
||||
}
|
||||
|
||||
collector := obj.(*troubleshootv1beta1.Collector)
|
||||
|
||||
s := spin.New()
|
||||
finishedCh := make(chan bool, 1)
|
||||
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 {
|
||||
close(finishedCh)
|
||||
}()
|
||||
|
||||
archivePath, err := runCollectors(v, collector, progressChan)
|
||||
archivePath, err := runCollectors(v, *collector, progressChan)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "run collectors")
|
||||
}
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
package v1beta1
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.undefinedlabs.com/scopeagent"
|
||||
)
|
||||
|
||||
func TestAnalyze_Unmarshal(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
spec string
|
||||
expectObject Analyze
|
||||
}{
|
||||
{
|
||||
name: "clusterVersion",
|
||||
spec: `clusterVersion:
|
||||
outcomes:
|
||||
- fail:
|
||||
message: failed
|
||||
- pass:
|
||||
message: passed`,
|
||||
expectObject: Analyze{
|
||||
ClusterVersion: &ClusterVersion{
|
||||
Outcomes: []*Outcome{
|
||||
&Outcome{
|
||||
Fail: &SingleOutcome{
|
||||
Message: "failed",
|
||||
},
|
||||
},
|
||||
&Outcome{
|
||||
Pass: &SingleOutcome{
|
||||
Message: "passed",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
scopetest := scopeagent.StartTest(t)
|
||||
defer scopetest.End()
|
||||
req := require.New(t)
|
||||
|
||||
a := Analyze{}
|
||||
err := json.Unmarshal([]byte(test.spec), &a)
|
||||
req.NoError(err)
|
||||
|
||||
assert.Equal(t, test.expectObject, a)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package collect
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -190,13 +189,3 @@ func (cs Collectors) CheckRBAC() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ParseSpec(specContents string) (*troubleshootv1beta1.Collect, error) {
|
||||
collect := troubleshootv1beta1.Collect{}
|
||||
|
||||
if err := json.Unmarshal([]byte(specContents), &collect); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &collect, nil
|
||||
}
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
package collect
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.undefinedlabs.com/scopeagent"
|
||||
)
|
||||
|
||||
func Test_ParseSpec(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
spec string
|
||||
expectError bool
|
||||
expectObject interface{}
|
||||
}{
|
||||
{
|
||||
name: "clusterInfo",
|
||||
spec: "clusterInfo: {}",
|
||||
expectError: false,
|
||||
expectObject: &troubleshootv1beta1.Collect{
|
||||
ClusterInfo: &troubleshootv1beta1.ClusterInfo{},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
scopetest := scopeagent.StartTest(t)
|
||||
defer scopetest.End()
|
||||
c, err := ParseSpec(test.spec)
|
||||
|
||||
if test.expectError {
|
||||
assert.Error(t, err)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
assert.Equal(t, test.expectObject, c)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user