-
Notifications
You must be signed in to change notification settings - Fork 72
/
mockutil.go
88 lines (75 loc) · 2.23 KB
/
mockutil.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
76
77
78
79
80
81
82
83
84
85
86
87
88
package mockutil
import (
"context"
"errors"
"github.com/redhat-developer/app-services-cli/pkg/core/config"
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/iostreams"
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
"github.com/redhat-developer/app-services-cli/pkg/shared/connection"
"github.com/redhat-developer/app-services-cli/pkg/shared/connection/api"
"github.com/redhat-developer/app-services-cli/pkg/shared/connection/kcconnection"
kafkamgmtclient "github.com/redhat-developer/app-services-sdk-core/app-services-sdk-go/kafkamgmt/apiv1/client"
)
func NewConfigMock(cfg *config.Config) config.IConfig {
return &config.IConfigMock{
LocationFunc: func() (string, error) {
return ":mock_location:", nil
},
LoadFunc: func() (*config.Config, error) {
return cfg, nil
},
SaveFunc: func(c *config.Config) error {
cfg = c
return nil
},
RemoveFunc: func() error {
cfg = nil
return nil
},
}
}
func NewConnectionMock(conn *kcconnection.Connection, apiClient *kafkamgmtclient.APIClient) connection.Connection {
return &connection.ConnectionMock{
RefreshTokensFunc: func(ctx context.Context) error {
if conn.Token.AccessToken == "" && conn.Token.RefreshToken == "" {
return errors.New("")
}
if conn.Token.RefreshToken == "expired" {
return errors.New("")
}
return nil
},
LogoutFunc: func(ctx context.Context) error {
if conn.Token.AccessToken == "" && conn.Token.RefreshToken == "" {
return errors.New("")
}
if conn.Token.AccessToken == "expired" && conn.Token.RefreshToken == "expired" {
return errors.New("")
}
cfg, err := conn.Config.Load()
if err != nil {
return err
}
cfg.AccessToken = ""
cfg.RefreshToken = ""
return conn.Config.Save(cfg)
},
APIFunc: func() api.API {
return nil
},
}
}
func NewKafkaRequestTypeMock(name string) kafkamgmtclient.KafkaRequest {
var kafkaReq kafkamgmtclient.KafkaRequest
kafkaReq.SetId("1")
kafkaReq.SetName(name)
return kafkaReq
}
func NewLoggerMock() logging.Logger {
io := iostreams.System()
var logger logging.Logger
loggerBuilder := logging.NewStdLoggerBuilder()
loggerBuilder = loggerBuilder.Streams(io.Out, io.ErrOut)
logger, _ = loggerBuilder.Build()
return logger
}