aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2025-02-06 17:09:39 -0300
committerEuAndreh <eu@euandre.org>2025-02-06 17:09:39 -0300
commit63c15f4b904b0669a5b4e56d0e2e76fb083b98e7 (patch)
tree4afb9df91df42f2a549e07214768747900fa7eba
parentsrc/dedo.go: Parameterize the file "magic" byte markers (diff)
downloaddedo-63c15f4b904b0669a5b4e56d0e2e76fb083b98e7.tar.gz
dedo-63c15f4b904b0669a5b4e56d0e2e76fb083b98e7.tar.xz
tests/dedo.go: Add tests for usage(), getGetopt() and setGetopt()
Diffstat (limited to '')
-rw-r--r--src/dedo.go2
-rw-r--r--tests/dedo.go88
2 files changed, 88 insertions, 2 deletions
diff --git a/src/dedo.go b/src/dedo.go
index 86012c1..8ebc4c4 100644
--- a/src/dedo.go
+++ b/src/dedo.go
@@ -3932,7 +3932,7 @@ func listExec(args argsT, db *DB, r io.Reader, w io.Writer) error {
func usage(argv0 string, w io.Writer) {
fmt.Fprintf(
w,
- "Usage: %s [-f FILE] [-b BUCKET] COMMAND [ARGUMENTS...]\n",
+ "Usage: %s [-f FILE] [-b BUCKET] COMMAND [ARGS...]\n",
argv0,
)
}
diff --git a/tests/dedo.go b/tests/dedo.go
index ba78b34..1d585c6 100644
--- a/tests/dedo.go
+++ b/tests/dedo.go
@@ -182,12 +182,95 @@ func test_Open() {
g.TestStart("Open()")
}
+func test_getGetopt() {
+ g.TestStart("getGetopt()")
+
+ g.Testing("checks for the require positional argument", func() {
+ var w strings.Builder
+ argsIn := argsT{
+ args: []string{},
+ }
+
+ argsOut, ok := getGetopt(argsIn, &w)
+ g.TAssertEqual(w.String(), "Missing KEY.\n")
+ g.TAssertEqual(ok, false)
+ g.TAssertEqual(argsOut, argsIn)
+ })
+
+ g.Testing("success otherwise", func() {
+ var w strings.Builder
+ argsIn := argsT{
+ args: []string{"a key"},
+ }
+
+ argsOut, ok := getGetopt(argsIn, &w)
+ g.TAssertEqual(w.String(), "")
+ g.TAssertEqual(ok, true)
+ argsIn.key = []byte("a key")
+ g.TAssertEqual(argsOut, argsIn)
+ })
+}
+
+func test_setGetopt() {
+ g.TestStart("setGetopt()")
+
+ g.Testing("checks for required KEY argument", func() {
+ var w strings.Builder
+ argsIn := argsT{
+ args: []string{},
+ }
+
+ argsOut, ok := setGetopt(argsIn, &w)
+ g.TAssertEqual(w.String(), "Missing KEY and VALUE.\n")
+ g.TAssertEqual(ok, false)
+ g.TAssertEqual(argsOut, argsIn)
+ })
+
+ g.Testing("given KEY, it still needs the VALUE", func() {
+ var w strings.Builder
+ argsIn := argsT{
+ args: []string{"a key"},
+ }
+
+ argsOut, ok := setGetopt(argsIn, &w)
+ g.TAssertEqual(w.String(), "Missing VALUE.\n")
+ g.TAssertEqual(ok, false)
+ g.TAssertEqual(argsOut, argsIn)
+ })
+
+ g.Testing("we get a custom argsT{} otherwise", func() {
+ var w strings.Builder
+ argsIn := argsT{
+ args: []string{"a key", "a value"},
+ }
+
+ argsOut, ok := setGetopt(argsIn, &w)
+ g.TAssertEqual(w.String(), "")
+ g.TAssertEqual(ok, true)
+ argsIn.key = []byte("a key")
+ argsIn.value = []byte("a value")
+ g.TAssertEqual(argsOut, argsIn)
+ })
+}
+
+func test_usage() {
+ g.TestStart("usage()")
+
+ g.Testing("it just writes to the given io.Writer", func() {
+ var w strings.Builder
+ usage("yyy", &w)
+ const message =
+ "Usage: yyy [-f FILE] [-b BUCKET] COMMAND [ARGS...]\n"
+ g.TAssertEqual(w.String(), message)
+ })
+}
+
func test_getopt() {
g.TestStart("getopt()")
const warning = "Missing COMMAND.\n"
const usage =
- "Usage: $0 [-f FILE] [-b BUCKET] COMMAND [ARGUMENTS...]\n"
+ "Usage: $0 [-f FILE] [-b BUCKET] COMMAND [ARGS...]\n"
commandsMap := map[string]commandT{
"good": commandT{
@@ -6542,6 +6625,9 @@ func MainTest() {
test_readPageSize()
test_initDB()
test_Open()
+ test_getGetopt()
+ test_setGetopt()
+ test_usage()
test_getopt()
test_runCommand()
test_commands()