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:
Ta-Ching Chen
2019-11-12 21:00:55 +08:00
committed by GitHub
parent a645a1e197
commit 1cda7e051b
5 changed files with 58 additions and 21 deletions
@@ -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)
}
}