-
Notifications
You must be signed in to change notification settings - Fork 13
/
mockserviceclient.go
71 lines (62 loc) · 2.5 KB
/
mockserviceclient.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
package apic
import (
"net/http"
"time"
cache2 "github.com/Axway/agent-sdk/pkg/agent/cache"
"github.com/Axway/agent-sdk/pkg/util/log"
"github.com/Axway/agent-sdk/pkg/api"
"github.com/Axway/agent-sdk/pkg/cache"
corecfg "github.com/Axway/agent-sdk/pkg/config"
)
// GetTestServiceClient - return a true ServiceClient, but with mocks for tokengetter and the HTTPClient and dummy values
// for various configurations. Has enough other configuration to make the client usable. This function also returns the
// MockHTTPClient so the caller can use it directly if needed, as it is not available directly from ServiceClient in other packages
func GetTestServiceClient() (*ServiceClient, *api.MockHTTPClient) {
webhook := &corecfg.WebhookConfiguration{
URL: "http://foo.bar",
Headers: "Header=contentType,Value=application/json",
Secret: "",
}
subscriptionCfg := corecfg.SubscriptionConfiguration{
Approval: &corecfg.ApprovalConfig{
SubscriptionApprovalMode: "webhook",
SubscriptionApprovalWebhook: webhook,
},
Notifications: &corecfg.NotificationConfig{
Webhook: &corecfg.WebhookConfiguration{
URL: "http://bar.foo",
Headers: "Header=contentType,Value=application/json",
},
},
}
subscriptionCfg.SetNotificationType(corecfg.NotifySMTP)
cfg := &corecfg.CentralConfiguration{
TeamName: "testteam",
TenantID: "112456",
Environment: "testenvironment",
PollInterval: 1 * time.Second,
Auth: &corecfg.AuthConfiguration{
URL: "http://localhost:8888",
Realm: "Broker",
ClientID: "dummy",
},
SubscriptionConfiguration: &subscriptionCfg,
}
apiClient := &api.MockHTTPClient{ResponseCode: http.StatusOK}
svcClient := &ServiceClient{
cfg: cfg,
tokenRequester: MockTokenGetter,
subscriptionSchemaCache: cache.New(),
caches: cache2.NewAgentCacheManager(cfg, false),
apiClient: apiClient,
DefaultSubscriptionApprovalWebhook: webhook,
DefaultSubscriptionSchema: NewSubscriptionSchema(cfg.GetEnvironmentName() + SubscriptionSchemaNameSuffix),
logger: log.NewFieldLogger(),
}
svcClient.subscriptionMgr = newSubscriptionManager(svcClient)
return svcClient, apiClient
}
// GetTestServiceClientCentralConfiguration - cast and return the CentralConfiguration
func GetTestServiceClientCentralConfiguration(client *ServiceClient) *corecfg.CentralConfiguration {
return client.cfg.(*corecfg.CentralConfiguration)
}