How to use Run method of sql Package

Best Venom code snippet using sql.Run

orm_test.go

Source:orm_test.go Github

copy

Full Screen

...889 },890 },891 }892 for _, test := range tests {893 t.Run(test.name, func(t *testing.T) {894 runOrmTest(t, func(db *sql.DB, mock sqlmock.Sqlmock) {895 rs := sqlmock.NewRows([]string{"age"}).FromCSVString("5")896 mock.ExpectQuery("select (.+) from users where user=?").WithArgs(897 "anyone").WillReturnRows(rs)898 var r struct {899 User string `db:"user"`900 Age int `db:"age"`901 }902 test.validate(query(db, func(rows *sql.Rows) error {903 scanner := mockedScanner{904 colErr: test.colErr,905 scanErr: test.scanErr,906 err: test.err,907 }...

Full Screen

Full Screen

macros_test.go

Source:macros_test.go Github

copy

Full Screen

...12 engine := newPostgresMacroEngine(timescaledbEnabled)13 timescaledbEnabled = true14 engineTS := newPostgresMacroEngine(timescaledbEnabled)15 query := &backend.DataQuery{}16 t.Run("Given a time range between 2018-04-12 00:00 and 2018-04-12 00:05", func(t *testing.T) {17 from := time.Date(2018, 4, 12, 18, 0, 0, 0, time.UTC)18 to := from.Add(5 * time.Minute)19 timeRange := backend.TimeRange{From: from, To: to}20 t.Run("interpolate __time function", func(t *testing.T) {21 sql, err := engine.Interpolate(query, timeRange, "select $__time(time_column)")22 require.NoError(t, err)23 require.Equal(t, "select time_column AS \"time\"", sql)24 })25 t.Run("interpolate __time function wrapped in aggregation", func(t *testing.T) {26 sql, err := engine.Interpolate(query, timeRange, "select min($__time(time_column))")27 require.NoError(t, err)28 require.Equal(t, "select min(time_column AS \"time\")", sql)29 })30 t.Run("interpolate __timeFilter function", func(t *testing.T) {31 sql, err := engine.Interpolate(query, timeRange, "WHERE $__timeFilter(time_column)")32 require.NoError(t, err)33 require.Equal(t, fmt.Sprintf("WHERE time_column BETWEEN '%s' AND '%s'", from.Format(time.RFC3339Nano), to.Format(time.RFC3339Nano)), sql)34 })35 t.Run("interpolate __timeFrom function", func(t *testing.T) {36 sql, err := engine.Interpolate(query, timeRange, "select $__timeFrom()")37 require.NoError(t, err)38 require.Equal(t, "select '2018-04-12T18:00:00Z'", sql)39 })40 t.Run("interpolate __timeTo function", func(t *testing.T) {41 sql, err := engine.Interpolate(query, timeRange, "select $__timeTo()")42 require.NoError(t, err)43 require.Equal(t, "select '2018-04-12T18:05:00Z'", sql)44 })45 t.Run("interpolate __timeGroup function pre 5.3 compatibility", func(t *testing.T) {46 sql, err := engine.Interpolate(query, timeRange, "SELECT $__timeGroup(time_column,'5m'), value")47 require.NoError(t, err)48 require.Equal(t, "SELECT floor(extract(epoch from time_column)/300)*300 AS \"time\", value", sql)49 sql, err = engine.Interpolate(query, timeRange, "SELECT $__timeGroup(time_column,'5m') as time, value")50 require.NoError(t, err)51 require.Equal(t, "SELECT floor(extract(epoch from time_column)/300)*300 as time, value", sql)52 })53 t.Run("interpolate __timeGroup function", func(t *testing.T) {54 sql, err := engine.Interpolate(query, timeRange, "SELECT $__timeGroup(time_column,'5m')")55 require.NoError(t, err)56 sql2, err := engine.Interpolate(query, timeRange, "SELECT $__timeGroupAlias(time_column,'5m')")57 require.NoError(t, err)58 require.Equal(t, "SELECT floor(extract(epoch from time_column)/300)*300", sql)59 require.Equal(t, sql2, sql+" AS \"time\"")60 })61 t.Run("interpolate __timeGroup function with spaces between args", func(t *testing.T) {62 sql, err := engine.Interpolate(query, timeRange, "$__timeGroup(time_column , '5m')")63 require.NoError(t, err)64 sql2, err := engine.Interpolate(query, timeRange, "$__timeGroupAlias(time_column , '5m')")65 require.NoError(t, err)66 require.Equal(t, "floor(extract(epoch from time_column)/300)*300", sql)67 require.Equal(t, sql2, sql+" AS \"time\"")68 })69 t.Run("interpolate __timeGroup function with TimescaleDB enabled", func(t *testing.T) {70 sql, err := engineTS.Interpolate(query, timeRange, "GROUP BY $__timeGroup(time_column,'5m')")71 require.NoError(t, err)72 require.Equal(t, "GROUP BY time_bucket('300.000s',time_column)", sql)73 })74 t.Run("interpolate __timeGroup function with spaces between args and TimescaleDB enabled", func(t *testing.T) {75 sql, err := engineTS.Interpolate(query, timeRange, "GROUP BY $__timeGroup(time_column , '5m')")76 require.NoError(t, err)77 require.Equal(t, "GROUP BY time_bucket('300.000s',time_column)", sql)78 })79 t.Run("interpolate __timeGroup function with large time range as an argument and TimescaleDB enabled", func(t *testing.T) {80 sql, err := engineTS.Interpolate(query, timeRange, "GROUP BY $__timeGroup(time_column , '12d')")81 require.NoError(t, err)82 require.Equal(t, "GROUP BY time_bucket('1036800.000s',time_column)", sql)83 })84 t.Run("interpolate __timeGroup function with small time range as an argument and TimescaleDB enabled", func(t *testing.T) {85 sql, err := engineTS.Interpolate(query, timeRange, "GROUP BY $__timeGroup(time_column , '20ms')")86 require.NoError(t, err)87 require.Equal(t, "GROUP BY time_bucket('0.020s',time_column)", sql)88 })89 t.Run("interpolate __unixEpochFilter function", func(t *testing.T) {90 sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochFilter(time)")91 require.NoError(t, err)92 require.Equal(t, fmt.Sprintf("select time >= %d AND time <= %d", from.Unix(), to.Unix()), sql)93 })94 t.Run("interpolate __unixEpochNanoFilter function", func(t *testing.T) {95 sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochNanoFilter(time)")96 require.NoError(t, err)97 require.Equal(t, fmt.Sprintf("select time >= %d AND time <= %d", from.UnixNano(), to.UnixNano()), sql)98 })99 t.Run("interpolate __unixEpochNanoFrom function", func(t *testing.T) {100 sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochNanoFrom()")101 require.NoError(t, err)102 require.Equal(t, fmt.Sprintf("select %d", from.UnixNano()), sql)103 })104 t.Run("interpolate __unixEpochNanoTo function", func(t *testing.T) {105 sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochNanoTo()")106 require.NoError(t, err)107 require.Equal(t, fmt.Sprintf("select %d", to.UnixNano()), sql)108 })109 t.Run("interpolate __unixEpochGroup function", func(t *testing.T) {110 sql, err := engine.Interpolate(query, timeRange, "SELECT $__unixEpochGroup(time_column,'5m')")111 require.NoError(t, err)112 sql2, err := engine.Interpolate(query, timeRange, "SELECT $__unixEpochGroupAlias(time_column,'5m')")113 require.NoError(t, err)114 require.Equal(t, "SELECT floor(time_column/300)*300", sql)115 require.Equal(t, sql2, sql+" AS \"time\"")116 })117 })118 t.Run("Given a time range between 1960-02-01 07:00 and 1965-02-03 08:00", func(t *testing.T) {119 from := time.Date(1960, 2, 1, 7, 0, 0, 0, time.UTC)120 to := time.Date(1965, 2, 3, 8, 0, 0, 0, time.UTC)121 timeRange := backend.TimeRange{122 From: from,123 To: to,124 }125 t.Run("interpolate __timeFilter function", func(t *testing.T) {126 sql, err := engine.Interpolate(query, timeRange, "WHERE $__timeFilter(time_column)")127 require.NoError(t, err)128 require.Equal(t, fmt.Sprintf("WHERE time_column BETWEEN '%s' AND '%s'", from.Format(time.RFC3339Nano), to.Format(time.RFC3339Nano)), sql)129 })130 t.Run("interpolate __unixEpochFilter function", func(t *testing.T) {131 sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochFilter(time)")132 require.NoError(t, err)133 require.Equal(t, fmt.Sprintf("select time >= %d AND time <= %d", from.Unix(), to.Unix()), sql)134 })135 t.Run("interpolate __unixEpochNanoFilter function", func(t *testing.T) {136 sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochNanoFilter(time)")137 require.NoError(t, err)138 require.Equal(t, fmt.Sprintf("select time >= %d AND time <= %d", from.UnixNano(), to.UnixNano()), sql)139 })140 })141 t.Run("Given a time range between 1960-02-01 07:00 and 1980-02-03 08:00", func(t *testing.T) {142 from := time.Date(1960, 2, 1, 7, 0, 0, 0, time.UTC)143 to := time.Date(1980, 2, 3, 8, 0, 0, 0, time.UTC)144 timeRange := backend.TimeRange{145 From: from,146 To: to,147 }148 t.Run("interpolate __timeFilter function", func(t *testing.T) {149 sql, err := engine.Interpolate(query, timeRange, "WHERE $__timeFilter(time_column)")150 require.NoError(t, err)151 require.Equal(t, fmt.Sprintf("WHERE time_column BETWEEN '%s' AND '%s'", from.Format(time.RFC3339Nano), to.Format(time.RFC3339Nano)), sql)152 })153 t.Run("interpolate __unixEpochFilter function", func(t *testing.T) {154 sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochFilter(time)")155 require.NoError(t, err)156 require.Equal(t, fmt.Sprintf("select time >= %d AND time <= %d", from.Unix(), to.Unix()), sql)157 })158 t.Run("interpolate __unixEpochNanoFilter function", func(t *testing.T) {159 sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochNanoFilter(time)")160 require.NoError(t, err)161 require.Equal(t, fmt.Sprintf("select time >= %d AND time <= %d", from.UnixNano(), to.UnixNano()), sql)162 })163 })164 t.Run("Given a time range between 1960-02-01 07:00:00.5 and 1980-02-03 08:00:00.5", func(t *testing.T) {165 from := time.Date(1960, 2, 1, 7, 0, 0, 500e6, time.UTC)166 to := time.Date(1980, 2, 3, 8, 0, 0, 500e6, time.UTC)167 timeRange := backend.TimeRange{168 From: from,169 To: to,170 }171 require.Equal(t, "1960-02-01T07:00:00.5Z", from.Format(time.RFC3339Nano))172 require.Equal(t, "1980-02-03T08:00:00.5Z", to.Format(time.RFC3339Nano))173 t.Run("interpolate __timeFilter function", func(t *testing.T) {174 sql, err := engine.Interpolate(query, timeRange, "WHERE $__timeFilter(time_column)")175 require.NoError(t, err)176 require.Equal(t, fmt.Sprintf("WHERE time_column BETWEEN '%s' AND '%s'", from.Format(time.RFC3339Nano), to.Format(time.RFC3339Nano)), sql)177 })178 })179}180func TestMacroEngineConcurrency(t *testing.T) {181 engine := newPostgresMacroEngine(false)182 query1 := backend.DataQuery{183 JSON: []byte{},184 }185 query2 := backend.DataQuery{186 JSON: []byte{},187 }...

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 Venom 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