Build error formatting on fission spec apply --wait (#1403)
The character `\n` in buildlog stores in package status are escaped and so when we have to replace them with actual line breaker.
This commit is contained in:
@@ -25,6 +25,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
@@ -175,3 +176,15 @@ func DownloadStoragesvcURL(client *client.Client, fileUrl string) (io.ReadCloser
|
||||
|
||||
return reader, nil
|
||||
}
|
||||
|
||||
// PrintPackageSummary prints package information and build logs.
|
||||
func PrintPackageSummary(writer io.Writer, pkg *fv1.Package) {
|
||||
// replace escaped line breaker character
|
||||
buildlog := strings.ReplaceAll(pkg.Status.BuildLog, `\n`, "\n")
|
||||
w := tabwriter.NewWriter(writer, 0, 0, 1, ' ', 0)
|
||||
fmt.Fprintf(w, "%v\t%v\n", "Name:", pkg.Metadata.Name)
|
||||
fmt.Fprintf(w, "%v\t%v\n", "Environment:", pkg.Spec.Environment.Name)
|
||||
fmt.Fprintf(w, "%v\t%v\n", "Status:", pkg.Status.BuildStatus)
|
||||
fmt.Fprintf(w, "%v\n%v", "Build Logs:", buildlog)
|
||||
w.Flush()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||
)
|
||||
|
||||
func TestPrintPackageSummary(t *testing.T) {
|
||||
|
||||
pkg := &fv1.Package{
|
||||
Metadata: metav1.ObjectMeta{
|
||||
Name: "foobar",
|
||||
Namespace: "dummy",
|
||||
},
|
||||
Status: fv1.PackageStatus{
|
||||
BuildStatus: "failed",
|
||||
BuildLog: "dummy-build-log",
|
||||
},
|
||||
}
|
||||
|
||||
expected := `Name: foobar\nEnvironment: \nStatus: failed\nBuild Logs:\ndummy-build-log`
|
||||
writer := &bytes.Buffer{}
|
||||
PrintPackageSummary(writer, pkg)
|
||||
|
||||
gotWriter := strings.ReplaceAll(writer.String(), "\n", `\n`)
|
||||
if gotWriter != expected {
|
||||
t.Errorf("PrintPackageBuildLog() = %v, want %v", gotWriter, expected)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user