-
Notifications
You must be signed in to change notification settings - Fork 2
/
parser_mock.go
49 lines (41 loc) · 1.13 KB
/
parser_mock.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
package client
import (
"context"
"encoding/json"
"io/ioutil"
"log"
"github.com/gerbenjacobs/go-habbo/habbo"
)
type ParserMock struct {
HabboResponse *habbo.Habbo
HabboError error
ProfileResponse *habbo.Profile
ProfileError error
}
func NewParserMock() *ParserMock {
return &ParserMock{}
}
func (p *ParserMock) habbo(context.Context, string, string, bool) (*habbo.Habbo, error) {
return p.HabboResponse, p.HabboError
}
func (p *ParserMock) profile(context.Context, string, string) (*habbo.Profile, error) {
return p.ProfileResponse, p.ProfileError
}
func (p *ParserMock) loadHabbo(file string) {
bytes, err := ioutil.ReadFile(file)
if err != nil {
log.Fatalf("failed to read Habbo file: %v", err)
}
if err := json.Unmarshal(bytes, &p.HabboResponse); err != nil {
log.Fatalf("failed to unmarshal Habbo response: %v", err)
}
}
func (p *ParserMock) loadProfile(file string) {
bytes, err := ioutil.ReadFile(file)
if err != nil {
log.Fatalf("failed to read Habbo file: %v", err)
}
if err := json.Unmarshal(bytes, &p.ProfileResponse); err != nil {
log.Fatalf("failed to unmarshal Habbo response: %v", err)
}
}