github.com/bananabytelabs/wazero@v0.0.0-20240105073314-54b22a776da8/internal/assemblyscript/logging/logging_test.go (about)

     1  package logging
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/bananabytelabs/wazero/api"
     7  	. "github.com/bananabytelabs/wazero/internal/assemblyscript"
     8  	"github.com/bananabytelabs/wazero/internal/logging"
     9  	"github.com/bananabytelabs/wazero/internal/testing/require"
    10  	"github.com/bananabytelabs/wazero/internal/wasm"
    11  )
    12  
    13  type testFunctionDefinition struct {
    14  	name string
    15  	*wasm.FunctionDefinition
    16  }
    17  
    18  // ExportNames implements the same method as documented on api.FunctionDefinition.
    19  func (f *testFunctionDefinition) ExportNames() []string {
    20  	return []string{f.name}
    21  }
    22  
    23  func TestIsInLogScope(t *testing.T) {
    24  	abort := &testFunctionDefinition{name: AbortName}
    25  	seed := &testFunctionDefinition{name: SeedName}
    26  	tests := []struct {
    27  		name     string
    28  		fnd      api.FunctionDefinition
    29  		scopes   logging.LogScopes
    30  		expected bool
    31  	}{
    32  		{
    33  			name:     "abort in LogScopeProc",
    34  			fnd:      abort,
    35  			scopes:   logging.LogScopeProc,
    36  			expected: true,
    37  		},
    38  		{
    39  			name:     "abort not in LogScopeFilesystem",
    40  			fnd:      abort,
    41  			scopes:   logging.LogScopeFilesystem,
    42  			expected: false,
    43  		},
    44  		{
    45  			name:     "abort in LogScopeProc|LogScopeFilesystem",
    46  			fnd:      abort,
    47  			scopes:   logging.LogScopeProc | logging.LogScopeFilesystem,
    48  			expected: true,
    49  		},
    50  		{
    51  			name:     "abort in LogScopeAll",
    52  			fnd:      abort,
    53  			scopes:   logging.LogScopeAll,
    54  			expected: true,
    55  		},
    56  		{
    57  			name:     "abort not in LogScopeNone",
    58  			fnd:      abort,
    59  			scopes:   logging.LogScopeNone,
    60  			expected: false,
    61  		},
    62  		{
    63  			name:     "seed not in LogScopeFilesystem",
    64  			fnd:      seed,
    65  			scopes:   logging.LogScopeFilesystem,
    66  			expected: false,
    67  		},
    68  		{
    69  			name:     "seed in LogScopeRandom|LogScopeFilesystem",
    70  			fnd:      seed,
    71  			scopes:   logging.LogScopeRandom | logging.LogScopeFilesystem,
    72  			expected: true,
    73  		},
    74  		{
    75  			name:     "seed in LogScopeAll",
    76  			fnd:      seed,
    77  			scopes:   logging.LogScopeAll,
    78  			expected: true,
    79  		},
    80  		{
    81  			name:     "seed not in LogScopeNone",
    82  			fnd:      seed,
    83  			scopes:   logging.LogScopeNone,
    84  			expected: false,
    85  		},
    86  	}
    87  
    88  	for _, tt := range tests {
    89  		tc := tt
    90  
    91  		t.Run(tc.name, func(t *testing.T) {
    92  			require.Equal(t, tc.expected, IsInLogScope(tc.fnd, tc.scopes))
    93  		})
    94  	}
    95  }