Skip to content

Commit

Permalink
test: add fuzzer tests
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <[email protected]>
  • Loading branch information
GuptaManan100 committed Feb 27, 2024
1 parent 4047339 commit d416ea8
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions go/test/endtoend/vtgate/foreignkey/fk_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,15 @@ func (fz *fuzzer) generateUpdateDMLQuery() string {
idValue := 1 + rand.Intn(fz.maxValForId)
tableName := fkTables[tableId]
setVarFkChecksVal := fz.getSetVarFkChecksVal()
updWithLimit := rand.Intn(2)
limitCount := rand.Intn(3)
if tableName == "fk_t20" {
colValue := convertIntValueToString(rand.Intn(1 + fz.maxValForCol))
col2Value := convertIntValueToString(rand.Intn(1 + fz.maxValForCol))
return fmt.Sprintf("update %v%v set col = %v, col2 = %v where id = %v", setVarFkChecksVal, tableName, colValue, col2Value, idValue)
if updWithLimit == 0 {
return fmt.Sprintf("update %v%v set col = %v, col2 = %v where id = %v", setVarFkChecksVal, tableName, colValue, col2Value, idValue)
}
return fmt.Sprintf("update %v%v set col = %v, col2 = %v order by id limit %v", setVarFkChecksVal, tableName, colValue, col2Value, limitCount)
} else if isMultiColFkTable(tableName) {
if rand.Intn(2) == 0 {
colaValue := convertIntValueToString(rand.Intn(1 + fz.maxValForCol))
Expand All @@ -169,15 +174,24 @@ func (fz *fuzzer) generateUpdateDMLQuery() string {
colaValue = fz.generateExpression(rand.Intn(4)+1, "cola", "colb", "id")
colbValue = fz.generateExpression(rand.Intn(4)+1, "cola", "colb", "id")
}
return fmt.Sprintf("update %v%v set cola = %v, colb = %v where id = %v", setVarFkChecksVal, tableName, colaValue, colbValue, idValue)
if updWithLimit == 0 {
return fmt.Sprintf("update %v%v set cola = %v, colb = %v where id = %v", setVarFkChecksVal, tableName, colaValue, colbValue, idValue)
}
return fmt.Sprintf("update %v%v set cola = %v, colb = %v order by id limit %v", setVarFkChecksVal, tableName, colaValue, colbValue, limitCount)
} else {
colValue := fz.generateExpression(rand.Intn(4)+1, "cola", "colb", "id")
colToUpdate := []string{"cola", "colb"}[rand.Intn(2)]
return fmt.Sprintf("update %v set %v = %v where id = %v", tableName, colToUpdate, colValue, idValue)
if updWithLimit == 0 {
return fmt.Sprintf("update %v set %v = %v where id = %v", tableName, colToUpdate, colValue, idValue)
}
return fmt.Sprintf("update %v set %v = %v order by id limit %v", tableName, colToUpdate, colValue, limitCount)
}
} else {
colValue := fz.generateExpression(rand.Intn(4)+1, "col", "id")
return fmt.Sprintf("update %v%v set col = %v where id = %v", setVarFkChecksVal, tableName, colValue, idValue)
if updWithLimit == 0 {
return fmt.Sprintf("update %v%v set col = %v where id = %v", setVarFkChecksVal, tableName, colValue, idValue)
}
return fmt.Sprintf("update %v%v set col = %v order by id limit %v", setVarFkChecksVal, tableName, colValue, limitCount)
}
}

Expand Down

0 comments on commit d416ea8

Please sign in to comment.