MCPcopy
hub / github.com/FiloSottile/age / TestPluginError

Function TestPluginError

plugin/client_test.go:177–227  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

175}
176
177func TestPluginError(t *testing.T) {
178 if runtime.GOOS == "windows" {
179 t.Skip("Windows support is TODO")
180 }
181 temp := t.TempDir()
182 testOnlyPluginPath = temp
183 t.Cleanup(func() { testOnlyPluginPath = "" })
184 ex, err := os.Executable()
185 if err != nil {
186 t.Fatal(err)
187 }
188 if err := os.Link(ex, filepath.Join(temp, "age-plugin-error")); err != nil {
189 t.Fatal(err)
190 }
191 if err := os.Chmod(filepath.Join(temp, "age-plugin-error"), 0755); err != nil {
192 t.Fatal(err)
193 }
194
195 r := EncodeRecipient("error", nil)
196 testPluginRecipient, err := NewRecipient(r, &ClientUI{})
197 if err != nil {
198 t.Fatal(err)
199 }
200 if _, err := age.Encrypt(io.Discard, testPluginRecipient); err == nil {
201 t.Errorf("expected error from plugin")
202 } else if !strings.Contains(err.Error(), "oh my, an error occurred") {
203 t.Errorf("expected plugin error, got: %v", err)
204 }
205
206 buf := &bytes.Buffer{}
207 id, err := age.GenerateHybridIdentity()
208 if err != nil {
209 t.Fatal(err)
210 }
211 w, err := age.Encrypt(buf, id.Recipient())
212 if err != nil {
213 t.Fatal(err)
214 }
215 w.Close()
216
217 i := EncodeIdentity("error", nil)
218 testPluginIdentity, err := NewIdentity(i, &ClientUI{})
219 if err != nil {
220 t.Fatal(err)
221 }
222 if _, err := age.Decrypt(buf, testPluginIdentity); err == nil {
223 t.Errorf("expected error from plugin")
224 } else if !strings.Contains(err.Error(), "oh my, an error occurred") {
225 t.Errorf("expected plugin error, got: %v", err)
226 }
227}

Callers

nothing calls this directly

Calls 10

EncryptFunction · 0.92
GenerateHybridIdentityFunction · 0.92
DecryptFunction · 0.92
EncodeRecipientFunction · 0.85
EncodeIdentityFunction · 0.85
NewRecipientFunction · 0.70
NewIdentityFunction · 0.70
ErrorMethod · 0.45
RecipientMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…