Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors must be always shown in oc status #14849

Merged
merged 1 commit into from
Jun 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions pkg/cmd/cli/describe/projectstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,18 +372,18 @@ func printMarkerSuggestions(markers []osgraph.Marker, suggest bool, out *tabwrit
if len(marker.Suggestion) > 0 {
suggestionAmount++
}
if len(marker.Suggestion) > 0 || len(marker.Message) > 0 {
if suggest {
fmt.Fprintln(out, indent+"* "+marker.Message)
switch s := marker.Suggestion.String(); {
case strings.Contains(s, "\n"):
fmt.Fprintln(out)
for _, line := range strings.Split(s, "\n") {
fmt.Fprintln(out, indent+" "+line)
}
case len(s) > 0:
fmt.Fprintln(out, indent+" try: "+s)
if len(marker.Message) > 0 && (suggest || marker.Severity == osgraph.ErrorSeverity) {
fmt.Fprintln(out, indent+"* "+marker.Message)
}
if len(marker.Suggestion) > 0 && suggest {
switch s := marker.Suggestion.String(); {
case strings.Contains(s, "\n"):
fmt.Fprintln(out)
for _, line := range strings.Split(s, "\n") {
fmt.Fprintln(out, indent+" "+line)
}
case len(s) > 0:
fmt.Fprintln(out, indent+" try: "+s)
}
}
}
Expand Down
64 changes: 64 additions & 0 deletions pkg/cmd/cli/describe/projectstatus_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package describe

import (
"bytes"
"strings"
"testing"
"text/tabwriter"
"time"

"k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -12,6 +14,7 @@ import (
kapi "k8s.io/kubernetes/pkg/api"

oapi "github.com/openshift/origin/pkg/api"
osgraph "github.com/openshift/origin/pkg/api/graph"
"github.com/openshift/origin/pkg/client/testclient"
projectapi "github.com/openshift/origin/pkg/project/api"
)
Expand Down Expand Up @@ -465,3 +468,64 @@ func TestProjectStatusErrors(t *testing.T) {
}
}
}

func TestPrintMarkerSuggestions(t *testing.T) {
testCases := []struct {
markers []osgraph.Marker
suggest bool
expected string
}{
{
markers: []osgraph.Marker{
{
Severity: osgraph.InfoSeverity,
Message: "Some info message",
Suggestion: "Some suggestion",
},
},
suggest: true,
expected: "* Some info message\n try: Some suggestion\n",
},
{
markers: []osgraph.Marker{
{
Severity: osgraph.InfoSeverity,
Message: "Some info message",
Suggestion: "Some suggestion",
},
},
suggest: false,
expected: "",
},
{
markers: []osgraph.Marker{
{
Severity: osgraph.ErrorSeverity,
Message: "Some error message",
Suggestion: "Some suggestion",
},
},
suggest: false,
expected: "* Some error message\n",
},
{
markers: []osgraph.Marker{
{
Severity: osgraph.ErrorSeverity,
Message: "Some error message",
Suggestion: "Some suggestion",
},
},
suggest: true,
expected: "* Some error message\n try: Some suggestion\n",
},
}
for _, test := range testCases {
var out bytes.Buffer
writer := tabwriter.NewWriter(&out, 0, 0, 1, ' ', 0)
printMarkerSuggestions(test.markers, test.suggest, writer, "")
if out.String() != test.expected {
t.Errorf("unexpected output, wanted %q, got %q", test.expected, out.String())
}
}
}