wa-lang.org/wazero@v1.0.2/imports/proxywasm/_proxytest/option.go (about)

     1  // Copyright 2021 Tetrate
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package proxytest
    16  
    17  import (
    18  	"wa-lang.org/wazero/imports/proxywasm/internal"
    19  	"wa-lang.org/wazero/imports/proxywasm/types"
    20  )
    21  
    22  // EmulatorOption is an option that can be passed to NewHostEmulator.
    23  type EmulatorOption struct {
    24  	pluginConfiguration []byte
    25  	vmConfiguration     []byte
    26  	vmContext           types.VMContext
    27  	properties          map[string][]byte
    28  }
    29  
    30  // NewEmulatorOption creates a new EmulatorOption.
    31  func NewEmulatorOption() *EmulatorOption {
    32  	return &EmulatorOption{vmContext: &types.DefaultVMContext{}}
    33  }
    34  
    35  // WithVMContext sets the VMContext.
    36  func (o *EmulatorOption) WithVMContext(context types.VMContext) *EmulatorOption {
    37  	o.vmContext = context
    38  	return o
    39  }
    40  
    41  // WithPluginConfiguration sets the plugin configuration.
    42  func (o *EmulatorOption) WithPluginConfiguration(data []byte) *EmulatorOption {
    43  	o.pluginConfiguration = data
    44  	return o
    45  }
    46  
    47  // WithVMConfiguration sets the VM configuration.
    48  func (o *EmulatorOption) WithVMConfiguration(data []byte) *EmulatorOption {
    49  	o.vmConfiguration = data
    50  	return o
    51  }
    52  
    53  // WithProperty sets a property. If the property already exists, it will be overwritten.
    54  func (o *EmulatorOption) WithProperty(path []string, value []byte) *EmulatorOption {
    55  	if o.properties == nil {
    56  		o.properties = map[string][]byte{}
    57  	}
    58  	o.properties[string(internal.SerializePropertyPath(path))] = value
    59  	return o
    60  }