-
Notifications
You must be signed in to change notification settings - Fork 0
/
shorten_test.go
62 lines (47 loc) · 1.42 KB
/
shorten_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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package shorten
import (
"errors"
"testing"
)
type mockProvider struct{}
func (m *mockProvider) S(url string) (string, error) {
return url, nil
}
func TestNewInstance(t *testing.T) {
s := New()
_, err := s.Shorten(&UrlParams{Destination: "asad"})
if !errors.Is(err, ErrNoProviderAvailable) {
t.Error("[TestNewInstance]: Incorrect error")
}
}
func TestShortenWithProvider(t *testing.T) {
s := New()
p := &mockProvider{}
s.AddProvider("test", p)
u, _ := s.Shorten(&UrlParams{Destination: "http://test"})
if u.Link != "http://test" {
t.Errorf("[TestNewInstance] - invalid shorten url. Wanted: %s, Got: %s", "http://test", u.Link)
}
u, _ = s.With("test").Shorten(&UrlParams{Destination: "http://test"})
if u.Link != "http://test" {
t.Errorf("[TestNewInstance] - invalid shorten url. Wanted: %s, Got: %s", "http://test", u.Link)
}
}
func TestProviderFunctionalities(t *testing.T) {
s := New()
p := &mockProvider{}
s.AddProvider("test", p)
if len(s.GetProviders()) != 1 {
t.Errorf("[TestProviderFunctionalities]: Incorrect numbers of providers. ")
}
if s.getFirstProvider() == nil {
t.Errorf("[TestProviderFunctionalities]: Incorrect numbers of providers. ")
}
if s.getProvider() == nil {
t.Errorf("[TestProviderFunctionalities]: Incorrect numbers of providers. ")
}
s.DeleteProvider("test")
if len(s.GetProviders()) != 0 {
t.Errorf("[TestProviderFunctionalities]: Incorrect numbers of providers. ")
}
}