MCPcopy Create free account
hub / github.com/conforma/cli / logTaskOutput

Function logTaskOutput

acceptance/kubernetes/kubernetes.go:290–339  ·  view source on GitHub ↗
(ctx context.Context, c ClusterState)

Source from the content-addressed store, hash-verified

288}
289
290func logTaskOutput(ctx context.Context, c ClusterState) error {
291 info, err := c.cluster.TaskInfo(ctx)
292 if err != nil {
293 return err
294 }
295
296 noColors := testenv.NoColorOutput(ctx)
297 if clr.SUPPORT_COLOR != !noColors {
298 clr.SUPPORT_COLOR = !noColors
299 }
300
301 output := &strings.Builder{}
302 outputSegment := func(name string, v any) {
303 output.WriteString("\n\n")
304 output.WriteString(clr.Underline(clr.Bold(name)))
305 output.WriteString(fmt.Sprintf("\n%v", v))
306 }
307
308 var buffy bytes.Buffer
309 w := tabwriter.NewWriter(&buffy, 10, 1, 2, ' ', 0)
310
311 fmt.Fprintf(w, "%s\t%s\n", clr.Bold("Namespace"), info.Namespace)
312 fmt.Fprintf(w, "%s\t%s\n", clr.Bold("TaskRunName2"), info.Name)
313 fmt.Fprintf(w, "%s\t%s", clr.Bold("Status"), info.Status)
314 w.Flush()
315 outputSegment("TaskRun", buffy.String())
316
317 buffy.Reset()
318 fmt.Fprintf(w, "%s\t%s\n", clr.Bold("Name"), clr.Bold("Value"))
319 for n, v := range info.Params {
320 fmt.Fprintf(w, "%s\t%v\n", n, v)
321 }
322 w.Flush()
323 outputSegment("Parameters", buffy.String())
324
325 buffy.Reset()
326 for _, step := range info.Steps {
327 outputSegment(fmt.Sprintf("Step \"%s\"", clr.Bold(step.Name)), fmt.Sprintf("%s %s\n----- Logs -----\n%s\n----- /Logs -----", clr.Bold("Status"), step.Status, step.Logs))
328 }
329 w.Flush()
330
331 // TODO, when the task fails and test state is persisted add some debugging
332 // lines here to help debug, e.g. `export
333 // KUBECONFIG=$TMPDIR/ec-acceptance.../kubeconfig`, set the current
334 // namespace with: `kubectl config set-context --current --namespace
335 // acceptance-...`
336
337 fmt.Println(output)
338 return nil
339}
340
341func taskLogsShouldMatchTheSnapshot(ctx context.Context, stepName string) error {
342 c := testenv.FetchState[ClusterState](ctx)

Callers 1

Calls 3

NoColorOutputFunction · 0.92
TaskInfoMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected