Disallows nil context and fixes linters (#754)
staticcheck linters broke until recent golangci-lint. Now, normal behaviour of enforcing no nil context works again. Ex. ``` assemblyscript/assemblyscript_example_test.go:16:25: SA1012: do not pass a nil Context, even if a function permits it; pass context.TODO if you are unsure about which Context to use (staticcheck) r := wazero.NewRuntime(nil) ``` Since default lint already checks for nil context, this removes our permission of nil context args. The original reason we permitted nil is no longer valid: we once allowed context to be stashed in config, and removed that as it caused bugs. We forgot to undo allowing nil explicitly. Note: this doesn't particularly check in our code for nil context, similar as we don't particularly check in our code for nil anything else. End users should use linters as none of our parameters should be nil anyway. Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
@@ -22,35 +22,16 @@ var (
|
||||
)
|
||||
|
||||
func TestNewRuntimeWithConfig_version(t *testing.T) {
|
||||
// Make sure nil ctx doesn't panic
|
||||
tests := []struct {
|
||||
name string
|
||||
ctx context.Context
|
||||
}{
|
||||
{
|
||||
name: "not nil",
|
||||
ctx: testCtx,
|
||||
},
|
||||
{
|
||||
name: "nil",
|
||||
ctx: nil,
|
||||
},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
tt := tc
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cfg := NewRuntimeConfig().(*runtimeConfig)
|
||||
oldNewEngine := cfg.newEngine
|
||||
cfg.newEngine = func(ctx context.Context, features wasm.Features) wasm.Engine {
|
||||
// Ensures that wazeroVersion is propagated to the engine.
|
||||
v := ctx.Value(version.WazeroVersionKey{})
|
||||
require.NotNil(t, v)
|
||||
require.Equal(t, wazeroVersion, v.(string))
|
||||
return oldNewEngine(ctx, features)
|
||||
}
|
||||
_ = NewRuntimeWithConfig(tt.ctx, cfg)
|
||||
})
|
||||
cfg := NewRuntimeConfig().(*runtimeConfig)
|
||||
oldNewEngine := cfg.newEngine
|
||||
cfg.newEngine = func(ctx context.Context, features wasm.Features) wasm.Engine {
|
||||
// Ensures that wazeroVersion is propagated to the engine.
|
||||
v := ctx.Value(version.WazeroVersionKey{})
|
||||
require.NotNil(t, v)
|
||||
require.Equal(t, wazeroVersion, v.(string))
|
||||
return oldNewEngine(ctx, features)
|
||||
}
|
||||
_ = NewRuntimeWithConfig(testCtx, cfg)
|
||||
}
|
||||
|
||||
func TestRuntime_CompileModule(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user