fix: added some unit tests for vm #8
+24
-1
@@ -35,15 +35,21 @@ func runner(commands []string, t *testing.T) []string {
|
||||
go func() {
|
||||
defer stdin.Close()
|
||||
for _, c := range commands {
|
||||
_, _ = io.WriteString(stdin, c+"\n")
|
||||
_, err = io.WriteString(stdin, c+"\n")
|
||||
if err != nil {
|
||||
t.Errorf("Failed to execute %v because of %q\n", c, err)
|
||||
break
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
reader := bufio.NewReader(stdout)
|
||||
for {
|
||||
// fmt.Printf("reading command outputs...\n")
|
||||
line, err := reader.ReadString('\n')
|
||||
if line != "" {
|
||||
formattedline := fmt.Sprintf("%v", strings.Trim(strings.ReplaceAll(line, "\x00", ""), "\n"))
|
||||
// fmt.Printf("formatting and appending result: %v\n", formattedline)
|
||||
results = append(results, formattedline)
|
||||
}
|
||||
if err != nil {
|
||||
@@ -83,3 +89,20 @@ func TestMain(t *testing.T) {
|
||||
t.Errorf("Output Mismatch\nExpected: %v\nGot: %v\n", expected, results)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTableFull(t *testing.T) {
|
||||
maxRows := 1400
|
||||
commands := make([]string, 0)
|
||||
|
||||
for i := range maxRows {
|
||||
c := fmt.Sprintf("insert %d user%d person%d@example.com", i, i, i)
|
||||
commands = append(commands, c)
|
||||
}
|
||||
commands = append(commands, ".exit")
|
||||
|
||||
results := runner(commands, t)
|
||||
|
||||
if results[1300] != "godb > Error: Table is full" {
|
||||
t.Errorf("Our Tables max capacity is 1300 rows, but we're able to insert %v\n", len(results))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user