-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror_test.go
More file actions
32 lines (26 loc) · 953 Bytes
/
Copy patherror_test.go
File metadata and controls
32 lines (26 loc) · 953 Bytes
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
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: Copyright (c) 2026 Matthew Penner
package nxhttp_test
import (
"fmt"
"net/http"
"testing"
"github.com/matthewpi/nxhttp"
)
func TestStatusError(t *testing.T) {
var err error
err = nxhttp.NewStatusError(nil, http.StatusOK)
if sErr, ok := nxhttp.AsStatusError(err); !ok {
t.Error("return result of nxhttp.NewStatusError does not work with nxhttp.AsStatusError")
} else if sErr.Expected != http.StatusOK {
t.Error("nxhttp.AsStatusError returned a different nxhttp.StatusError")
}
// Wrap the error so we can ensure [nxhttp.AsStatusError] still works even
// if the error is wrapped.
err = fmt.Errorf("%w", err)
if sErr, ok := nxhttp.AsStatusError(err); !ok {
t.Error("wrapped result of nxhttp.NewStatusError does not work with nxhttp.AsStatusError")
} else if sErr.Expected != http.StatusOK {
t.Error("nxhttp.AsStatusError returned a different nxhttp.StatusError")
}
}