This repository has been archived by the owner on Jul 2, 2024. It is now read-only.
forked from OtusGolang/home_work
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats_test.go
39 lines (32 loc) · 1.56 KB
/
stats_test.go
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
33
34
35
36
37
38
39
// +build !bench
package hw10programoptimization
import (
"bytes"
"testing"
"github.com/stretchr/testify/require"
)
func TestGetDomainStat(t *testing.T) {
data := `{"Id":1,"Name":"Howard Mendoza","Username":"0Oliver","Email":"[email protected]","Phone":"6-866-899-36-79","Password":"InAQJvsq","Address":"Blackbird Place 25"}
{"Id":2,"Name":"Jesse Vasquez","Username":"qRichardson","Email":"[email protected]","Phone":"9-373-949-64-00","Password":"SiZLeNSGn","Address":"Fulton Hill 80"}
{"Id":3,"Name":"Clarence Olson","Username":"RachelAdams","Email":"[email protected]","Phone":"988-48-97","Password":"71kuz3gA5w","Address":"Monterey Park 39"}
{"Id":4,"Name":"Gregory Reid","Username":"tButler","Email":"[email protected]","Phone":"520-04-16","Password":"r639qLNu","Address":"Sunfield Park 20"}
{"Id":5,"Name":"Janice Rose","Username":"KeithHart","Email":"[email protected]","Phone":"146-91-01","Password":"acSBF5","Address":"Russell Trail 61"}`
t.Run("find 'com'", func(t *testing.T) {
result, err := GetDomainStat(bytes.NewBufferString(data), "com")
require.NoError(t, err)
require.Equal(t, DomainStat{
"browsecat.com": 2,
"linktype.com": 1,
}, result)
})
t.Run("find 'gov'", func(t *testing.T) {
result, err := GetDomainStat(bytes.NewBufferString(data), "gov")
require.NoError(t, err)
require.Equal(t, DomainStat{"browsedrive.gov": 1}, result)
})
t.Run("find 'unknown'", func(t *testing.T) {
result, err := GetDomainStat(bytes.NewBufferString(data), "unknown")
require.NoError(t, err)
require.Equal(t, DomainStat{}, result)
})
}