From 533c1a6cece8cdf2423a3dcbda072656184c601d Mon Sep 17 00:00:00 2001 From: lew Date: Thu, 18 Dec 2025 15:52:58 +0000 Subject: [PATCH] test(db format): tests for db format error --- cmd/shared.go | 2 +- testdata/del-db__err__with__invalid_db.ct | 2 ++ testdata/get__err__with__invalid_db.ct | 2 ++ testdata/help__ok.ct | 4 ++-- testdata/list__err__with__invalid_db.ct | 2 ++ testdata/root__ok.ct | 2 +- 6 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 testdata/del-db__err__with__invalid_db.ct create mode 100644 testdata/get__err__with__invalid_db.ct create mode 100644 testdata/list__err__with__invalid_db.ct diff --git a/cmd/shared.go b/cmd/shared.go index fdec7d9..d3b622d 100644 --- a/cmd/shared.go +++ b/cmd/shared.go @@ -261,7 +261,7 @@ func ensureSubpath(base, target string) error { } func validateDBName(name string) error { - if strings.ContainsAny(name, `/\`) { + if strings.ContainsAny(name, `/\~`) { return fmt.Errorf("bad db format, use DB or @DB") } return nil diff --git a/testdata/del-db__err__with__invalid_db.ct b/testdata/del-db__err__with__invalid_db.ct new file mode 100644 index 0000000..0d8d373 --- /dev/null +++ b/testdata/del-db__err__with__invalid_db.ct @@ -0,0 +1,2 @@ +$ pda del-db foo/bar --> FAIL +Error: cannot delete-db 'foo/bar': cannot parse db: bad db format, use DB or @DB diff --git a/testdata/get__err__with__invalid_db.ct b/testdata/get__err__with__invalid_db.ct new file mode 100644 index 0000000..c082ae3 --- /dev/null +++ b/testdata/get__err__with__invalid_db.ct @@ -0,0 +1,2 @@ +$ pda get key@foo/bar --> FAIL +Error: cannot get 'key@foo/bar': bad db format, use DB or @DB diff --git a/testdata/help__ok.ct b/testdata/help__ok.ct index 20b0c8c..f097e0e 100644 --- a/testdata/help__ok.ct +++ b/testdata/help__ok.ct @@ -25,7 +25,7 @@ Available Commands: mv Move a key between (or within) databases. restore Restore key/value pairs from an NDJSON dump set Set a value for a key by passing VALUE or Stdin. Optionally specify a db. - version Show the version of your CLI tool + version Display pda! version Flags: -h, --help help for pda @@ -56,7 +56,7 @@ Available Commands: mv Move a key between (or within) databases. restore Restore key/value pairs from an NDJSON dump set Set a value for a key by passing VALUE or Stdin. Optionally specify a db. - version Show the version of your CLI tool + version Display pda! version Flags: -h, --help help for pda diff --git a/testdata/list__err__with__invalid_db.ct b/testdata/list__err__with__invalid_db.ct new file mode 100644 index 0000000..b2594dc --- /dev/null +++ b/testdata/list__err__with__invalid_db.ct @@ -0,0 +1,2 @@ +$ pda ls foo/bar --> FAIL +Error: cannot ls 'foo/bar': cannot parse db: bad db format, use DB or @DB diff --git a/testdata/root__ok.ct b/testdata/root__ok.ct index f0d9530..2cff512 100644 --- a/testdata/root__ok.ct +++ b/testdata/root__ok.ct @@ -24,7 +24,7 @@ Available Commands: mv Move a key between (or within) databases. restore Restore key/value pairs from an NDJSON dump set Set a value for a key by passing VALUE or Stdin. Optionally specify a db. - version Show the version of your CLI tool + version Display pda! version Flags: -h, --help help for pda