From c296945f0ea98c6a556ada3e87e70672957033ea Mon Sep 17 00:00:00 2001 From: TakshakRamteke Date: Wed, 29 Jul 2026 00:51:30 +0530 Subject: [PATCH] feat: restructured test to be more idiomatic --- tests/main_test.go | 76 +++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 45 deletions(-) diff --git a/tests/main_test.go b/tests/main_test.go index 94a3b6d..eca49e2 100644 --- a/tests/main_test.go +++ b/tests/main_test.go @@ -66,28 +66,42 @@ func runner(commands []string, t *testing.T) []string { return results } -func TestMain(t *testing.T) { - commands := []string{ - "insert 1 user1 person1@example.com", - "select", - ".exit", +func TestE2E(t *testing.T) { + tests := []struct { + name string + commands []string + expected []string + }{ + { + name: "Test Main Loop", + commands: []string{"insert 1 user1 person1@example.com", "select", ".exit"}, + expected: []string{"godb > Executed.", "godb > {1 user1 person1@example.com}", "Executed.", "godb > bye!"}, + }, + { + name: "Test Maximum Length For Values", + commands: []string{"insert 0 " + strings.Repeat("n", 32) + " " + strings.Repeat("n", 255), ".exit"}, + expected: []string{"godb > Executed.", "godb > bye!"}, + }, + { + name: "Test Over Maximum Length For Values", + commands: []string{"insert 0 " + strings.Repeat("n", 42) + " " + strings.Repeat("n", 275), ".exit"}, + expected: []string{"godb > Values for either username or email are too long", "godb > bye!"}, + }, } - expected := []string{ - "godb > Executed.", - "godb > {1 user1 person1@example.com}", - "Executed.", - "godb > bye!", - } - results := runner(commands, t) + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + results := runner(test.commands, t) + for i := range results { + results[i] = strings.ReplaceAll(results[i], "\n", "") + } - for i := range results { - results[i] = strings.ReplaceAll(results[i], "\n", "") + if !slices.Equal(test.expected, results) { + t.Errorf("Output Mismatch\nExpected: %v\nGot: %v\n", test.expected, results) + } + }) } - if !slices.Equal(expected, results) { - t.Errorf("Output Mismatch\nExpected: %v\nGot: %v\n", expected, results) - } } func TestTableFull(t *testing.T) { @@ -106,31 +120,3 @@ func TestTableFull(t *testing.T) { t.Errorf("Our Tables max capacity is 1300 rows, but we're able to insert %v\n", len(results)) } } - -func TestMaxLengthForValues(t *testing.T) { - commands := []string{"insert 0 " + strings.Repeat("n", 32) + " " + strings.Repeat("n", 255), ".exit"} - expected := []string{"godb > Executed.", "godb > bye!"} - - results := runner(commands, t) - for i := range results { - results[i] = strings.ReplaceAll(results[i], "\n", "") - } - - if !slices.Equal(expected, results) { - t.Errorf("Output Mismatch\nExpected: %v\nGot: %v\n", expected, results) - } -} - -func TestOverMaxLengthValues(t *testing.T) { - commands := []string{"insert 0 " + strings.Repeat("n", 42) + " " + strings.Repeat("n", 275), ".exit"} - expected := []string{"godb > Values for either username or email are too long", "godb > bye!"} - - results := runner(commands, t) - for i := range results { - results[i] = strings.ReplaceAll(results[i], "\n", "") - } - - if !slices.Equal(expected, results) { - t.Errorf("Output Mismatch\nExpected: %v\nGot: %v\n", expected, results) - } -}