@@ -40,36 +40,25 @@ def run
4040end
4141`
4242
43+ func requireRunMemoryQuotaError (t * testing.T , script * Script , args []Value , opts CallOptions ) {
44+ t .Helper ()
45+ requireCallErrorContains (t , script , "run" , args , opts , "memory quota exceeded" )
46+ }
47+
4348func TestMemoryQuotaExceeded (t * testing.T ) {
4449 script := compileScriptWithConfig (t , Config {
4550 StepQuota : 20000 ,
4651 MemoryQuotaBytes : 2048 ,
4752 }, quotaFixture )
48-
49- var err error
50- _ , err = script .Call (context .Background (), "run" , nil , CallOptions {})
51- if err == nil {
52- t .Fatalf ("expected memory quota error" )
53- }
54- if ! strings .Contains (err .Error (), "memory quota exceeded" ) {
55- t .Fatalf ("unexpected error: %v" , err )
56- }
53+ requireRunMemoryQuotaError (t , script , nil , CallOptions {})
5754}
5855
5956func TestMemoryQuotaCountsClassVars (t * testing.T ) {
6057 script := compileScriptWithConfig (t , Config {
6158 StepQuota : 20000 ,
6259 MemoryQuotaBytes : 3072 ,
6360 }, classVarFixture )
64-
65- var err error
66- _ , err = script .Call (context .Background (), "run" , nil , CallOptions {})
67- if err == nil {
68- t .Fatalf ("expected memory quota error" )
69- }
70- if ! strings .Contains (err .Error (), "memory quota exceeded" ) {
71- t .Fatalf ("unexpected error: %v" , err )
72- }
61+ requireRunMemoryQuotaError (t , script , nil , CallOptions {})
7362}
7463
7564func TestMemoryQuotaAllowsExecution (t * testing.T ) {
@@ -95,14 +84,7 @@ func TestMemoryQuotaExceededOnCompletion(t *testing.T) {
9584 }, splitFixture )
9685
9786 input := strings .Repeat ("a," , 4000 )
98- var err error
99- _ , err = script .Call (context .Background (), "run" , []Value {NewString (input )}, CallOptions {})
100- if err == nil {
101- t .Fatalf ("expected memory quota error" )
102- }
103- if ! strings .Contains (err .Error (), "memory quota exceeded" ) {
104- t .Fatalf ("unexpected error: %v" , err )
105- }
87+ requireRunMemoryQuotaError (t , script , []Value {NewString (input )}, CallOptions {})
10688}
10789
10890func TestMemoryQuotaExceededForEmptyBodyDefaultArg (t * testing.T ) {
@@ -116,15 +98,7 @@ func TestMemoryQuotaExceededForEmptyBodyDefaultArg(t *testing.T) {
11698end`
11799
118100 script := compileScriptWithConfig (t , cfg , source )
119-
120- var err error
121- _ , err = script .Call (context .Background (), "run" , nil , CallOptions {})
122- if err == nil {
123- t .Fatalf ("expected memory quota error" )
124- }
125- if ! strings .Contains (err .Error (), "memory quota exceeded" ) {
126- t .Fatalf ("unexpected error: %v" , err )
127- }
101+ requireRunMemoryQuotaError (t , script , nil , CallOptions {})
128102}
129103
130104func TestMemoryQuotaExceededForBoundArguments (t * testing.T ) {
@@ -140,26 +114,12 @@ end`)
140114 }
141115 largeArg := NewArray (parts )
142116
143- var err error
144- _ , err = script .Call (context .Background (), "run" , []Value {largeArg }, CallOptions {})
145- if err == nil {
146- t .Fatalf ("expected memory quota error for positional arg" )
147- }
148- if ! strings .Contains (err .Error (), "memory quota exceeded" ) {
149- t .Fatalf ("unexpected positional arg error: %v" , err )
150- }
151-
152- _ , err = script .Call (context .Background (), "run" , nil , CallOptions {
117+ requireRunMemoryQuotaError (t , script , []Value {largeArg }, CallOptions {})
118+ requireRunMemoryQuotaError (t , script , nil , CallOptions {
153119 Keywords : map [string ]Value {
154120 "payload" : largeArg ,
155121 },
156122 })
157- if err == nil {
158- t .Fatalf ("expected memory quota error for keyword arg" )
159- }
160- if ! strings .Contains (err .Error (), "memory quota exceeded" ) {
161- t .Fatalf ("unexpected keyword arg error: %v" , err )
162- }
163123}
164124
165125func TestMemoryQuotaCountsIndependentEmptySlices (t * testing.T ) {
@@ -173,15 +133,7 @@ func TestMemoryQuotaCountsIndependentEmptySlices(t *testing.T) {
173133 end
174134 items.size
175135end` )
176-
177- var err error
178- _ , err = script .Call (context .Background (), "run" , nil , CallOptions {})
179- if err == nil {
180- t .Fatalf ("expected memory quota error for many independent empty slices" )
181- }
182- if ! strings .Contains (err .Error (), "memory quota exceeded" ) {
183- t .Fatalf ("unexpected error: %v" , err )
184- }
136+ requireRunMemoryQuotaError (t , script , nil , CallOptions {})
185137}
186138
187139func TestMemoryQuotaExceededWithWhileLoopAllocations (t * testing.T ) {
@@ -197,15 +149,7 @@ func TestMemoryQuotaExceededWithWhileLoopAllocations(t *testing.T) {
197149 end
198150 items.size
199151end` )
200-
201- var err error
202- _ , err = script .Call (context .Background (), "run" , nil , CallOptions {})
203- if err == nil {
204- t .Fatalf ("expected memory quota error for while-loop allocations" )
205- }
206- if ! strings .Contains (err .Error (), "memory quota exceeded" ) {
207- t .Fatalf ("unexpected error: %v" , err )
208- }
152+ requireRunMemoryQuotaError (t , script , nil , CallOptions {})
209153}
210154
211155func TestAssignmentPostCheckDoesNotDoubleCountAssignedValue (t * testing.T ) {
0 commit comments