32 lines
1.1 KiB
Go
32 lines
1.1 KiB
Go
package processor
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"errors"
|
||
|
|
"fmt"
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
"github.com/stretchr/testify/assert"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestClassifyVoucherIssue(t *testing.T) {
|
||
|
|
issued := &VoucherIssue{Code: "ABC"}
|
||
|
|
for name, tc := range map[string]struct {
|
||
|
|
issue *VoucherIssue
|
||
|
|
err error
|
||
|
|
want voucherIssueOutcome
|
||
|
|
}{
|
||
|
|
"issued": {issued, nil, voucherIssued},
|
||
|
|
"issued without code": {&VoucherIssue{}, nil, voucherUnknown},
|
||
|
|
"no issue, no error": {nil, nil, voucherUnknown},
|
||
|
|
"refused": {nil, fmt.Errorf("acme: %w: sold out", ErrVoucherProviderRejected), voucherRejected},
|
||
|
|
"never got it": {nil, fmt.Errorf("acme: %w", ErrVoucherProviderNotFound), voucherNotFound},
|
||
|
|
"timeout": {nil, context.DeadlineExceeded, voucherUnknown},
|
||
|
|
"server error": {nil, errors.New("acme: 502 bad gateway"), voucherUnknown},
|
||
|
|
"code with odd error": {issued, errors.New("acme: partial response"), voucherUnknown},
|
||
|
|
"refused despite code": {issued, ErrVoucherProviderRejected, voucherRejected},
|
||
|
|
} {
|
||
|
|
assert.Equal(t, tc.want, classifyVoucherIssue(tc.issue, tc.err), name)
|
||
|
|
}
|
||
|
|
}
|