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

Function TestNotFound

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

Source from the content-addressed store, hash-verified

123}
124
125func 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
177func TestPluginError(t *testing.T) {
178 if runtime.GOOS == "windows" {

Callers

nothing calls this directly

Calls 9

EncryptFunction · 0.92
GenerateHybridIdentityFunction · 0.92
DecryptFunction · 0.92
EncodeRecipientFunction · 0.85
EncodeIdentityFunction · 0.85
NewRecipientFunction · 0.70
NewIdentityFunction · 0.70
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…