aboutsummaryrefslogtreecommitdiff
path: root/cmd/podman/root_test.go
blob: f2826a304de20936eff8ce9acbb69f0505118f44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main

import (
	"fmt"
	"strings"
	"testing"

	"github.com/containers/podman/v3/libpod/define"
	"github.com/pkg/errors"
)

func TestFormatError(t *testing.T) {
	err := errors.New("unknown error")
	output := formatError(err)
	expected := fmt.Sprintf("Error: %v", err)

	if output != expected {
		t.Errorf("Expected \"%s\" to equal \"%s\"", output, err.Error())
	}
}

func TestFormatOCIError(t *testing.T) {
	expectedPrefix := "Error: "
	expectedSuffix := "OCI runtime output"
	err := errors.Wrap(define.ErrOCIRuntime, expectedSuffix)
	output := formatError(err)

	if !strings.HasPrefix(output, expectedPrefix) {
		t.Errorf("Expected \"%s\" to start with \"%s\"", output, expectedPrefix)
	}
	if !strings.HasSuffix(output, expectedSuffix) {
		t.Errorf("Expected \"%s\" to end with \"%s\"", output, expectedSuffix)
	}
}