Skip to content

Commit 4674e78

Browse files
authored
extend dataRequestErrorToStatus testing (#996)
<!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. --> ## Overview Extend the unit testing to cover more test cases and turn into a table test as an example for future unit testing. <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. --> ## Checklist <!-- Please complete the checklist to ensure that the PR is ready to be reviewed. IMPORTANT: PRs should be left in Draft until the below checklist is completed. --> - [x] New and updated code has appropriate documentation - [x] New and updated code has new and/or updated testing - [x] Required CI checks are passing - [x] Visual proof for any user facing features like CLI or documentation updates - [x] Linked issues closed with keywords
1 parent 39d020f commit 4674e78

1 file changed

Lines changed: 29 additions & 4 deletions

File tree

da/celestia/celestia_test.go

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,34 @@ import (
1010
)
1111

1212
func TestDataRequestErrorToStatus(t *testing.T) {
13+
randErr := errors.New("some random error")
14+
var test = []struct {
15+
statusCode da.StatusCode
16+
err error
17+
}{
18+
// Status Success Cases
19+
{da.StatusSuccess, nil},
20+
{da.StatusSuccess, da.ErrNamespaceNotFound},
21+
{da.StatusSuccess, errors.Join(randErr, da.ErrNamespaceNotFound, randErr)},
22+
23+
// TODO: cases that need investigating, are these possible? If
24+
// so, is this the correct status code?
25+
{da.StatusSuccess, errors.Join(da.ErrEDSNotFound, da.ErrNamespaceNotFound)},
26+
{da.StatusSuccess, errors.Join(da.ErrDataNotFound, da.ErrNamespaceNotFound)},
27+
28+
// Status not Found Cases
29+
{da.StatusNotFound, da.ErrDataNotFound},
30+
{da.StatusNotFound, da.ErrEDSNotFound},
31+
{da.StatusNotFound, errors.Join(da.ErrEDSNotFound, da.ErrDataNotFound)},
32+
{da.StatusNotFound, errors.Join(da.ErrEDSNotFound, randErr)},
33+
{da.StatusNotFound, errors.Join(randErr, da.ErrDataNotFound)},
34+
35+
// Status Error Cases
36+
{da.StatusError, randErr},
37+
}
1338
assert := assert.New(t)
14-
assert.Equal(da.StatusSuccess, dataRequestErrorToStatus(da.ErrNamespaceNotFound))
15-
assert.Equal(da.StatusNotFound, dataRequestErrorToStatus(da.ErrDataNotFound))
16-
assert.Equal(da.StatusNotFound, dataRequestErrorToStatus(da.ErrEDSNotFound))
17-
assert.Equal(da.StatusError, dataRequestErrorToStatus(errors.New("some random error")))
39+
for _, tt := range test {
40+
t.Logf("Testing %v", tt.err)
41+
assert.Equal(tt.statusCode, dataRequestErrorToStatus(tt.err))
42+
}
1843
}

0 commit comments

Comments
 (0)