github.com/bananabytelabs/wazero@v0.0.0-20240105073314-54b22a776da8/internal/gojs/crypto_test.go (about) 1 package gojs_test 2 3 import ( 4 "bytes" 5 "context" 6 "testing" 7 8 "github.com/bananabytelabs/wazero/experimental" 9 "github.com/bananabytelabs/wazero/experimental/logging" 10 "github.com/bananabytelabs/wazero/internal/testing/require" 11 ) 12 13 func Test_crypto(t *testing.T) { 14 t.Parallel() 15 16 var log bytes.Buffer 17 loggingCtx := context.WithValue(testCtx, experimental.FunctionListenerFactoryKey{}, 18 logging.NewHostLoggingListenerFactory(&log, logging.LogScopeRandom)) 19 20 stdout, stderr, err := compileAndRun(loggingCtx, "crypto", defaultConfig) 21 22 require.Zero(t, stderr) 23 require.NoError(t, err) 24 require.Equal(t, `7a0c9f9f0d 25 `, stdout) 26 require.Equal(t, `==> go.runtime.getRandomData(r_len=32) 27 <== 28 ==> go.runtime.getRandomData(r_len=8) 29 <== 30 ==> go.syscall/js.valueCall(crypto.getRandomValues(r_len=5)) 31 <== (n=5) 32 `, logString(log)) 33 }