36 lines
906 B
Go
36 lines
906 B
Go
package upstream
|
|
|
|
import "testing"
|
|
|
|
func TestClassifyFetchResult(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
callErr error
|
|
parseErr error
|
|
valid int
|
|
newCount int
|
|
want FetchClass
|
|
}{
|
|
{name: "network error", callErr: errFixture, want: FetchError},
|
|
{name: "parse error", parseErr: errFixture, want: FetchError},
|
|
{name: "empty response", want: FetchEmpty},
|
|
{name: "duplicates are not empty", valid: 3, want: FetchDuplicateOnly},
|
|
{name: "new proxy", valid: 3, newCount: 1, want: FetchValid},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := ClassifyFetchResult(tt.callErr, tt.parseErr, tt.valid, tt.newCount)
|
|
if got != tt.want {
|
|
t.Fatalf("ClassifyFetchResult() = %q, want %q", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
type fixtureError string
|
|
|
|
func (e fixtureError) Error() string { return string(e) }
|
|
|
|
const errFixture = fixtureError("fixture")
|