mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-20 01:47:33 +00:00
util/vizerror: add As function to get wrapped Error
Signed-off-by: Will Norris <will@tailscale.com>
This commit is contained in:
@@ -5,6 +5,7 @@ package vizerror
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"testing"
|
||||
)
|
||||
@@ -28,3 +29,16 @@ func TestErrorf(t *testing.T) {
|
||||
t.Errorf("error chain does not contain fs.ErrNotExist")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAs(t *testing.T) {
|
||||
verr := New("visible error")
|
||||
err := fmt.Errorf("wrap: %w", verr)
|
||||
|
||||
got, ok := As(err)
|
||||
if !ok {
|
||||
t.Errorf("As() return false, want true")
|
||||
}
|
||||
if got != verr {
|
||||
t.Errorf("As() returned error %v, want %v", got, verr)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user