summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-10-26 15:47:57 -0300
committerEuAndreh <eu@euandre.org>2024-10-26 16:47:14 -0300
commitda12c61343f988a6f19f65bf7be331298bc1cca8 (patch)
treed62b50894858e7099a68bf5de362a2c267b47bb9 /tests
parentMakefile: "var version" -> "const Version" (diff)
downloadpapod-da12c61343f988a6f19f65bf7be331298bc1cca8.tar.gz
papod-da12c61343f988a6f19f65bf7be331298bc1cca8.tar.xz
Big bundle commit: adjust build project skeleton; include uncommitted code
There was some code that was being slowly tweaked as I'd work or related things on other repositories that wasn't committed step by step, and that now I'd rather include all as a single changeset, single there weren't really separated stages on how it was developed. Other than that, this commit includes adjustments on dependencies API usage, as they changed during my work on them, and adjustments on the build and test system, as I improved how they worked also during work on other projects. As of this commit, the code compiles and the tests pass. I can't recall if this was true before this commit, but it is true now.
Diffstat (limited to 'tests')
l---------tests/benchmarks/join-leave/main.go1
-rw-r--r--tests/benchmarks/join-leave/papod.go23
l---------tests/functional/multiple-channels-and-users/main.go1
-rw-r--r--tests/functional/multiple-channels-and-users/papod.go12
l---------tests/fuzz/api-check/main.go1
-rw-r--r--tests/fuzz/api-check/papod.go34
-rw-r--r--tests/papod.go124
-rw-r--r--tests/queries.sql0
8 files changed, 126 insertions, 70 deletions
diff --git a/tests/benchmarks/join-leave/main.go b/tests/benchmarks/join-leave/main.go
new file mode 120000
index 0000000..f67563d
--- /dev/null
+++ b/tests/benchmarks/join-leave/main.go
@@ -0,0 +1 @@
+../../main.go \ No newline at end of file
diff --git a/tests/benchmarks/join-leave/papod.go b/tests/benchmarks/join-leave/papod.go
new file mode 100644
index 0000000..7bb69cc
--- /dev/null
+++ b/tests/benchmarks/join-leave/papod.go
@@ -0,0 +1,23 @@
+package papod
+
+import (
+ "flag"
+ "time"
+)
+
+
+
+var nFlag = flag.Int(
+ "n",
+ 1_000,
+ "The number of iterations to execute",
+)
+
+func MainTest() {
+ flag.Parse()
+ n := *nFlag
+
+ for i := 0; i < n; i++ {
+ time.Sleep(time.Millisecond * 1)
+ }
+}
diff --git a/tests/functional/multiple-channels-and-users/main.go b/tests/functional/multiple-channels-and-users/main.go
new file mode 120000
index 0000000..f67563d
--- /dev/null
+++ b/tests/functional/multiple-channels-and-users/main.go
@@ -0,0 +1 @@
+../../main.go \ No newline at end of file
diff --git a/tests/functional/multiple-channels-and-users/papod.go b/tests/functional/multiple-channels-and-users/papod.go
new file mode 100644
index 0000000..6f6a67b
--- /dev/null
+++ b/tests/functional/multiple-channels-and-users/papod.go
@@ -0,0 +1,12 @@
+package papod
+
+import (
+ g "gobang"
+)
+
+
+
+func MainTest() {
+ g.Testing("multiple users can join a channel", func() {
+ })
+}
diff --git a/tests/fuzz/api-check/main.go b/tests/fuzz/api-check/main.go
new file mode 120000
index 0000000..f67563d
--- /dev/null
+++ b/tests/fuzz/api-check/main.go
@@ -0,0 +1 @@
+../../main.go \ No newline at end of file
diff --git a/tests/fuzz/api-check/papod.go b/tests/fuzz/api-check/papod.go
new file mode 100644
index 0000000..edab81c
--- /dev/null
+++ b/tests/fuzz/api-check/papod.go
@@ -0,0 +1,34 @@
+package papod
+
+import (
+ "os"
+ "testing"
+ "testing/internal/testdeps"
+)
+
+
+
+func api(f *testing.F) {
+ f.Fuzz(func(t *testing.T, n int) {
+ if n > 1 {
+ if n < 2 {
+ t.Errorf("Failed n: %v\n", n)
+ }
+ }
+ })
+}
+
+
+
+func MainTest() {
+ fuzzTargets := []testing.InternalFuzzTarget{
+ { "api", api },
+ }
+
+ deps := testdeps.TestDeps{}
+ tests := []testing.InternalTest {}
+ benchmarks := []testing.InternalBenchmark{}
+ examples := []testing.InternalExample {}
+ m := testing.MainStart(deps, tests, benchmarks, fuzzTargets, examples)
+ os.Exit(m.Run())
+}
diff --git a/tests/papod.go b/tests/papod.go
index af2a5f7..2d908f5 100644
--- a/tests/papod.go
+++ b/tests/papod.go
@@ -4,46 +4,42 @@ import (
"bufio"
"database/sql"
"errors"
- "os"
- "reflect"
"strings"
- "testing"
- "testing/internal/testdeps"
+ // "q"
g "gobang"
)
-func errorIf(t *testing.T, err error) {
- if err != nil {
- t.Errorf("Unexpected error: %#v\n", err)
- }
-}
-func errorIfNotI(t *testing.T, i int, err error) {
- if err == nil {
- t.Errorf("Expected error, got nil (i = %d)\n", i)
+func test_initDB() {
+ g.TestStart("initDB()")
+
+ /*
+ q := new(liteq.Queue)
+ sql.Register("sqliteq", liteq.MakeDriver(q))
+
+ db, err := sql.Open("sqliteq", "file:papod-test.db?mode=memory&cache=shared")
+ if err != nil {
+ panic(err)
}
-}
+ // defer db.Close()
-func assertEqualI(t *testing.T, i int, given any, expected any) {
- if !reflect.DeepEqual(given, expected) {
- t.Errorf("given != expected (i = %d)\n", i)
- t.Errorf("given: %#v\n", given)
- t.Errorf("expected: %#v\n", expected)
+ *q, err = liteq.New(db)
+ if err != nil {
+ panic(err)
}
-}
+ // defer q.Close()
-func assertEqual(t *testing.T, given any, expected any) {
- if !reflect.DeepEqual(given, expected) {
- t.Errorf("given != expected")
- t.Errorf("given: %#v\n", given)
- t.Errorf("expected: %#v\n", expected)
+ // _, err = New(db, *q)
+ // _, err = initDB(db,
+ if err != nil {
+ panic(err)
}
+ */
}
-
-func TestSplitOnCRLF(t *testing.T) {
+func test_SplitOnCRLF() {
type tableT struct {
input string
expected []string
@@ -83,7 +79,7 @@ func TestSplitOnCRLF(t *testing.T) {
},
}
- for i, entry := range table {
+ for _, entry := range table {
var given []string
scanner := bufio.NewScanner(strings.NewReader(entry.input))
scanner.Split(SplitOnCRLF)
@@ -92,12 +88,12 @@ func TestSplitOnCRLF(t *testing.T) {
}
err := scanner.Err()
- errorIf(t, err)
- assertEqualI(t, i, given, entry.expected)
+ g.TErrorIf(err)
+ g.TAssertEqual(given, entry.expected)
}
}
-func TestSplitOnRawMessage(t *testing.T) {
+func test_SplitOnRawMessage() {
type tableT struct {
input string
expected []string
@@ -114,7 +110,7 @@ func TestSplitOnRawMessage(t *testing.T) {
}
- for i, entry := range table {
+ for _, entry := range table {
var given []string
scanner := bufio.NewScanner(strings.NewReader(entry.input))
scanner.Split(SplitOnRawMessage)
@@ -123,12 +119,12 @@ func TestSplitOnRawMessage(t *testing.T) {
}
err := scanner.Err()
- errorIf(t, err)
- assertEqualI(t, i, given, entry.expected)
+ g.TErrorIf(err)
+ g.TAssertEqual(given, entry.expected)
}
}
-func TestParseMessageParams(t *testing.T) {
+func test_ParseMessageParams() {
type tableT struct {
input string
expected MessageParams
@@ -311,13 +307,13 @@ func TestParseMessageParams(t *testing.T) {
},
}
- for i, entry := range table {
+ for _, entry := range table {
given := ParseMessageParams(entry.input)
- assertEqualI(t, i, given, entry.expected)
+ g.TAssertEqual(given, entry.expected)
}
}
-func TestParseMessage(t *testing.T) {
+func test_ParseMessage() {
type tableTOK struct {
input string
expected Message
@@ -442,16 +438,16 @@ func TestParseMessage(t *testing.T) {
},
}}
- for i, entry := range tableOK {
+ for _, entry := range tableOK {
given, err := ParseMessage(entry.input)
- errorIf(t, err)
- assertEqualI(t, i, given, entry.expected)
+ g.TErrorIf(err)
+ g.TAssertEqual(given, entry.expected)
}
type tableErrorT struct {
input string
- expected error
+ expected error
}
parseErr := errors.New("Can't parse message")
tableError := []tableErrorT {
@@ -469,31 +465,31 @@ func TestParseMessage(t *testing.T) {
},
}
- for i, entry := range tableError {
+ for _, entry := range tableError {
_, given := ParseMessage(entry.input)
- assertEqualI(t, i, given, entry.expected)
+ g.TAssertEqual(given, entry.expected)
}
}
-func TestInitMigrations(t *testing.T) {
+func test_InitMigrations() {
const query = `SELECT filename FROM migrations;`
db, err := sql.Open("sqlite3", ":memory:")
g.FatalIf(err)
_, err = db.Query(query)
- assertEqual(t, err.Error(), "no such table: migrations")
+ g.TAssertEqual(err.Error(), "no such table: migrations")
for i := 0; i < 5; i++ {
InitMigrations(db)
rows, err := db.Query(query)
g.FatalIf(err)
- assertEqual(t, rows.Next(), false)
+ g.TAssertEqual(rows.Next(), false)
g.FatalIf(rows.Err())
}
}
-func TestPendingMigrations(t *testing.T) {
+func test_PendingMigrations() {
db, err := sql.Open("sqlite3", ":memory:")
g.FatalIf(err)
@@ -501,10 +497,10 @@ func TestPendingMigrations(t *testing.T) {
pending1 := PendingMigrations(db)
pending2 := PendingMigrations(db)
- assertEqual(t, pending1, pending2)
+ g.TAssertEqual(pending1, pending2)
}
-func TestRunMigrations(t *testing.T) {
+func test_RunMigrations() {
db, err := sql.Open("sqlite3", ":memory:")
g.FatalIf(err)
@@ -516,25 +512,13 @@ func TestRunMigrations(t *testing.T) {
func MainTest() {
- tests := []testing.InternalTest {
- { "TestSplitOnCRLF", TestSplitOnCRLF },
- { "TestSplitOnRawMessage", TestSplitOnRawMessage },
- { "TestParseMessageParams", TestParseMessageParams },
- { "TestParseMessage", TestParseMessage },
- { "TestInitMigrations", TestInitMigrations },
- { "TestPendingMigrations", TestPendingMigrations },
- { "TestRunMigrations", TestRunMigrations },
- }
-
- benchmarks := []testing.InternalBenchmark {}
- fuzzTargets := []testing.InternalFuzzTarget {}
- examples := []testing.InternalExample {}
- m := testing.MainStart(
- testdeps.TestDeps {},
- tests,
- benchmarks,
- fuzzTargets,
- examples,
- )
- os.Exit(m.Run())
+ test_initDB()
+ test_SplitOnCRLF()
+ test_SplitOnRawMessage()
+ test_ParseMessageParams()
+ test_ParseMessage()
+
+ // { "TestInitMigrations", TestInitMigrations },
+ // { "TestPendingMigrations", TestPendingMigrations },
+ // { "TestRunMigrations", TestRunMigrations },
}
diff --git a/tests/queries.sql b/tests/queries.sql
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/queries.sql