-
Notifications
You must be signed in to change notification settings - Fork 510
/
Copy pathproxy_test.go
89 lines (80 loc) · 2.53 KB
/
proxy_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright 2020 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package jujuclient_test
import (
"github.com/juju/testing"
jc "github.com/juju/testing/checkers"
"go.uber.org/mock/gomock"
gc "gopkg.in/check.v1"
"gopkg.in/yaml.v3"
"github.com/juju/juju/caas/kubernetes/provider/proxy"
"github.com/juju/juju/jujuclient"
)
type proxyWrapperSuite struct {
testing.IsolationSuite
}
var _ = gc.Suite(&proxyWrapperSuite{})
func (p *proxyWrapperSuite) TestMarshalling(c *gc.C) {
config := proxy.ProxierConfig{
APIHost: "https://127.0.0.1:443",
CAData: "cadata====",
Namespace: "test",
RemotePort: "8123",
Service: "test",
ServiceAccountToken: "token====",
}
proxier := proxy.NewProxier(config)
wrapper := &jujuclient.ProxyConfWrapper{proxier}
data, err := yaml.Marshal(wrapper)
c.Assert(err, jc.ErrorIsNil)
c.Assert(string(data), gc.Equals, `
type: kubernetes-port-forward
config:
api-host: https://127.0.0.1:443
ca-cert: cadata====
namespace: test
remote-port: "8123"
service: test
service-account-token: token====
`[1:])
}
func (p *proxyWrapperSuite) TestUnmarshalling(c *gc.C) {
ctrl := gomock.NewController(c)
defer ctrl.Finish()
config := proxy.ProxierConfig{
APIHost: "https://127.0.0.1:443",
CAData: "cadata====",
Namespace: "test",
RemotePort: "8123",
Service: "test",
ServiceAccountToken: "token====",
}
proxier := proxy.NewProxier(config)
rawConfig := map[string]interface{}{
"api-host": "https://127.0.0.1:443",
"ca-cert": "cadata====",
"namespace": "test",
"remote-port": "8123",
"service": "test",
"service-account-token": "token====",
}
factory := NewMockProxyFactory(ctrl)
factory.EXPECT().ProxierFromConfig("kubernetes-port-forward", rawConfig).Return(proxier, nil)
p.PatchValue(&jujuclient.NewProxierFactory, func() (jujuclient.ProxyFactory, error) { return factory, nil })
var wrapper jujuclient.ProxyConfWrapper
err := yaml.Unmarshal([]byte(`
type: kubernetes-port-forward
config:
api-host: https://127.0.0.1:443
ca-cert: cadata====
namespace: test
remote-port: "8123"
service: test
service-account-token: token====
`[1:]), &wrapper)
c.Assert(err, jc.ErrorIsNil)
c.Assert(wrapper.Proxier.Type(), gc.Equals, "kubernetes-port-forward")
rCfg, err := wrapper.Proxier.RawConfig()
c.Assert(err, jc.ErrorIsNil)
c.Assert(rCfg, gc.DeepEquals, rawConfig)
}