Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/some-tests #3

Merged
merged 1 commit into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions parser/proxy/proxy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package proxy

import "testing"

func TestProxy_GetAddress(t *testing.T) {
type fields struct {
Ipv4 string
Port int
ProxyType string
}
tests := []struct {
name string
fields fields
want string
}{
{
name: "Make address as string ip:port",
fields: fields{
Ipv4: "0.0.0.0",
Port: 1234,
ProxyType: "https",
},
want: "0.0.0.0:1234",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := Proxy{
Ipv4: tt.fields.Ipv4,
Port: tt.fields.Port,
ProxyType: tt.fields.ProxyType,
}
if got := p.GetAddress(); got != tt.want {
t.Errorf("GetAddress() = %v, want %v", got, tt.want)
}
})
}
}
74 changes: 74 additions & 0 deletions scaper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package proxyscraper

import (
"github.com/texnicii/proxy-scraper/parser/proxy"
"reflect"
"testing"
)

func TestCollectUniq(t *testing.T) {
a := proxy.Proxy{
Ipv4: "0.0.0.0",
Port: 0,
ProxyType: "0",
}
b := proxy.Proxy{
Ipv4: "1.0.0.0",
Port: 0,
ProxyType: "0",
}
//is not uniq by ip address with "a"
c := proxy.Proxy{
Ipv4: "0.0.0.0",
Port: 0,
ProxyType: "1",
}

type args struct {
inputData []proxy.Proxy
errorCh <-chan error
debug bool
}
tests := []struct {
name string
args args
want map[string]proxy.Proxy
}{
{
name: "Two uniq elements write to channel",
args: args{
inputData: []proxy.Proxy{a, b},
errorCh: nil,
debug: false,
},
want: map[string]proxy.Proxy{
"0.0.0.0": a,
"1.0.0.0": b,
},
},
{
name: "Two uniq elements write to channel",
args: args{
inputData: []proxy.Proxy{a, c},
errorCh: nil,
debug: false,
},
want: map[string]proxy.Proxy{
"0.0.0.0": a,
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
inputCh := make(chan []proxy.Proxy)
go func() {
inputCh <- tt.args.inputData
close(inputCh)
}()
if got := CollectUniq(inputCh, nil, tt.args.debug); !reflect.DeepEqual(got, tt.want) {
t.Errorf("CollectUniq() = %v, want %v", got, tt.want)
}
})
}
}