(t *testing.T)
| 175 | } |
| 176 | |
| 177 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…