mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 18:31:54 +00:00
fix(sg): cloud eph - do not fail just because we cannot parse reason (#62989)
* do not fail just because we cannot parse reason * fix tests * whitespace
This commit is contained in:
parent
e1974fe9f5
commit
0fcffdd657
@ -178,14 +178,12 @@ type InstanceFeatures struct {
|
||||
features map[string]string
|
||||
}
|
||||
|
||||
func newInstanceStatus(src *cloudapiv1.InstanceState) (*InstanceStatus, error) {
|
||||
reason, err := newStatusReason(src.GetReason())
|
||||
func newInstanceStatus(src *cloudapiv1.InstanceState) *InstanceStatus {
|
||||
status := InstanceStatus{}
|
||||
var err error
|
||||
status.Reason, err = newStatusReason(src.GetReason())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
status := InstanceStatus{
|
||||
Reason: reason,
|
||||
status.Error = err.Error()
|
||||
}
|
||||
switch src.GetInstanceStatus() {
|
||||
case cloudapiv1.InstanceStatus_INSTANCE_STATUS_UNSPECIFIED:
|
||||
@ -201,16 +199,13 @@ func newInstanceStatus(src *cloudapiv1.InstanceState) (*InstanceStatus, error) {
|
||||
status.Status = InstanceStatusUnknown
|
||||
}
|
||||
|
||||
return &status, nil
|
||||
return &status
|
||||
}
|
||||
|
||||
func newInstance(src *cloudapiv1.Instance) (*Instance, error) {
|
||||
details := src.GetInstanceDetails()
|
||||
platform := src.GetPlatformDetails()
|
||||
status, err := newInstanceStatus(src.GetInstanceState())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
status := newInstanceStatus(src.GetInstanceState())
|
||||
features := newInstanceFeaturesFrom(details.GetInstanceFeatures())
|
||||
expiresAt, err := features.GetEphemeralLeaseTime()
|
||||
if err != nil && !errors.Is(err, ErrLeaseTimeNotSet) {
|
||||
|
||||
@ -2,7 +2,6 @@ package cloud
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -39,14 +38,18 @@ func TestInstanceStatus(t *testing.T) {
|
||||
reason: "",
|
||||
},
|
||||
{
|
||||
name: "incorrect reason format",
|
||||
reason: "https://test.com/action/123",
|
||||
errText: "failed to parse status reason",
|
||||
name: "incorrect reason format",
|
||||
statusEnum: cloudapiv1.InstanceStatus_INSTANCE_STATUS_UNSPECIFIED,
|
||||
statusText: "unspecified",
|
||||
reason: "https://test.com/action/123",
|
||||
errText: `failed to parse status reason: "https://test.com/action/123"`,
|
||||
},
|
||||
{
|
||||
name: "incorrect reason field format",
|
||||
reason: "actionURL=https://test.com/action/123, status=completed",
|
||||
errText: "failed to parse status reason",
|
||||
name: "incorrect reason field format",
|
||||
statusEnum: cloudapiv1.InstanceStatus_INSTANCE_STATUS_UNSPECIFIED,
|
||||
statusText: "unspecified",
|
||||
reason: "actionURL=https://test.com/action/123, status=completed",
|
||||
errText: `failed to parse status reason: "actionURL=https://test.com/action/123, status=completed"`,
|
||||
},
|
||||
}
|
||||
for _, tc := range tt {
|
||||
@ -56,14 +59,9 @@ func TestInstanceStatus(t *testing.T) {
|
||||
Reason: &tc.reason,
|
||||
}
|
||||
|
||||
instanceSatus, err := newInstanceStatus(src)
|
||||
if err != nil {
|
||||
if tc.errText == "" {
|
||||
t.Fatal(err)
|
||||
} else if !strings.Contains(err.Error(), tc.errText) {
|
||||
t.Errorf("incorrect error. want=%s have=%s", tc.errText, err.Error())
|
||||
}
|
||||
return
|
||||
instanceSatus := newInstanceStatus(src)
|
||||
if tc.errText != "" && instanceSatus.Error != tc.errText {
|
||||
t.Errorf("incorrect error. want=%s have=%s", tc.errText, instanceSatus.Error)
|
||||
}
|
||||
|
||||
if instanceSatus.Reason.JobURL != tc.jobURL {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user