How to use Execute method of client Package

Best Testkube code snippet using client.Execute

reserve_test.go

Source:reserve_test.go Github

copy

Full Screen

...23func TestMultipleReserveHaveDifferentConnection(t *testing.T) {24 client1 := framework.NewClient()25 client2 := framework.NewClient()26 query := "select connection_id()"27 qrc1_1, err := client1.ReserveExecute(query, nil, nil)28 require.NoError(t, err)29 defer client1.Release()30 qrc2_1, err := client2.ReserveExecute(query, nil, nil)31 require.NoError(t, err)32 defer client2.Release()33 require.NotEqual(t, qrc1_1.Rows, qrc2_1.Rows)34 qrc1_2, err := client1.Execute(query, nil)35 require.NoError(t, err)36 qrc2_2, err := client2.Execute(query, nil)37 require.NoError(t, err)38 require.Equal(t, qrc1_1.Rows, qrc1_2.Rows)39 require.Equal(t, qrc2_1.Rows, qrc2_2.Rows)40}41func TestReserveBeginRelease(t *testing.T) {42 client := framework.NewClient()43 query := "select connection_id()"44 qr1, err := client.ReserveExecute(query, nil, nil)45 require.NoError(t, err)46 defer client.Release()47 qr2, err := client.BeginExecute(query, nil, nil)48 require.NoError(t, err)49 assert.Equal(t, qr1.Rows, qr2.Rows)50 assert.Equal(t, client.ReservedID(), client.TransactionID())51 require.NoError(t, client.Release())52}53func TestBeginReserveRelease(t *testing.T) {54 client := framework.NewClient()55 query := "select connection_id()"56 qr1, err := client.BeginExecute(query, nil, nil)57 require.NoError(t, err)58 defer client.Release()59 qr2, err := client.ReserveExecute(query, nil, nil)60 require.NoError(t, err)61 assert.Equal(t, qr1.Rows, qr2.Rows)62 assert.Equal(t, client.ReservedID(), client.TransactionID())63 require.NoError(t, client.Release())64}65func TestReserveBeginExecuteRelease(t *testing.T) {66 client := framework.NewClient()67 insQuery := "insert into vitess_test (intval, floatval, charval, binval) values (4, null, null, null)"68 selQuery := "select intval from vitess_test where intval = 4"69 _, err := client.ReserveBeginExecute(insQuery, nil, nil, nil)70 require.NoError(t, err)71 qr, err := client.Execute(selQuery, nil)72 require.NoError(t, err)73 assert.Equal(t, `[[INT32(4)]]`, fmt.Sprintf("%v", qr.Rows))74 err = client.Release()75 require.NoError(t, err)76 qr, err = client.Execute(selQuery, nil)77 require.NoError(t, err)78 assert.Equal(t, `[]`, fmt.Sprintf("%v", qr.Rows))79}80func TestMultipleReserveBeginHaveDifferentConnection(t *testing.T) {81 client1 := framework.NewClient()82 client2 := framework.NewClient()83 query := "select connection_id()"84 qrc1_1, err := client1.ReserveBeginExecute(query, nil, nil, nil)85 require.NoError(t, err)86 defer client1.Release()87 qrc2_1, err := client2.ReserveBeginExecute(query, nil, nil, nil)88 require.NoError(t, err)89 defer client2.Release()90 require.NotEqual(t, qrc1_1.Rows, qrc2_1.Rows)91 qrc1_2, err := client1.Execute(query, nil)92 require.NoError(t, err)93 qrc2_2, err := client2.Execute(query, nil)94 require.NoError(t, err)95 require.Equal(t, qrc1_1.Rows, qrc1_2.Rows)96 require.Equal(t, qrc2_1.Rows, qrc2_2.Rows)97}98func TestCommitOnReserveBeginConn(t *testing.T) {99 client := framework.NewClient()100 query := "select connection_id()"101 qr1, err := client.ReserveBeginExecute(query, nil, nil, nil)102 require.NoError(t, err)103 defer client.Release()104 oldRID := client.ReservedID()105 err = client.Commit()106 require.NoError(t, err)107 assert.NotEqual(t, client.ReservedID(), oldRID, "reservedID must change after commit")108 assert.EqualValues(t, 0, client.TransactionID(), "transactionID should be 0 after commit")109 qr2, err := client.Execute(query, nil)110 require.NoError(t, err)111 assert.Equal(t, qr1.Rows, qr2.Rows)112}113func TestRollbackOnReserveBeginConn(t *testing.T) {114 client := framework.NewClient()115 query := "select connection_id()"116 qr1, err := client.ReserveBeginExecute(query, nil, nil, nil)117 require.NoError(t, err)118 defer client.Release()119 oldRID := client.ReservedID()120 err = client.Rollback()121 require.NoError(t, err)122 assert.NotEqual(t, client.ReservedID(), oldRID, "reservedID must change after rollback")123 assert.EqualValues(t, 0, client.TransactionID(), "transactionID should be 0 after commit")124 qr2, err := client.Execute(query, nil)125 require.NoError(t, err)126 assert.Equal(t, qr1.Rows, qr2.Rows)127}128func TestReserveBeginRollbackAndBeginCommitAgain(t *testing.T) {129 client := framework.NewClient()130 query := "select connection_id()"131 qr1, err := client.ReserveBeginExecute(query, nil, nil, nil)132 require.NoError(t, err)133 defer client.Release()134 oldRID := client.ReservedID()135 err = client.Rollback()136 require.NoError(t, err)137 assert.EqualValues(t, 0, client.TransactionID(), "transactionID should be 0 after rollback")138 assert.NotEqual(t, client.ReservedID(), oldRID, "reservedID must change after rollback")139 oldRID = client.ReservedID()140 qr2, err := client.BeginExecute(query, nil, nil)141 require.NoError(t, err)142 err = client.Commit()143 require.NoError(t, err)144 assert.EqualValues(t, 0, client.TransactionID(), "transactionID should be 0 after commit")145 assert.NotEqual(t, client.ReservedID(), oldRID, "reservedID must change after rollback")146 qr3, err := client.Execute(query, nil)147 require.NoError(t, err)148 assert.Equal(t, qr1.Rows, qr2.Rows)149 assert.Equal(t, qr2.Rows, qr3.Rows)150 require.NoError(t,151 client.Release())152}153func TestReserveBeginCommitFailToReuseTxID(t *testing.T) {154 client := framework.NewClient()155 query := "select connection_id()"156 _, err := client.ReserveBeginExecute(query, nil, nil, nil)157 require.NoError(t, err)158 defer client.Release()159 oldTxID := client.TransactionID()160 err = client.Commit()161 require.NoError(t, err)162 client.SetTransactionID(oldTxID)163 _, err = client.Execute(query, nil)164 require.Error(t, err)165 require.NoError(t,166 client.Release())167}168func TestReserveBeginRollbackFailToReuseTxID(t *testing.T) {169 client := framework.NewClient()170 query := "select connection_id()"171 _, err := client.ReserveBeginExecute(query, nil, nil, nil)172 require.NoError(t, err)173 defer client.Release()174 oldTxID := client.TransactionID()175 err = client.Rollback()176 require.NoError(t, err)177 client.SetTransactionID(oldTxID)178 _, err = client.Execute(query, nil)179 require.Error(t, err)180 require.NoError(t,181 client.Release())182}183func TestReserveBeginCommitFailToReuseOldReservedID(t *testing.T) {184 client := framework.NewClient()185 query := "select connection_id()"186 _, err := client.ReserveBeginExecute(query, nil, nil, nil)187 require.NoError(t, err)188 oldRID := client.ReservedID()189 err = client.Commit()190 require.NoError(t, err)191 newRID := client.ReservedID()192 client.SetReservedID(oldRID)193 _, err = client.Execute(query, nil)194 require.Error(t, err)195 client.SetReservedID(newRID)196 require.NoError(t,197 client.Release())198}199func TestReserveBeginRollbackFailToReuseOldReservedID(t *testing.T) {200 client := framework.NewClient()201 query := "select connection_id()"202 _, err := client.ReserveBeginExecute(query, nil, nil, nil)203 require.NoError(t, err)204 oldRID := client.ReservedID()205 err = client.Rollback()206 require.NoError(t, err)207 newRID := client.ReservedID()208 client.SetReservedID(oldRID)209 _, err = client.Execute(query, nil)210 require.Error(t, err)211 client.SetReservedID(newRID)212 require.NoError(t,213 client.Release())214}215func TestReserveReleaseAndFailToUseReservedIDAgain(t *testing.T) {216 client := framework.NewClient()217 query := "select 42"218 _, err := client.ReserveExecute(query, nil, nil)219 require.NoError(t, err)220 rID := client.ReservedID()221 require.NoError(t,222 client.Release())223 client.SetReservedID(rID)224 _, err = client.Execute(query, nil)225 require.Error(t, err)226}227func TestReserveAndFailToRunTwiceConcurrently(t *testing.T) {228 client := framework.NewClient()229 query := "select 42"230 _, err := client.ReserveExecute(query, nil, nil)231 require.NoError(t, err)232 defer client.Release()233 // WaitGroup will make defer call to wait for go func to complete.234 wg := &sync.WaitGroup{}235 wg.Add(1)236 go func() {237 _, err = client.Execute("select sleep(1)", nil)238 wg.Done()239 }()240 _, err2 := client.Execute("select sleep(1)", nil)241 wg.Wait()242 if err == nil && err2 == nil {243 assert.Fail(t, "at least one execution should fail")244 }245}246func TestBeginReserveCommitAndNewTransactionsOnSameReservedID(t *testing.T) {247 client := framework.NewClient()248 query := "select connection_id()"249 qrTx, err := client.BeginExecute(query, nil, nil)250 require.NoError(t, err)251 qrRID, err := client.ReserveExecute(query, nil, nil)252 require.NoError(t, err)253 require.Equal(t, qrTx.Rows, qrRID.Rows)254 err = client.Commit()255 require.NoError(t, err)256 qrTx, err = client.BeginExecute(query, nil, nil)257 require.NoError(t, err)258 require.Equal(t, qrTx.Rows, qrRID.Rows)259 err = client.Commit()260 require.NoError(t, err)261 qrTx, err = client.BeginExecute(query, nil, nil)262 require.NoError(t, err)263 require.Equal(t, qrTx.Rows, qrRID.Rows)264 err = client.Rollback()265 require.NoError(t, err)266 require.NoError(t,267 client.Release())268}269func TestBeginReserveRollbackAndNewTransactionsOnSameReservedID(t *testing.T) {270 client := framework.NewClient()271 query := "select connection_id()"272 qrTx, err := client.BeginExecute(query, nil, nil)273 require.NoError(t, err)274 qrRID, err := client.ReserveExecute(query, nil, nil)275 require.NoError(t, err)276 require.Equal(t, qrTx.Rows, qrRID.Rows)277 err = client.Rollback()278 require.NoError(t, err)279 qrTx, err = client.BeginExecute(query, nil, nil)280 require.NoError(t, err)281 require.Equal(t, qrTx.Rows, qrRID.Rows)282 err = client.Commit()283 require.NoError(t, err)284 qrTx, err = client.BeginExecute(query, nil, nil)285 require.NoError(t, err)286 require.Equal(t, qrTx.Rows, qrRID.Rows)287 err = client.Rollback()288 require.NoError(t, err)289 require.NoError(t,290 client.Release())291}292func TestBeginReserveReleaseAndFailToUseReservedIDAndTxIDAgain(t *testing.T) {293 client := framework.NewClient()294 query := "select 42"295 _, err := client.BeginExecute(query, nil, nil)296 require.NoError(t, err)297 _, err = client.ReserveExecute(query, nil, nil)298 require.NoError(t, err)299 rID := client.ReservedID()300 txID := client.TransactionID()301 require.NoError(t,302 client.Release())303 client.SetReservedID(rID)304 _, err = client.Execute(query, nil)305 require.Error(t, err)306 client.SetReservedID(0)307 client.SetTransactionID(txID)308 _, err = client.Execute(query, nil)309 require.Error(t, err)310}311func TestReserveBeginReleaseAndFailToUseReservedIDAndTxIDAgain(t *testing.T) {312 client := framework.NewClient()313 query := "select 42"314 _, err := client.ReserveExecute(query, nil, nil)315 require.NoError(t, err)316 _, err = client.BeginExecute(query, nil, nil)317 require.NoError(t, err)318 rID := client.ReservedID()319 txID := client.TransactionID()320 require.NoError(t,321 client.Release())322 client.SetReservedID(rID)323 _, err = client.Execute(query, nil)324 require.Error(t, err)325 client.SetReservedID(0)326 client.SetTransactionID(txID)327 _, err = client.Execute(query, nil)328 require.Error(t, err)329}330func TestReserveExecuteWithFailingQueryAndReserveConnectionRemainsOpen(t *testing.T) {331 client := framework.NewClient()332 _, err := client.ReserveExecute("select foo", nil, nil)333 require.Error(t, err)334 defer client.Release()335 require.NotEqual(t, int64(0), client.ReservedID())336 _, err = client.Execute("select 42", nil)337 require.NoError(t, err)338 require.NoError(t, client.Release())339}340func TestReserveAndExecuteWithFailingQueryAndReserveConnectionRemainsOpen(t *testing.T) {341 client := framework.NewClient()342 qr1, err := client.ReserveExecute("select connection_id()", nil, nil)343 require.NoError(t, err)344 defer client.Release()345 _, err = client.Execute("select foo", nil)346 require.Error(t, err)347 qr2, err := client.Execute("select connection_id()", nil)348 require.NoError(t, err)349 require.Equal(t, qr1.Rows, qr2.Rows)350 require.NoError(t, client.Release())351}352func TestReserveBeginExecuteWithFailingQueryAndReserveConnAndTxRemainsOpen(t *testing.T) {353 client := framework.NewClient()354 _, err := client.ReserveBeginExecute("select foo", nil, nil, nil)355 require.Error(t, err)356 // Save the connection id to check in the end that everything got executed on same connection.357 qr1, err := client.Execute("select connection_id()", nil)358 require.NoError(t, err)359 _, err = client.Execute("insert into vitess_test (intval, floatval, charval, binval) values (4, null, null, null)", nil)360 require.NoError(t, err)361 qr, err := client.Execute("select intval from vitess_test", nil)362 require.NoError(t, err)363 assert.Equal(t, "[[INT32(1)] [INT32(2)] [INT32(3)] [INT32(4)]]", fmt.Sprintf("%v", qr.Rows))364 err = client.Rollback()365 require.NoError(t, err)366 qr, err = client.Execute("select intval from vitess_test", nil)367 require.NoError(t, err)368 assert.Equal(t, "[[INT32(1)] [INT32(2)] [INT32(3)]]", fmt.Sprintf("%v", qr.Rows))369 qr2, err := client.Execute("select connection_id()", nil)370 require.NoError(t, err)371 require.Equal(t, qr1.Rows, qr2.Rows)372 require.NoError(t, client.Release())373}374func TestReserveAndBeginExecuteWithFailingQueryAndReserveConnAndTxRemainsOpen(t *testing.T) {375 client := framework.NewClient()376 // Save the connection id to check in the end that everything got executed on same connection.377 qr1, err := client.ReserveExecute("select connection_id()", nil, nil)378 require.NoError(t, err)379 _, err = client.BeginExecute("select foo", nil, nil)380 require.Error(t, err)381 _, err = client.Execute("insert into vitess_test (intval, floatval, charval, binval) values (4, null, null, null)", nil)382 require.NoError(t, err)383 qr, err := client.Execute("select intval from vitess_test", nil)384 require.NoError(t, err)385 assert.Equal(t, "[[INT32(1)] [INT32(2)] [INT32(3)] [INT32(4)]]", fmt.Sprintf("%v", qr.Rows))386 err = client.Rollback()387 require.NoError(t, err)388 qr, err = client.Execute("select intval from vitess_test", nil)389 require.NoError(t, err)390 assert.Equal(t, "[[INT32(1)] [INT32(2)] [INT32(3)]]", fmt.Sprintf("%v", qr.Rows))391 qr2, err := client.Execute("select connection_id()", nil)392 require.NoError(t, err)393 require.Equal(t, qr1.Rows, qr2.Rows)394 require.NoError(t, client.Release())395}396func TestReserveExecuteWithPreQueriesAndCheckConnectionState(t *testing.T) {397 client1 := framework.NewClient()398 client2 := framework.NewClient()399 selQuery := "select str_to_date('00/00/0000', '%m/%d/%Y')"400 warnQuery := "show warnings"401 preQueries1 := []string{402 "set sql_mode = ''",403 }404 preQueries2 := []string{405 "set sql_mode = 'NO_ZERO_DATE'",406 }407 qr1, err := client1.ReserveExecute(selQuery, preQueries1, nil)408 require.NoError(t, err)409 defer client1.Release()410 qr2, err := client2.ReserveExecute(selQuery, preQueries2, nil)411 require.NoError(t, err)412 defer client2.Release()413 assert.NotEqual(t, qr1.Rows, qr2.Rows)414 assert.Equal(t, `[[DATE("0000-00-00")]]`, fmt.Sprintf("%v", qr1.Rows))415 assert.Equal(t, `[[NULL]]`, fmt.Sprintf("%v", qr2.Rows))416 qr1, err = client1.Execute(warnQuery, nil)417 require.NoError(t, err)418 qr2, err = client2.Execute(warnQuery, nil)419 require.NoError(t, err)420 assert.NotEqual(t, qr1.Rows, qr2.Rows)421 assert.Equal(t, `[]`, fmt.Sprintf("%v", qr1.Rows))422 assert.Equal(t, `[[VARCHAR("Warning") UINT32(1411) VARCHAR("Incorrect datetime value: '00/00/0000' for function str_to_date")]]`, fmt.Sprintf("%v", qr2.Rows))423}424func TestReserveExecuteWithPreQueriesAndSavepoint(t *testing.T) {425 client := framework.NewClient()426 defer client.Release()427 insQuery := "insert into vitess_test (intval) values (5)"428 selQuery := "select intval from vitess_test where intval = 5"429 preQueries := []string{430 "set sql_mode = ''",431 }432 postBeginQueries1 := []string{433 "savepoint a",434 }435 // savepoint there after begin.436 _, err := client.ReserveBeginExecute(insQuery, preQueries, postBeginQueries1, nil)437 require.NoError(t, err)438 qr, err := client.Execute(selQuery, nil)439 require.NoError(t, err)440 assert.Equal(t, `[[INT32(5)]]`, fmt.Sprintf("%v", qr.Rows))441 _, err = client.Execute("rollback to a", nil)442 require.NoError(t, err)443 qr, err = client.Execute(selQuery, nil)444 require.NoError(t, err)445 assert.Equal(t, `[]`, fmt.Sprintf("%v", qr.Rows))446 err = client.Release()447 require.NoError(t, err)448 postBeginQueries2 := []string{449 "savepoint a",450 "release savepoint a",451 "savepoint b",452 }453 // no savepoint after begin454 _, err = client.ReserveBeginExecute(insQuery, preQueries, postBeginQueries2, nil)455 require.NoError(t, err)456 qr, err = client.Execute(selQuery, nil)457 require.NoError(t, err)458 assert.Equal(t, `[[INT32(5)]]`, fmt.Sprintf("%v", qr.Rows))459 // no savepoint a460 _, err = client.Execute("rollback to a", nil)461 require.Error(t, err)462 // no savepoint a.463 _, err = client.Execute("release a", nil)464 require.Error(t, err)465 // record still exists.466 qr, err = client.Execute(selQuery, nil)467 require.NoError(t, err)468 assert.Equal(t, `[[INT32(5)]]`, fmt.Sprintf("%v", qr.Rows))469 _, err = client.Execute("rollback to b", nil)470 require.NoError(t, err)471 qr, err = client.Execute(selQuery, nil)472 require.NoError(t, err)473 assert.Equal(t, `[]`, fmt.Sprintf("%v", qr.Rows))474}475func TestReserveBeginExecuteWithPreQueriesAndCheckConnectionState(t *testing.T) {476 rcClient := framework.NewClient()477 rucClient := framework.NewClient()478 insRcQuery := "insert into vitess_test (intval, floatval, charval, binval) values (4, null, null, null)"479 insRucQuery := "insert into vitess_test (intval, floatval, charval, binval) values (5, null, null, null)"480 selQuery := "select intval from vitess_test"481 delQuery := "delete from vitess_test where intval = 5"482 rcQuery := []string{483 "set session transaction isolation level read committed",484 }485 rucQuery := []string{486 "set session transaction isolation level read uncommitted",487 }488 _, err := rcClient.ReserveBeginExecute(insRcQuery, rcQuery, nil, nil)489 require.NoError(t, err)490 defer rcClient.Release()491 _, err = rucClient.ReserveBeginExecute(insRucQuery, rucQuery, nil, nil)492 require.NoError(t, err)493 defer rucClient.Release()494 qr1, err := rcClient.Execute(selQuery, nil)495 require.NoError(t, err)496 qr2, err := rucClient.Execute(selQuery, nil)497 require.NoError(t, err)498 assert.NotEqual(t, qr1.Rows, qr2.Rows)499 // As the transaction is read commited it is not able to see #5.500 assert.Equal(t, `[[INT32(1)] [INT32(2)] [INT32(3)] [INT32(4)]]`, fmt.Sprintf("%v", qr1.Rows))501 // As the transaction is read uncommited it is able to see #4.502 assert.Equal(t, `[[INT32(1)] [INT32(2)] [INT32(3)] [INT32(4)] [INT32(5)]]`, fmt.Sprintf("%v", qr2.Rows))503 err = rucClient.Commit()504 require.NoError(t, err)505 qr1, err = rcClient.Execute(selQuery, nil)506 require.NoError(t, err)507 qr2, err = rucClient.Execute(selQuery, nil)508 require.NoError(t, err)509 // As the transaction on read uncommitted client got committed, transaction with read committed will be able to see #5.510 assert.Equal(t, qr1.Rows, qr2.Rows)511 assert.Equal(t, `[[INT32(1)] [INT32(2)] [INT32(3)] [INT32(4)] [INT32(5)]]`, fmt.Sprintf("%v", qr1.Rows))512 err = rcClient.Rollback()513 require.NoError(t, err)514 qr1, err = rcClient.Execute(selQuery, nil)515 require.NoError(t, err)516 qr2, err = rucClient.Execute(selQuery, nil)517 require.NoError(t, err)518 // As the transaction on read committed client got rollbacked back, table will forget #4.519 assert.Equal(t, qr1.Rows, qr2.Rows)520 assert.Equal(t, `[[INT32(1)] [INT32(2)] [INT32(3)] [INT32(5)]]`, fmt.Sprintf("%v", qr2.Rows))521 // This is executed on reserved connection without transaction as the transaction was committed.522 _, err = rucClient.Execute(delQuery, nil)523 require.NoError(t, err)524}525func TestReserveExecuteWithFailingPreQueriesAndCheckConnectionState(t *testing.T) {526 client := framework.NewClient()527 selQuery := "select 42"528 preQueries := []string{529 "set @@no_sys_var = 42",530 }531 _, err := client.ReserveExecute(selQuery, preQueries, nil)532 require.Error(t, err)533 err = client.Release()534 require.Error(t, err)535}536func TestReserveBeginExecuteWithFailingPreQueriesAndCheckConnectionState(t *testing.T) {537 client := framework.NewClient()538 selQuery := "select 42"539 preQueries := []string{540 "set @@no_sys_var = 42",541 }542 _, err := client.ReserveBeginExecute(selQuery, preQueries, nil, nil)543 require.Error(t, err)544 err = client.Commit()545 require.Error(t, err)546 err = client.Release()547 require.Error(t, err)548}549func TestBeginReserveExecuteWithFailingPreQueriesAndCheckConnectionState(t *testing.T) {550 client := framework.NewClient()551 selQuery := "select 42"552 preQueries := []string{553 "set @@no_sys_var = 42",554 }555 _, err := client.BeginExecute(selQuery, nil, nil)556 require.NoError(t, err)557 _, err = client.ReserveExecute(selQuery, preQueries, nil)558 require.Error(t, err)559 err = client.Commit()560 require.Error(t, err)561 err = client.Release()562 require.Error(t, err)563}564func TestReserveBeginExecuteWithCommitFailureAndCheckConnectionAndDBState(t *testing.T) {565 client := framework.NewClient()566 connQuery := "select connection_id()"567 insQuery := "insert into vitess_test (intval, floatval, charval, binval) values (4, null, null, null)"568 selQuery := "select intval from vitess_test where intval = 4"569 connQr, err := client.ReserveBeginExecute(connQuery, nil, nil, nil)570 require.NoError(t, err)571 _, err = client.Execute(insQuery, nil)572 require.NoError(t, err)573 killConnection(t, connQr.Rows[0][0].ToString())574 err = client.Commit()575 require.Error(t, err)576 require.Zero(t, client.ReservedID())577 qr, err := client.Execute(selQuery, nil)578 require.NoError(t, err)579 require.Empty(t, qr.Rows)580 qr, err = client.Execute(connQuery, nil)581 require.NoError(t, err)582 require.NotEqual(t, connQr.Rows, qr.Rows)583 require.Error(t, client.Release())584}585func TestReserveBeginExecuteWithRollbackFailureAndCheckConnectionAndDBState(t *testing.T) {586 client := framework.NewClient()587 connQuery := "select connection_id()"588 insQuery := "insert into vitess_test (intval, floatval, charval, binval) values (4, null, null, null)"589 selQuery := "select intval from vitess_test where intval = 4"590 connQr, err := client.ReserveBeginExecute(connQuery, nil, nil, nil)591 require.NoError(t, err)592 _, err = client.Execute(insQuery, nil)593 require.NoError(t, err)594 killConnection(t, connQr.Rows[0][0].ToString())595 err = client.Rollback()596 require.Error(t, err)597 require.Zero(t, client.ReservedID())598 qr, err := client.Execute(selQuery, nil)599 require.NoError(t, err)600 require.Empty(t, qr.Rows)601 qr, err = client.Execute(connQuery, nil)602 require.NoError(t, err)603 require.NotEqual(t, connQr.Rows, qr.Rows)604 require.Error(t, client.Release())605}606func TestReserveExecuteWithExecuteFailureAndCheckConnectionAndDBState(t *testing.T) {607 client := framework.NewClient()608 connQuery := "select connection_id()"609 insQuery := "insert into vitess_test (intval, floatval, charval, binval) values (4, null, null, null)"610 selQuery := "select intval from vitess_test where intval = 4"611 connQr, err := client.ReserveExecute(connQuery, nil, nil)612 require.NoError(t, err)613 killConnection(t, connQr.Rows[0][0].ToString())614 _, err = client.Execute(insQuery, nil)615 require.Error(t, err)616 // Expectation - require.Zero(t, client.ReservedID())617 // Reality618 require.NotZero(t, client.ReservedID())619 // Client still has transaction id and client id as non-zero.620 _, err = client.Execute(selQuery, nil)621 require.Error(t, err)622 client.SetTransactionID(0)623 _, err = client.Execute(selQuery, nil)624 require.Error(t, err)625 client.SetReservedID(0)626 qr, err := client.Execute(selQuery, nil)627 require.NoError(t, err)628 require.Empty(t, qr.Rows)629 qr, err = client.Execute(connQuery, nil)630 require.NoError(t, err)631 require.NotEqual(t, connQr.Rows, qr.Rows)632 require.Error(t, client.Release())633}634func TestReserveExecuteDDLWithoutTx(t *testing.T) {635 client := framework.NewClient()636 defer client.Release()637 connQuery := "select connection_id()"638 createQuery := "create table vitess_test_ddl(id bigint primary key)"639 dropQuery := "drop table vitess_test_ddl"640 descQuery := "describe vitess_test_ddl"641 qr1, err := client.ReserveExecute(connQuery, nil, nil)642 require.NoError(t, err)643 _, err = client.Execute(createQuery, nil)644 require.NoError(t, err)645 require.Zero(t, client.TransactionID())646 defer client.Execute(dropQuery, nil)647 qr2, err := client.Execute(connQuery, nil)648 require.NoError(t, err)649 assert.Equal(t, qr1.Rows, qr2.Rows)650 qr3, err := client.Execute(descQuery, nil)651 require.NoError(t, err)652 require.NotZero(t, qr3.Rows)653}654func TestReserveExecuteDDLWithTx(t *testing.T) {655 client := framework.NewClient()656 defer client.Release()657 connQuery := "select connection_id()"658 createQuery := "create table vitess_test_ddl(id bigint primary key)"659 dropQuery := "drop table vitess_test_ddl"660 descQuery := "describe vitess_test_ddl"661 qr1, err := client.ReserveBeginExecute(connQuery, nil, nil, nil)662 require.NoError(t, err)663 _, err = client.Execute(createQuery, nil)664 require.NoError(t, err)665 require.NotZero(t, client.TransactionID())666 defer client.Execute(dropQuery, nil)667 qr2, err := client.Execute(connQuery, nil)668 require.NoError(t, err)669 assert.Equal(t, qr1.Rows, qr2.Rows)670 qr3, err := client.Execute(descQuery, nil)671 require.NoError(t, err)672 require.NotZero(t, qr3.Rows)673}674func killConnection(t *testing.T, connID string) {675 client := framework.NewClient()676 _, err := client.ReserveExecute("select 1", []string{fmt.Sprintf("kill %s", connID)}, nil)677 require.NoError(t, err)678 defer client.Release()679}...

Full Screen

Full Screen

commands_test.go

Source:commands_test.go Github

copy

Full Screen

...12 defer th.TearDown()13 Client := th.Client14 channel1 := th.BasicChannel15 echoTestString := "/echo test"16 if r1 := Client.Must(Client.ExecuteCommand(channel1.Id, echoTestString)).(*model.CommandResponse); r1 == nil {17 t.Fatal("Echo command failed to execute")18 }19 if r1 := Client.Must(Client.ExecuteCommand(channel1.Id, "/echo ")).(*model.CommandResponse); r1 == nil {20 t.Fatal("Echo command failed to execute")21 }22 time.Sleep(100 * time.Millisecond)23 p1 := Client.Must(Client.GetPostsForChannel(channel1.Id, 0, 2, "")).(*model.PostList)24 if len(p1.Order) != 2 {25 t.Fatal("Echo command failed to send")26 }27}28func TestGroupmsgCommands(t *testing.T) {29 th := Setup().InitBasic()30 defer th.TearDown()31 Client := th.Client32 team := th.BasicTeam33 user1 := th.BasicUser34 user2 := th.BasicUser235 user3 := th.CreateUser()36 user4 := th.CreateUser()37 user5 := th.CreateUser()38 user6 := th.CreateUser()39 user7 := th.CreateUser()40 user8 := th.CreateUser()41 user9 := th.CreateUser()42 th.LinkUserToTeam(user3, team)43 th.LinkUserToTeam(user4, team)44 rs1 := Client.Must(Client.ExecuteCommand(th.BasicChannel.Id, "/groupmsg "+user2.Username+","+user3.Username)).(*model.CommandResponse)45 group1 := model.GetGroupNameFromUserIds([]string{user1.Id, user2.Id, user3.Id})46 if !strings.HasSuffix(rs1.GotoLocation, "/"+team.Name+"/channels/"+group1) {47 t.Fatal("failed to create group channel")48 }49 rs2 := Client.Must(Client.ExecuteCommand(th.BasicChannel.Id, "/groupmsg "+user3.Username+","+user4.Username+" foobar")).(*model.CommandResponse)50 group2 := model.GetGroupNameFromUserIds([]string{user1.Id, user3.Id, user4.Id})51 if !strings.HasSuffix(rs2.GotoLocation, "/"+team.Name+"/channels/"+group2) {52 t.Fatal("failed to create second direct channel")53 }54 if result := Client.Must(Client.SearchPosts(team.Id, "foobar", false)).(*model.PostList); len(result.Order) == 0 {55 t.Fatal("post did not get sent to direct message")56 }57 rs3 := Client.Must(Client.ExecuteCommand(th.BasicChannel.Id, "/groupmsg "+user2.Username+","+user3.Username)).(*model.CommandResponse)58 if !strings.HasSuffix(rs3.GotoLocation, "/"+team.Name+"/channels/"+group1) {59 t.Fatal("failed to go back to existing group channel")60 }61 Client.Must(Client.ExecuteCommand(th.BasicChannel.Id, "/groupmsg "+user2.Username+" foobar"))62 Client.Must(Client.ExecuteCommand(th.BasicChannel.Id, "/groupmsg "+user2.Username+","+user3.Username+","+user4.Username+","+user5.Username+","+user6.Username+","+user7.Username+","+user8.Username+","+user9.Username+" foobar"))63 Client.Must(Client.ExecuteCommand(th.BasicChannel.Id, "/groupmsg junk foobar"))64 Client.Must(Client.ExecuteCommand(th.BasicChannel.Id, "/groupmsg junk,junk2 foobar"))65}66func TestInvitePeopleCommand(t *testing.T) {67 th := Setup().InitBasic()68 defer th.TearDown()69 Client := th.Client70 channel := th.BasicChannel71 r1 := Client.Must(Client.ExecuteCommand(channel.Id, "/invite_people test@example.com")).(*model.CommandResponse)72 if r1 == nil {73 t.Fatal("Command failed to execute")74 }75 r2 := Client.Must(Client.ExecuteCommand(channel.Id, "/invite_people test1@example.com test2@example.com")).(*model.CommandResponse)76 if r2 == nil {77 t.Fatal("Command failed to execute")78 }79 r3 := Client.Must(Client.ExecuteCommand(channel.Id, "/invite_people")).(*model.CommandResponse)80 if r3 == nil {81 t.Fatal("Command failed to execute")82 }83}84// also used to test /open (see command_open_test.go)85func testJoinCommands(t *testing.T, alias string) {86 th := Setup().InitBasic()87 defer th.TearDown()88 Client := th.Client89 team := th.BasicTeam90 user2 := th.BasicUser291 channel0 := &model.Channel{DisplayName: "00", Name: "00" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}92 channel0 = Client.Must(Client.CreateChannel(channel0)).(*model.Channel)93 channel1 := &model.Channel{DisplayName: "AA", Name: "aa" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}94 channel1 = Client.Must(Client.CreateChannel(channel1)).(*model.Channel)95 Client.Must(Client.RemoveUserFromChannel(channel1.Id, th.BasicUser.Id))96 channel2 := &model.Channel{DisplayName: "BB", Name: "bb" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}97 channel2 = Client.Must(Client.CreateChannel(channel2)).(*model.Channel)98 Client.Must(Client.RemoveUserFromChannel(channel2.Id, th.BasicUser.Id))99 channel3 := Client.Must(Client.CreateDirectChannel(th.BasicUser.Id, user2.Id)).(*model.Channel)100 rs5 := Client.Must(Client.ExecuteCommand(channel0.Id, "/"+alias+" "+channel2.Name)).(*model.CommandResponse)101 if !strings.HasSuffix(rs5.GotoLocation, "/"+team.Name+"/channels/"+channel2.Name) {102 t.Fatal("failed to join channel")103 }104 rs6 := Client.Must(Client.ExecuteCommand(channel0.Id, "/"+alias+" "+channel3.Name)).(*model.CommandResponse)105 if strings.HasSuffix(rs6.GotoLocation, "/"+team.Name+"/channels/"+channel3.Name) {106 t.Fatal("should not have joined direct message channel")107 }108 c1 := Client.Must(Client.GetChannelsForTeamForUser(th.BasicTeam.Id, th.BasicUser.Id, "")).([]*model.Channel)109 found := false110 for _, c := range c1 {111 if c.Id == channel2.Id {112 found = true113 }114 }115 if !found {116 t.Fatal("did not join channel")117 }118}119func TestJoinCommands(t *testing.T) {120 testJoinCommands(t, "join")121}122func TestLoadTestHelpCommands(t *testing.T) {123 th := Setup().InitBasic()124 defer th.TearDown()125 Client := th.Client126 channel := th.BasicChannel127 enableTesting := *th.App.Config().ServiceSettings.EnableTesting128 defer func() {129 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableTesting = enableTesting })130 }()131 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableTesting = true })132 rs := Client.Must(Client.ExecuteCommand(channel.Id, "/test help")).(*model.CommandResponse)133 if !strings.Contains(rs.Text, "Mattermost testing commands to help") {134 t.Fatal(rs.Text)135 }136 time.Sleep(2 * time.Second)137}138func TestLoadTestSetupCommands(t *testing.T) {139 th := Setup().InitBasic()140 defer th.TearDown()141 Client := th.Client142 channel := th.BasicChannel143 enableTesting := *th.App.Config().ServiceSettings.EnableTesting144 defer func() {145 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableTesting = enableTesting })146 }()147 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableTesting = true })148 rs := Client.Must(Client.ExecuteCommand(channel.Id, "/test setup fuzz 1 1 1")).(*model.CommandResponse)149 if rs.Text != "Created environment" {150 t.Fatal(rs.Text)151 }152 time.Sleep(2 * time.Second)153}154func TestLoadTestUsersCommands(t *testing.T) {155 th := Setup().InitBasic()156 defer th.TearDown()157 Client := th.Client158 channel := th.BasicChannel159 enableTesting := *th.App.Config().ServiceSettings.EnableTesting160 defer func() {161 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableTesting = enableTesting })162 }()163 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableTesting = true })164 rs := Client.Must(Client.ExecuteCommand(channel.Id, "/test users fuzz 1 2")).(*model.CommandResponse)165 if rs.Text != "Added users" {166 t.Fatal(rs.Text)167 }168 time.Sleep(2 * time.Second)169}170func TestLoadTestChannelsCommands(t *testing.T) {171 th := Setup().InitBasic()172 defer th.TearDown()173 Client := th.Client174 channel := th.BasicChannel175 enableTesting := *th.App.Config().ServiceSettings.EnableTesting176 defer func() {177 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableTesting = enableTesting })178 }()179 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableTesting = true })180 rs := Client.Must(Client.ExecuteCommand(channel.Id, "/test channels fuzz 1 2")).(*model.CommandResponse)181 if rs.Text != "Added channels" {182 t.Fatal(rs.Text)183 }184 time.Sleep(2 * time.Second)185}186func TestLoadTestPostsCommands(t *testing.T) {187 th := Setup().InitBasic()188 defer th.TearDown()189 Client := th.Client190 channel := th.BasicChannel191 enableTesting := *th.App.Config().ServiceSettings.EnableTesting192 defer func() {193 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableTesting = enableTesting })194 }()195 th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableTesting = true })196 rs := Client.Must(Client.ExecuteCommand(channel.Id, "/test posts fuzz 2 3 2")).(*model.CommandResponse)197 if rs.Text != "Added posts" {198 t.Fatal(rs.Text)199 }200 time.Sleep(2 * time.Second)201}202func TestLeaveCommands(t *testing.T) {203 th := Setup().InitBasic()204 defer th.TearDown()205 Client := th.Client206 team := th.BasicTeam207 user2 := th.BasicUser2208 channel1 := &model.Channel{DisplayName: "AA", Name: "aa" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}209 channel1 = Client.Must(Client.CreateChannel(channel1)).(*model.Channel)210 Client.Must(Client.AddChannelMember(channel1.Id, th.BasicUser.Id))211 channel2 := &model.Channel{DisplayName: "BB", Name: "bb" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}212 channel2 = Client.Must(Client.CreateChannel(channel2)).(*model.Channel)213 Client.Must(Client.AddChannelMember(channel2.Id, th.BasicUser.Id))214 Client.Must(Client.AddChannelMember(channel2.Id, user2.Id))215 channel3 := Client.Must(Client.CreateDirectChannel(th.BasicUser.Id, user2.Id)).(*model.Channel)216 rs1 := Client.Must(Client.ExecuteCommand(channel1.Id, "/leave")).(*model.CommandResponse)217 if !strings.HasSuffix(rs1.GotoLocation, "/"+team.Name+"/channels/"+model.DEFAULT_CHANNEL) {218 t.Fatal("failed to leave open channel 1")219 }220 rs2 := Client.Must(Client.ExecuteCommand(channel2.Id, "/leave")).(*model.CommandResponse)221 if !strings.HasSuffix(rs2.GotoLocation, "/"+team.Name+"/channels/"+model.DEFAULT_CHANNEL) {222 t.Fatal("failed to leave private channel 1")223 }224 _, err := Client.ExecuteCommand(channel3.Id, "/leave")225 if err == nil {226 t.Fatal("should fail leaving direct channel")227 }228 cdata := Client.Must(Client.GetChannelsForTeamForUser(th.BasicTeam.Id, th.BasicUser.Id, "")).([]*model.Channel)229 found := false230 for _, c := range cdata {231 if c.Id == channel1.Id || c.Id == channel2.Id {232 found = true233 }234 }235 if found {236 t.Fatal("did not leave right channels")237 }238 for _, c := range cdata {239 if c.Name == model.DEFAULT_CHANNEL {240 if _, err := Client.RemoveUserFromChannel(c.Id, th.BasicUser.Id); err == nil {241 t.Fatal("should have errored on leaving default channel")242 }243 break244 }245 }246}247func TestLogoutTestCommand(t *testing.T) {248 th := Setup().InitBasic()249 defer th.TearDown()250 th.Client.Must(th.Client.ExecuteCommand(th.BasicChannel.Id, "/logout"))251}252func TestMeCommand(t *testing.T) {253 th := Setup().InitBasic()254 defer th.TearDown()255 Client := th.Client256 channel := th.BasicChannel257 testString := "/me hello"258 r1 := Client.Must(Client.ExecuteCommand(channel.Id, testString)).(*model.CommandResponse)259 if r1 == nil {260 t.Fatal("Command failed to execute")261 }262 time.Sleep(100 * time.Millisecond)263 p1 := Client.Must(Client.GetPostsForChannel(channel.Id, 0, 2, "")).(*model.PostList)264 if len(p1.Order) != 2 {265 t.Fatal("Command failed to send")266 } else {267 pt := p1.Posts[p1.Order[0]].Type268 if pt != model.POST_ME {269 t.Log(pt)270 t.Fatalf("invalid post type, got '%s', wanted '%s'", pt, model.POST_ME)271 }272 msg := p1.Posts[p1.Order[0]].Message273 want := "*hello*"274 if msg != want {275 t.Log(msg)276 t.Fatalf("invalid me response message, got '%s', wanted '%s'", msg, want)277 }278 }279}280func TestMsgCommands(t *testing.T) {281 th := Setup().InitBasic()282 defer th.TearDown()283 Client := th.Client284 team := th.BasicTeam285 user1 := th.BasicUser286 user2 := th.BasicUser2287 user3 := th.CreateUser()288 th.LinkUserToTeam(user3, team)289 Client.Must(Client.CreateDirectChannel(th.BasicUser.Id, user2.Id))290 Client.Must(Client.CreateDirectChannel(th.BasicUser.Id, user3.Id))291 rs1 := Client.Must(Client.ExecuteCommand(th.BasicChannel.Id, "/msg "+user2.Username)).(*model.CommandResponse)292 if !strings.HasSuffix(rs1.GotoLocation, "/"+team.Name+"/channels/"+user1.Id+"__"+user2.Id) && !strings.HasSuffix(rs1.GotoLocation, "/"+team.Name+"/channels/"+user2.Id+"__"+user1.Id) {293 t.Fatal("failed to create direct channel")294 }295 rs2 := Client.Must(Client.ExecuteCommand(th.BasicChannel.Id, "/msg "+user3.Username+" foobar")).(*model.CommandResponse)296 if !strings.HasSuffix(rs2.GotoLocation, "/"+team.Name+"/channels/"+user1.Id+"__"+user3.Id) && !strings.HasSuffix(rs2.GotoLocation, "/"+team.Name+"/channels/"+user3.Id+"__"+user1.Id) {297 t.Fatal("failed to create second direct channel")298 }299 if result := Client.Must(Client.SearchPosts(th.BasicTeam.Id, "foobar", false)).(*model.PostList); len(result.Order) == 0 {300 t.Fatalf("post did not get sent to direct message")301 }302 rs3 := Client.Must(Client.ExecuteCommand(th.BasicChannel.Id, "/msg "+user2.Username)).(*model.CommandResponse)303 if !strings.HasSuffix(rs3.GotoLocation, "/"+team.Name+"/channels/"+user1.Id+"__"+user2.Id) && !strings.HasSuffix(rs3.GotoLocation, "/"+team.Name+"/channels/"+user2.Id+"__"+user1.Id) {304 t.Fatal("failed to go back to existing direct channel")305 }306 Client.Must(Client.ExecuteCommand(th.BasicChannel.Id, "/msg "+th.BasicUser.Username+" foobar"))307 Client.Must(Client.ExecuteCommand(th.BasicChannel.Id, "/msg junk foobar"))308}309func TestOpenCommands(t *testing.T) {310 testJoinCommands(t, "open")311}312func TestSearchCommand(t *testing.T) {313 th := Setup().InitBasic()314 defer th.TearDown()315 th.Client.Must(th.Client.ExecuteCommand(th.BasicChannel.Id, "/search"))316}317func TestSettingsCommand(t *testing.T) {318 th := Setup().InitBasic()319 defer th.TearDown()320 th.Client.Must(th.Client.ExecuteCommand(th.BasicChannel.Id, "/settings"))321}322func TestShortcutsCommand(t *testing.T) {323 th := Setup().InitBasic()324 defer th.TearDown()325 th.Client.Must(th.Client.ExecuteCommand(th.BasicChannel.Id, "/shortcuts"))326}327func TestShrugCommand(t *testing.T) {328 th := Setup().InitBasic()329 defer th.TearDown()330 Client := th.Client331 channel := th.BasicChannel332 testString := "/shrug"333 r1 := Client.Must(Client.ExecuteCommand(channel.Id, testString)).(*model.CommandResponse)334 if r1 == nil {335 t.Fatal("Command failed to execute")336 }337 time.Sleep(100 * time.Millisecond)338 p1 := Client.Must(Client.GetPostsForChannel(channel.Id, 0, 2, "")).(*model.PostList)339 if len(p1.Order) != 2 {340 t.Fatal("Command failed to send")341 } else {342 if p1.Posts[p1.Order[0]].Message != `¯\\\_(ツ)\_/¯` {343 t.Log(p1.Posts[p1.Order[0]].Message)344 t.Fatal("invalid shrug response")345 }346 }347}348func TestStatusCommands(t *testing.T) {349 th := Setup().InitBasic()350 defer th.TearDown()351 commandAndTest(t, th, "away")352 commandAndTest(t, th, "offline")353 commandAndTest(t, th, "online")354}355func commandAndTest(t *testing.T, th *TestHelper, status string) {356 Client := th.Client357 channel := th.BasicChannel358 user := th.BasicUser359 r1 := Client.Must(Client.ExecuteCommand(channel.Id, "/"+status)).(*model.CommandResponse)360 if r1 == nil {361 t.Fatal("Command failed to execute")362 }363 time.Sleep(1000 * time.Millisecond)364 rstatus := Client.Must(Client.GetUserStatus(user.Id, "")).(*model.Status)365 if rstatus.Status != status {366 t.Fatal("Error setting status " + status)367 }368}...

