github.com/MetalBlockchain/metalgo@v1.11.9/snow/networking/handler/engine_test.go (about)

     1  // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package handler
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/require"
    10  
    11  	"github.com/MetalBlockchain/metalgo/proto/pb/p2p"
    12  )
    13  
    14  func TestEngineManager_Get(t *testing.T) {
    15  	type args struct {
    16  		engineType p2p.EngineType
    17  	}
    18  
    19  	avalanche := &Engine{}
    20  	snowman := &Engine{}
    21  
    22  	type expected struct {
    23  		engine *Engine
    24  	}
    25  
    26  	tests := []struct {
    27  		name     string
    28  		args     args
    29  		expected expected
    30  	}{
    31  		{
    32  			name: "request unspecified engine",
    33  			args: args{
    34  				engineType: p2p.EngineType_ENGINE_TYPE_UNSPECIFIED,
    35  			},
    36  			expected: expected{
    37  				engine: nil,
    38  			},
    39  		},
    40  		{
    41  			name: "request avalanche engine",
    42  			args: args{
    43  				engineType: p2p.EngineType_ENGINE_TYPE_AVALANCHE,
    44  			},
    45  			expected: expected{
    46  				engine: avalanche,
    47  			},
    48  		},
    49  		{
    50  			name: "request snowman engine",
    51  			args: args{
    52  				engineType: p2p.EngineType_ENGINE_TYPE_SNOWMAN,
    53  			},
    54  			expected: expected{
    55  				engine: snowman,
    56  			},
    57  		},
    58  	}
    59  	for _, test := range tests {
    60  		t.Run(test.name, func(t *testing.T) {
    61  			e := EngineManager{
    62  				Avalanche: avalanche,
    63  				Snowman:   snowman,
    64  			}
    65  
    66  			require.Equal(t, test.expected.engine, e.Get(test.args.engineType))
    67  		})
    68  	}
    69  }