Skip to content

Commit 8c4002c

Browse files
authored
verify delete error on conflicting (#3081)
* verify delete error on conflicting * typo fix * go-import-fix
1 parent 7e431ad commit 8c4002c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

cmd/delete_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package cmd
22

33
import (
4+
"bytes"
45
"context"
56
"os"
7+
"strings"
68
"testing"
79

810
fn "knative.dev/func/pkg/functions"
@@ -303,16 +305,23 @@ func TestDelete_NameAndPathExclusivity(t *testing.T) {
303305
// Command with a Client constructor using the mock remover.
304306
cmd := NewDeleteCmd(NewTestClient(fn.WithRemover(remover)))
305307

308+
// Capture command output for inspection
309+
buf := new(bytes.Buffer)
310+
cmd.SetOut(buf)
311+
cmd.SetErr(buf)
312+
306313
// Execute the command simulating the invalid argument combination of both
307314
// a path and an explicit name.
308315
cmd.SetArgs([]string{"-p", "./testpath", "testname"})
309316
err := cmd.Execute()
310317
if err == nil {
311-
// TODO should really either parse the output or use typed errors to ensure it's
312-
// failing for the expected reason.
313318
t.Fatalf("expected error on conflicting flags not received")
314319
}
315320

321+
if !strings.Contains(err.Error(), "only one of --path and [NAME] should be provided") {
322+
t.Fatalf("unexpected error message: %v", err)
323+
}
324+
316325
// Also fail if remover's .Remove is invoked.
317326
if remover.RemoveInvoked {
318327
t.Fatal("fn.Remover invoked despite invalid combination and an error")

0 commit comments

Comments
 (0)