MCPcopy Create free account
hub / github.com/docker/secrets-engine / Test_restoreConfig

Function Test_restoreConfig

plugin/config_test.go:130–192  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

128}
129
130func Test_restoreConfig(t *testing.T) {
131 tests := []struct {
132 name string
133 test func(t *testing.T)
134 }{
135 {
136 name: "no config from the runtime",
137 test: func(t *testing.T) {
138 _, err := restoreConfig(&mockPlugin{})
139 assert.ErrorIs(t, err, errPluginNotLaunchedByEngine)
140 },
141 },
142 {
143 name: "invalid config from the runtime",
144 test: func(t *testing.T) {
145 t.Setenv(api.PluginLaunchedByEngineVar, "test-plugin")
146 _, err := restoreConfig(&mockPlugin{})
147 assert.Error(t, err)
148 },
149 },
150 {
151 name: "valid config",
152 test: func(t *testing.T) {
153 sockets, err := nriNet.NewSocketPair()
154 require.NoError(t, err)
155 t.Cleanup(func() { sockets.Close() })
156 conn, err := sockets.LocalConn()
157 require.NoError(t, err)
158 t.Cleanup(func() { conn.Close() })
159 peerFile := sockets.PeerFile()
160 t.Cleanup(func() { peerFile.Close() })
161 engineCfg := ipc.PluginConfigFromEngine{
162 Name: "test-plugin",
163 RegistrationTimeout: 10 * api.DefaultPluginRegistrationTimeout,
164 Custom: ipc.FakeTestCustom(int(peerFile.Fd())),
165 }
166 cfgString, err := engineCfg.ToString()
167 require.NoError(t, err)
168 t.Setenv(api.PluginLaunchedByEngineVar, cfgString)
169
170 cfg, err := restoreConfig(&mockPlugin{})
171 assert.NoError(t, err)
172 assert.Equal(t, "test-plugin", cfg.name)
173 assert.Equal(t, 10*api.DefaultPluginRegistrationTimeout, cfg.registrationTimeout)
174 t.Cleanup(func() { cfg.conn.Close() })
175 msg := []byte("hello test")
176 go func() {
177 _, err := conn.Write(msg)
178 assert.NoError(t, err)
179 }()
180 buf := make([]byte, len(msg))
181 n, err := cfg.conn.Read(buf)
182 assert.NoError(t, err)
183 assert.Equal(t, msg, buf[:n])
184 },
185 },
186 }
187 for _, tt := range tests {

Callers

nothing calls this directly

Calls 7

ToStringMethod · 0.95
restoreConfigFunction · 0.85
CloseMethod · 0.65
RunMethod · 0.65
ErrorMethod · 0.45
WriteMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected