mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-04-15 07:16:34 +00:00
fix(hostpreflight): tcploadbalancer analyzer should use first outcome (#1130)
This commit is contained in:
@@ -31,6 +31,12 @@ func TestAnalyzeTCPConnect(t *testing.T) {
|
||||
Message: "Connection was refused",
|
||||
},
|
||||
},
|
||||
{
|
||||
Pass: &troubleshootv1beta2.SingleOutcome{
|
||||
When: "connected",
|
||||
Message: "Connection was successful",
|
||||
},
|
||||
},
|
||||
{
|
||||
Warn: &troubleshootv1beta2.SingleOutcome{
|
||||
Message: "Unexpected TCP connection status",
|
||||
@@ -47,7 +53,7 @@ func TestAnalyzeTCPConnect(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "connected, fail",
|
||||
name: "connected, success",
|
||||
info: &collect.NetworkStatusResult{
|
||||
Status: collect.NetworkStatusConnected,
|
||||
},
|
||||
|
||||
@@ -42,9 +42,9 @@ func (a *AnalyzeHostTCPLoadBalancer) Analyze(getCollectedFileContents func(strin
|
||||
}
|
||||
|
||||
var coll resultCollector
|
||||
result := &AnalyzeResult{Title: a.Title()}
|
||||
|
||||
for _, outcome := range hostAnalyzer.Outcomes {
|
||||
result := &AnalyzeResult{Title: a.Title()}
|
||||
|
||||
if outcome.Fail != nil {
|
||||
if outcome.Fail.When == "" {
|
||||
@@ -53,6 +53,7 @@ func (a *AnalyzeHostTCPLoadBalancer) Analyze(getCollectedFileContents func(strin
|
||||
result.URI = outcome.Fail.URI
|
||||
|
||||
coll.push(result)
|
||||
break
|
||||
}
|
||||
|
||||
if string(actual.Status) == outcome.Fail.When {
|
||||
@@ -61,6 +62,7 @@ func (a *AnalyzeHostTCPLoadBalancer) Analyze(getCollectedFileContents func(strin
|
||||
result.URI = outcome.Fail.URI
|
||||
|
||||
coll.push(result)
|
||||
break
|
||||
}
|
||||
} else if outcome.Warn != nil {
|
||||
if outcome.Warn.When == "" {
|
||||
@@ -69,6 +71,7 @@ func (a *AnalyzeHostTCPLoadBalancer) Analyze(getCollectedFileContents func(strin
|
||||
result.URI = outcome.Warn.URI
|
||||
|
||||
coll.push(result)
|
||||
break
|
||||
}
|
||||
|
||||
if string(actual.Status) == outcome.Warn.When {
|
||||
@@ -77,6 +80,7 @@ func (a *AnalyzeHostTCPLoadBalancer) Analyze(getCollectedFileContents func(strin
|
||||
result.URI = outcome.Warn.URI
|
||||
|
||||
coll.push(result)
|
||||
break
|
||||
}
|
||||
} else if outcome.Pass != nil {
|
||||
if outcome.Pass.When == "" {
|
||||
@@ -85,6 +89,7 @@ func (a *AnalyzeHostTCPLoadBalancer) Analyze(getCollectedFileContents func(strin
|
||||
result.URI = outcome.Pass.URI
|
||||
|
||||
coll.push(result)
|
||||
break
|
||||
}
|
||||
|
||||
if string(actual.Status) == outcome.Pass.When {
|
||||
@@ -93,6 +98,7 @@ func (a *AnalyzeHostTCPLoadBalancer) Analyze(getCollectedFileContents func(strin
|
||||
result.URI = outcome.Pass.URI
|
||||
|
||||
coll.push(result)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
112
pkg/analyze/host_tcploadbalancer_test.go
Normal file
112
pkg/analyze/host_tcploadbalancer_test.go
Normal file
@@ -0,0 +1,112 @@
|
||||
package analyzer
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
|
||||
"github.com/replicatedhq/troubleshoot/pkg/collect"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestAnalyzeTCPLoadBalancer(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
info *collect.NetworkStatusResult
|
||||
hostAnalyzer *troubleshootv1beta2.TCPLoadBalancerAnalyze
|
||||
result []*AnalyzeResult
|
||||
expectErr bool
|
||||
}{
|
||||
{
|
||||
name: "connection refused, fail",
|
||||
info: &collect.NetworkStatusResult{
|
||||
Status: collect.NetworkStatusConnectionRefused,
|
||||
},
|
||||
hostAnalyzer: &troubleshootv1beta2.TCPLoadBalancerAnalyze{
|
||||
Outcomes: []*troubleshootv1beta2.Outcome{
|
||||
{
|
||||
Fail: &troubleshootv1beta2.SingleOutcome{
|
||||
When: "connection-refused",
|
||||
Message: "Connection was refused",
|
||||
},
|
||||
},
|
||||
{
|
||||
Pass: &troubleshootv1beta2.SingleOutcome{
|
||||
When: "connected",
|
||||
Message: "Connection was successful",
|
||||
},
|
||||
},
|
||||
{
|
||||
Warn: &troubleshootv1beta2.SingleOutcome{
|
||||
Message: "Unexpected TCP connection status",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
result: []*AnalyzeResult{
|
||||
{
|
||||
Title: "TCP Load Balancer",
|
||||
IsFail: true,
|
||||
Message: "Connection was refused",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "connected, success",
|
||||
info: &collect.NetworkStatusResult{
|
||||
Status: collect.NetworkStatusConnected,
|
||||
},
|
||||
hostAnalyzer: &troubleshootv1beta2.TCPLoadBalancerAnalyze{
|
||||
Outcomes: []*troubleshootv1beta2.Outcome{
|
||||
{
|
||||
Fail: &troubleshootv1beta2.SingleOutcome{
|
||||
When: "connection-refused",
|
||||
Message: "Connection was refused",
|
||||
},
|
||||
},
|
||||
{
|
||||
Pass: &troubleshootv1beta2.SingleOutcome{
|
||||
When: "connected",
|
||||
Message: "Connection was successful",
|
||||
},
|
||||
},
|
||||
{
|
||||
Warn: &troubleshootv1beta2.SingleOutcome{
|
||||
Message: "Unexpected TCP connection status",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
result: []*AnalyzeResult{
|
||||
{
|
||||
Title: "TCP Load Balancer",
|
||||
IsPass: true,
|
||||
Message: "Connection was successful",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
req := require.New(t)
|
||||
b, err := json.Marshal(test.info)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
getCollectedFileContents := func(filename string) ([]byte, error) {
|
||||
return b, nil
|
||||
}
|
||||
|
||||
result, err := (&AnalyzeHostTCPLoadBalancer{test.hostAnalyzer}).Analyze(getCollectedFileContents)
|
||||
if test.expectErr {
|
||||
req.Error(err)
|
||||
} else {
|
||||
req.NoError(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, test.result, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user