(t *testing.T)
| 123 | } |
| 124 | |
| 125 | func TestNotFound(t *testing.T) { |
| 126 | if runtime.GOOS == "windows" { |
| 127 | t.Skip("Windows support is TODO") |
| 128 | } |
| 129 | |
| 130 | r := EncodeRecipient("nonexistentplugin", nil) |
| 131 | t.Log(r) |
| 132 | testPluginRecipient, err := NewRecipient(r, &ClientUI{}) |
| 133 | if err != nil { |
| 134 | t.Fatal(err) |
| 135 | } |
| 136 | var e *NotFoundError |
| 137 | if _, err := age.Encrypt(io.Discard, testPluginRecipient); err == nil { |
| 138 | t.Errorf("expected error for nonexistent plugin") |
| 139 | } else if !errors.As(err, &e) { |
| 140 | t.Errorf("expected NotFoundError, got %T: %v", err, err) |
| 141 | } else if e.Name != "nonexistentplugin" { |
| 142 | t.Errorf("expected NotFoundError.Name to be nonexistentplugin, got %q", e.Name) |
| 143 | } else if !errors.Is(err, exec.ErrNotFound) { |
| 144 | t.Errorf("expected error to wrap exec.ErrNotFound, got: %v", err) |
| 145 | } |
| 146 | |
| 147 | buf := &bytes.Buffer{} |
| 148 | id, err := age.GenerateHybridIdentity() |
| 149 | if err != nil { |
| 150 | t.Fatal(err) |
| 151 | } |
| 152 | w, err := age.Encrypt(buf, id.Recipient()) |
| 153 | if err != nil { |
| 154 | t.Fatal(err) |
| 155 | } |
| 156 | w.Close() |
| 157 | |
| 158 | i := EncodeIdentity("nonexistentplugin", nil) |
| 159 | t.Log(i) |
| 160 | testPluginIdentity, err := NewIdentity(i, &ClientUI{}) |
| 161 | if err != nil { |
| 162 | t.Fatal(err) |
| 163 | } |
| 164 | if _, err := age.Decrypt(buf, testPluginIdentity); err == nil { |
| 165 | t.Errorf("expected error for nonexistent plugin") |
| 166 | } else if errors.As(err, new(*age.NoIdentityMatchError)) { |
| 167 | t.Errorf("expected NotFoundError, got NoIdentityMatchError: %v", err) |
| 168 | } else if !errors.As(err, &e) { |
| 169 | t.Errorf("expected NotFoundError, got %T: %v", err, err) |
| 170 | } else if e.Name != "nonexistentplugin" { |
| 171 | t.Errorf("expected NotFoundError.Name to be nonexistentplugin, got %q", e.Name) |
| 172 | } else if !errors.Is(err, exec.ErrNotFound) { |
| 173 | t.Errorf("expected error to wrap exec.ErrNotFound, got: %v", err) |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | func TestPluginError(t *testing.T) { |
| 178 | if runtime.GOOS == "windows" { |
nothing calls this directly
no test coverage detected
searching dependent graphs…