Skip to content

Commit

Permalink
Merge pull request #14849 from fabianofranz/issues_14794
Browse files Browse the repository at this point in the history
Merged by openshift-bot
  • Loading branch information
OpenShift Bot authored Jun 25, 2017
2 parents 1e19d81 + 2208669 commit d41a748
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 11 deletions.
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())
}
}
}

0 comments on commit d41a748

Please sign in to comment.