1
0
mirror of https://github.com/go-acme/lego.git synced 2024-11-25 09:00:57 +02:00
lego/certificate/errors_test.go

70 lines
1.2 KiB
Go
Raw Normal View History

2023-08-19 18:05:33 +02:00
package certificate
import (
"errors"
"testing"
"github.com/stretchr/testify/require"
)
type TomatoError struct{}
func (t TomatoError) Error() string {
return "tomato"
}
type CarrotError struct{}
func (t CarrotError) Error() string {
return "carrot"
}
func Test_obtainError_Join(t *testing.T) {
failures := newObtainError()
failures.Add("example.com", &TomatoError{})
err := failures.Join()
to := &TomatoError{}
2023-10-31 15:08:50 +02:00
require.ErrorAs(t, err, &to)
2023-08-19 18:05:33 +02:00
}
func Test_obtainError_Join_multiple_domains(t *testing.T) {
failures := newObtainError()
failures.Add("example.com", &TomatoError{})
failures.Add("example.org", &CarrotError{})
err := failures.Join()
to := &TomatoError{}
2023-10-31 15:08:50 +02:00
require.ErrorAs(t, err, &to)
2023-08-19 18:05:33 +02:00
ca := &CarrotError{}
2023-10-31 15:08:50 +02:00
require.ErrorAs(t, err, &ca)
2023-08-19 18:05:33 +02:00
}
func Test_obtainError_Join_no_error(t *testing.T) {
failures := newObtainError()
2023-10-31 15:08:50 +02:00
require.NoError(t, failures.Join())
2023-08-19 18:05:33 +02:00
}
func Test_obtainError_Join_same_domain(t *testing.T) {
failures := newObtainError()
failures.Add("example.com", &TomatoError{})
failures.Add("example.com", &CarrotError{})
err := failures.Join()
to := &TomatoError{}
if errors.As(err, &to) {
require.Fail(t, "TomatoError should be overridden by CarrotError")
}
ca := &CarrotError{}
2023-10-31 15:08:50 +02:00
require.ErrorAs(t, err, &ca)
2023-08-19 18:05:33 +02:00
}