Full Screen

Full Screen

submitrequest_test.go

Source:submitrequest_test.go Github

copy

Full Screen

...20 mockClient := &client{mockSnapshotClient, mockSigner, buffer}21 resetFlags()22 cmd := submitRequestCmd(mockClient, nil)23 cmd.SetArgs([]string{"-c", "mychannel"})24 require.NoError(t, cmd.Execute())25 require.Equal(t, []byte("Snapshot request submitted successfully\n"), buffer.Contents())26 // use a new buffer to verify new command execution27 buffer2 := gbytes.NewBuffer()28 mockClient.writer = buffer229 resetFlags()30 cmd = submitRequestCmd(mockClient, nil)31 cmd.SetArgs([]string{"-c", "mychannel", "-b", "100"})32 require.NoError(t, cmd.Execute())33 require.Equal(t, []byte("Snapshot request submitted successfully\n"), buffer2.Contents())34 // error tests35 mockSnapshotClient.GenerateReturns(nil, fmt.Errorf("fake-generate-error"))36 require.EqualError(t, cmd.Execute(), "failed to submit the request: fake-generate-error")37 mockSigner.SignReturns(nil, fmt.Errorf("fake-sign-error"))38 require.EqualError(t, cmd.Execute(), "fake-sign-error")39 mockSigner.SerializeReturns(nil, fmt.Errorf("fake-serialize-error"))40 require.EqualError(t, cmd.Execute(), "fake-serialize-error")41 resetFlags()42 cmd.SetArgs([]string{})43 require.EqualError(t, cmd.Execute(), "the required parameter 'channelID' is empty. Rerun the command with -c flag")44}...

