dubbo.apache.org/dubbo-go/v3@v3.1.1/filter/seata/filter_test.go (about)

     1  /*
     2   * Licensed to the Apache Software Foundation (ASF) under one or more
     3   * contributor license agreements.  See the NOTICE file distributed with
     4   * this work for additional information regarding copyright ownership.
     5   * The ASF licenses this file to You under the Apache License, Version 2.0
     6   * (the "License"); you may not use this file except in compliance with
     7   * the License.  You may obtain a copy of the License at
     8   *
     9   *     http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17  
    18  package seata
    19  
    20  import (
    21  	"context"
    22  	"testing"
    23  )
    24  
    25  import (
    26  	"github.com/stretchr/testify/assert"
    27  )
    28  
    29  import (
    30  	"dubbo.apache.org/dubbo-go/v3/protocol"
    31  	"dubbo.apache.org/dubbo-go/v3/protocol/invocation"
    32  )
    33  
    34  type testMockSeataInvoker struct {
    35  	protocol.BaseInvoker
    36  }
    37  
    38  func (iv *testMockSeataInvoker) Invoke(ctx context.Context, _ protocol.Invocation) protocol.Result {
    39  	val := ctx.Value(SEATA_XID)
    40  	if val != nil {
    41  		xid, ok := val.(string)
    42  		if ok {
    43  			return &protocol.RPCResult{Rest: xid}
    44  		}
    45  	}
    46  	return &protocol.RPCResult{}
    47  }
    48  
    49  func TestSeataFilter_Invoke(t *testing.T) {
    50  	filter := &seataFilter{}
    51  	result := filter.Invoke(context.Background(), &testMockSeataInvoker{}, invocation.NewRPCInvocation("$echo",
    52  		[]interface{}{"OK"}, map[string]interface{}{
    53  			string(SEATA_XID): "10.30.21.227:8091:2000047792",
    54  		}))
    55  	assert.Equal(t, "10.30.21.227:8091:2000047792", result.Result())
    56  }