From e507d907662acdf41fa19fdaeefb166337f8e2d7 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Wed, 8 Nov 2023 22:26:41 -0300 Subject: [PATCH] beginnings of some humble tests. --- example_test.go | 19 +++++++++++++++++++ main.go | 28 ++++++++++++++-------------- 2 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 example_test.go diff --git a/example_test.go b/example_test.go new file mode 100644 index 0000000..2bcca5b --- /dev/null +++ b/example_test.go @@ -0,0 +1,19 @@ +package main + +func ExampleEventBasic() { + app.Run([]string{"nak", "event", "--ts", "1699485669"}) + // Output: + // {"id":"36d88cf5fcc449f2390a424907023eda7a74278120eebab8d02797cd92e7e29c","pubkey":"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","created_at":1699485669,"kind":1,"tags":[],"content":"hello from the nostr army knife","sig":"68e71a192e8abcf8582a222434ac823ecc50607450ebe8cc4c145eb047794cc382dc3f888ce879d2f404f5ba6085a47601360a0fa2dd4b50d317bd0c6197c2c2"} +} + +func ExampleEventComplex() { + app.Run([]string{"nak", "event", "--ts", "1699485669", "-k", "11", "-c", "skjdbaskd", "--sec", "17", "-t", "t=spam", "-e", "36d88cf5fcc449f2390a424907023eda7a74278120eebab8d02797cd92e7e29c", "-t", "r=https://abc.def;nothing"}) + // Output: + // {"id":"aec4de6d051a7c2b6ca2d087903d42051a31e07fb742f1240970084822de10a6","pubkey":"2fa2104d6b38d11b0230010559879124e42ab8dfeff5ff29dc9cdadd4ecacc3f","created_at":1699485669,"kind":11,"tags":[["t","spam"],["r","https://abc.def","nothing"],["e","36d88cf5fcc449f2390a424907023eda7a74278120eebab8d02797cd92e7e29c"]],"content":"skjdbaskd","sig":"1165ac7a27d774d351ef19c8e918fb22f4005fcba193976c3d7edba6ef87ead7f14467f376a9e199f8371835368d86a8506f591e382528d00287fb168a7b8f38"} +} + +func ExampleReq() { + app.Run([]string{"nak", "req", "-k", "1", "-l", "18", "-a", "2fa2104d6b38d11b0230010559879124e42ab8dfeff5ff29dc9cdadd4ecacc3f", "-e", "aec4de6d051a7c2b6ca2d087903d42051a31e07fb742f1240970084822de10a6"}) + // Output + // ["REQ","nak",{"kinds":[1],"authors":["2fa2104d6b38d11b0230010559879124e42ab8dfeff5ff29dc9cdadd4ecacc3f"],"limit":18,"#e":["aec4de6d051a7c2b6ca2d087903d42051a31e07fb742f1240970084822de10a6"]}] +} diff --git a/main.go b/main.go index d3c73c1..b07350b 100644 --- a/main.go +++ b/main.go @@ -7,21 +7,21 @@ import ( "github.com/urfave/cli/v2" ) -func main() { - app := &cli.App{ - Name: "nak", - Usage: "the nostr army knife command-line tool", - Commands: []*cli.Command{ - req, - count, - fetch, - event, - decode, - encode, - verify, - }, - } +var app = &cli.App{ + Name: "nak", + Usage: "the nostr army knife command-line tool", + Commands: []*cli.Command{ + req, + count, + fetch, + event, + decode, + encode, + verify, + }, +} +func main() { if err := app.Run(os.Args); err != nil { fmt.Println(err) os.Exit(1)