Full Screen

Full Screen

Execute

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 client := &http.Client{}4 req.Header.Add("Accept", "application/json")5 resp, _ := client.Do(req)6 defer resp.Body.Close()7 body, _ := ioutil.ReadAll(resp.Body)8 fmt.Println(string(body))9}10{"message":"Hello World"}11import (12func main() {13 defer resp.Body.Close()14 body, _ := ioutil.ReadAll(resp.Body)15 fmt.Println(string(body))16}17{"message":"Hello World"}18import (

Full Screen

Full Screen

Execute

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 conn, err := grpc.Dial("localhost:50051", grpc.WithInsecure())4 if err != nil {5 log.Fatalf("Could not connect %v", err)6 }7 defer conn.Close()8 c := protos.NewCalculatorServiceClient(conn)9 doUnary(c)10}11func doUnary(c protos.CalculatorServiceClient) {12 fmt.Println("Starting to do a Unary RPC...")13 req := &protos.SumRequest{14 }15 res, err := c.Sum(context.Background(), req)16 if err != nil {17 log.Fatalf("error while calling Sum RPC: %v", err)18 }19 log.Printf("Response from Sum: %v", res.SumResult)20}21import (22type server struct{}23func (*server) PrimeNumberDecomposition(req *protos.PrimeNumberDecompositionRequest, stream protos.CalculatorService_PrimeNumberDecompositionServer) error {24 fmt.Printf("PrimeNumberDecomposition function was invoked with %v25 number := req.GetNumber()26 divisor := int64(2)27 for number > 1 {28 if number%divisor == 0 {29 stream.Send(&protos.PrimeNumberDecompositionResponse{30 })31 } else {32 fmt.Printf("Divisor has increased to %v33 }34 }35}36func main() {37 fmt.Println("Calculator Server")

Full Screen

Full Screen

Execute

Using AI Code Generation

copy

Full Screen

1client := clientClass{}2client.Execute()3client := clientClass{}4client.Execute()5client := clientClass{}6client.Execute()7client := clientClass{}8client.Execute()9client := clientClass{}10client.Execute()11client := clientClass{}12client.Execute()13client := clientClass{}14client.Execute()15client := clientClass{}16client.Execute()17client := clientClass{}18client.Execute()19client := clientClass{}20client.Execute()21client := clientClass{}22client.Execute()23client := clientClass{}24client.Execute()25client := clientClass{}26client.Execute()

Full Screen

Full Screen

Execute

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 cb := gobreaker.NewCircuitBreaker(gobreaker.Settings{4 })5 client := &client{cb: cb}6 _, err := client.Do(context.Background())7 if err != nil {8 log.Fatal(err)9 }10}11type client struct {12}13func (c *client) Do(ctx context.Context) (string, error) {14 _, err := c.cb.Execute(func() (interface{}, error) {15 })16 if err != nil {17 }18}19import (20func main() {21 cb := gobreaker.NewCircuitBreaker(gobreaker.Settings{22 })23 client := &client{cb: cb}24 _, err := client.Do(context.Background())25 if err != nil {26 log.Fatal(err)27 }28}29type client struct {30}31func (c *client) Do(ctx context.Context) (string, error) {32 _, err := c.cb.Execute(func() (interface{}, error) {33 })

Full Screen

Full Screen

Execute

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 client := client.NewClient()4 fmt.Println(client.Execute(2, 3))5}6import (7func main() {8 client := client.NewClient()9 fmt.Println(client.Execute(2, 3))10}11import (12func main() {13 client := client.NewClient()14 fmt.Println(client.Execute(2, 3))15}16import (17func main() {18 client := client.NewClient()19 fmt.Println(client.Execute(2, 3))20}21import (22func main() {23 client := client.NewClient()24 fmt.Println(client.Execute(2, 3))25}26import (27func main() {28 client := client.NewClient()29 fmt.Println(client.Execute(2, 3))30}31import (32func main() {33 client := client.NewClient()34 fmt.Println(client.Execute(2, 3))35}36import (37func main() {38 client := client.NewClient()39 fmt.Println(client.Execute(2, 3))40}

Full Screen

Full Screen

Execute

Using AI Code Generation

copy

Full Screen

1import (2const (3func main() {4 conn, err := grpc.Dial(address, grpc.WithInsecure())5 if err != nil {6 log.Fatalf("did not connect: %v", err)7 }8 defer conn.Close()9 c := pb.NewCalculatorClient(conn)10 ctx, cancel := context.WithTimeout(context.Background(), 10000000)11 defer cancel()12 r, err := c.Execute(ctx, &pb.Request{A: 3, B: 5})13 if err != nil {14 log.Fatalf("could not greet: %v", err)15 }16 fmt.Println(r.Result)17}18import (19const (20type server struct{}21func (s *server) Execute(ctx context.Context, in *pb.Request) (*pb.Response, error) {22 return &pb.Response{Result: in.A + in.B}, nil23}24func main() {25 lis, err := net.Listen("tcp", port)26 if err != nil {27 log.Fatalf("failed to listen: %v", err)28 }29 s := grpc.NewServer()30 pb.RegisterCalculatorServer(s, &server{})31 if err := s.Serve(lis); err != nil {32 log.Fatalf("failed to serve: %v", err)33 }34}35syntax = "proto3";36package calculator;37service Calculator {38 rpc Execute (Request) returns (Response);39}40message Request {41 int32 A = 1;42 int32 B = 2;43}44message Response {45 int32 Result = 1;46}

Full Screen

Full Screen

Execute

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 receiver := &command.Receiver{}4 cmd := &command.Command{Receiver: receiver}5 invoker := &command.Invoker{Command: cmd}6 invoker.ExecuteCommand()7 fmt.Println("After executing the command")8 invoker.UndoCommand()9}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testkube automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful