-
Notifications
You must be signed in to change notification settings - Fork 0
/
func_get_feed_params_test.go
75 lines (67 loc) · 1.2 KB
/
func_get_feed_params_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
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"encoding/json"
"fmt"
"io"
"strings"
"testing"
)
type TestFeedParams struct {
Name string `json:"name"`
URL string `json:"url"`
}
func TestGetFeedParams(t *testing.T) {
str := "this is a string"
tests := []struct {
input TestFeedParams
expect FeedParams
}{
{}, // zero values
{
input: TestFeedParams{
Name: str,
},
expect: FeedParams{
Name: str,
},
},
{
input: TestFeedParams{
URL: str,
},
expect: FeedParams{
URL: str,
},
},
{
input: TestFeedParams{
Name: str,
URL: str,
},
expect: FeedParams{
Name: str,
URL: str,
},
},
}
for i, test := range tests {
t.Run(fmt.Sprintf("TestGetFeedParams Case #%v:", i), func(t *testing.T) {
b, err := json.Marshal(test.input)
if err != nil {
t.Errorf("Error: TestGetFeedParams Case #%v: %v", i, err)
return
}
reader := strings.NewReader(string(b))
readCloser := io.NopCloser(reader)
output, err := getFeedParams(readCloser)
if err != nil {
t.Errorf("Error: TestGetFeedParams Case #%v: %v", i, err)
return
}
if output != test.expect {
t.Errorf("Unexpected: TestGetFeedParams: \n%v", output)
return
}
})
}
}