github.com/prysmaticlabs/prysm@v1.4.4/proto/migration/enums_test.go (about) 1 package migration 2 3 import ( 4 "testing" 5 6 v1 "github.com/prysmaticlabs/prysm/proto/eth/v1" 7 eth "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1" 8 ) 9 10 func TestV1Alpha1ConnectionStateToV1(t *testing.T) { 11 tests := []struct { 12 name string 13 connState eth.ConnectionState 14 want v1.ConnectionState 15 }{ 16 { 17 name: "DISCONNECTED", 18 connState: eth.ConnectionState_DISCONNECTED, 19 want: v1.ConnectionState_DISCONNECTED, 20 }, 21 { 22 name: "CONNECTED", 23 connState: eth.ConnectionState_CONNECTED, 24 want: v1.ConnectionState_CONNECTED, 25 }, 26 { 27 name: "CONNECTING", 28 connState: eth.ConnectionState_CONNECTING, 29 want: v1.ConnectionState_CONNECTING, 30 }, 31 { 32 name: "DISCONNECTING", 33 connState: eth.ConnectionState_DISCONNECTING, 34 want: v1.ConnectionState_DISCONNECTING, 35 }, 36 } 37 for _, tt := range tests { 38 t.Run(tt.name, func(t *testing.T) { 39 if got := V1Alpha1ConnectionStateToV1(tt.connState); got != tt.want { 40 t.Errorf("V1Alpha1ConnectionStateToV1() = %v, want %v", got, tt.want) 41 } 42 }) 43 } 44 } 45 46 func TestV1Alpha1PeerDirectionToV1(t *testing.T) { 47 tests := []struct { 48 name string 49 peerDirection eth.PeerDirection 50 want v1.PeerDirection 51 wantErr bool 52 }{ 53 { 54 name: "UNKNOWN", 55 peerDirection: eth.PeerDirection_UNKNOWN, 56 want: 0, 57 wantErr: true, 58 }, 59 { 60 name: "INBOUND", 61 peerDirection: eth.PeerDirection_INBOUND, 62 want: v1.PeerDirection_INBOUND, 63 }, 64 { 65 name: "OUTBOUND", 66 peerDirection: eth.PeerDirection_OUTBOUND, 67 want: v1.PeerDirection_OUTBOUND, 68 }, 69 } 70 for _, tt := range tests { 71 t.Run(tt.name, func(t *testing.T) { 72 got, err := V1Alpha1PeerDirectionToV1(tt.peerDirection) 73 if (err != nil) != tt.wantErr { 74 t.Errorf("V1Alpha1PeerDirectionToV1() error = %v, wantErr %v", err, tt.wantErr) 75 return 76 } 77 if got != tt.want { 78 t.Errorf("V1Alpha1PeerDirectionToV1() got = %v, want %v", got, tt.want) 79 } 80 }) 81 } 82 }