HEX
Server: LiteSpeed
System: Linux in-mum-web785.main-hosting.eu 4.18.0-553.34.1.lve.el8.x86_64 #1 SMP Thu Jan 9 16:30:32 UTC 2025 x86_64
User: u338768758 (338768758)
PHP: 8.3.30
Disabled: system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Upload Files
File: //opt/go/pkg/mod/github.com/hashicorp/errwrap@v1.0.0/errwrap_test.go
package errwrap

import (
	"fmt"
	"testing"
)

func TestWrappedError_impl(t *testing.T) {
	var _ error = new(wrappedError)
}

func TestGetAll(t *testing.T) {
	cases := []struct {
		Err error
		Msg string
		Len int
	}{
		{},
		{
			fmt.Errorf("foo"),
			"foo",
			1,
		},
		{
			fmt.Errorf("bar"),
			"foo",
			0,
		},
		{
			Wrapf("bar", fmt.Errorf("foo")),
			"foo",
			1,
		},
		{
			Wrapf("{{err}}", fmt.Errorf("foo")),
			"foo",
			2,
		},
		{
			Wrapf("bar", Wrapf("baz", fmt.Errorf("foo"))),
			"foo",
			1,
		},
	}

	for i, tc := range cases {
		actual := GetAll(tc.Err, tc.Msg)
		if len(actual) != tc.Len {
			t.Fatalf("%d: bad: %#v", i, actual)
		}
		for _, v := range actual {
			if v.Error() != tc.Msg {
				t.Fatalf("%d: bad: %#v", i, actual)
			}
		}
	}
}

func TestGetAllType(t *testing.T) {
	cases := []struct {
		Err  error
		Type interface{}
		Len  int
	}{
		{},
		{
			fmt.Errorf("foo"),
			"foo",
			0,
		},
		{
			fmt.Errorf("bar"),
			fmt.Errorf("foo"),
			1,
		},
		{
			Wrapf("bar", fmt.Errorf("foo")),
			fmt.Errorf("baz"),
			2,
		},
		{
			Wrapf("bar", Wrapf("baz", fmt.Errorf("foo"))),
			Wrapf("", nil),
			0,
		},
	}

	for i, tc := range cases {
		actual := GetAllType(tc.Err, tc.Type)
		if len(actual) != tc.Len {
			t.Fatalf("%d: bad: %#v", i, actual)
		}
	}
}