dubbo.apache.org/dubbo-go/v3@v3.1.1/registry/etcdv3/registry_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  // nolint
    19  package etcdv3
    20  
    21  /*
    22  import (
    23  	"reflect"
    24  	"sync"
    25  	"testing"
    26  )
    27  
    28  import (
    29  	"github.com/agiledragon/gomonkey"
    30  
    31  	gxetcd "github.com/dubbogo/gost/database/kv/etcd/v3"
    32  )
    33  
    34  import (
    35  	"dubbo.apache.org/dubbo-go/v3/registry"
    36  	"dubbo.apache.org/dubbo-go/v3/remoting"
    37  	"dubbo.apache.org/dubbo-go/v3/remoting/etcdv3"
    38  )
    39  
    40  type fields struct {
    41  	BaseRegistry   registry.BaseRegistry
    42  	cltLock        sync.Mutex
    43  	client         *gxetcd.Client
    44  	listenerLock   sync.RWMutex
    45  	listener       *etcdv3.EventListener
    46  	dataListener   *dataListener
    47  	configListener *configurationListener
    48  }
    49  type args struct {
    50  	root      string
    51  	node      string
    52  	eventType remoting.Event
    53  }
    54  
    55  func newEtcdV3Registry(f fields) *etcdV3Registry {
    56  	return &etcdV3Registry{
    57  		client:         f.client,
    58  		listener:       f.listener,
    59  		dataListener:   f.dataListener,
    60  		configListener: f.configListener,
    61  	}
    62  }
    63  
    64  func Test_etcdV3Registry_DoRegister(t *testing.T) {
    65  	var client *gxetcd.Client
    66  	patches := gomonkey.NewPatches()
    67  	patches = patches.ApplyMethod(reflect.TypeOf(client), "RegisterTemp", func(_ *gxetcd.Client, k, v string) error {
    68  		return nil
    69  	})
    70  	defer patches.Reset()
    71  
    72  	tests := []struct {
    73  		name    string
    74  		fields  fields
    75  		args    args
    76  		wantErr bool
    77  	}{
    78  		{
    79  			name: "test",
    80  			fields: fields{
    81  				client: client,
    82  			},
    83  			args: args{
    84  				root: "/dubbo",
    85  				node: "/go",
    86  			},
    87  			wantErr: false,
    88  		},
    89  	}
    90  	for _, tt := range tests {
    91  		t.Run(tt.name, func(t *testing.T) {
    92  			r := newEtcdV3Registry(tt.fields)
    93  			if err := r.DoRegister(tt.args.root, tt.args.node); (err != nil) != tt.wantErr {
    94  				t.Errorf("DoRegister() error = %v, wantErr %v", err, tt.wantErr)
    95  			}
    96  		})
    97  	}
    98  }
    99  
   100  func Test_etcdV3Registry_DoUnregister(t *testing.T) {
   101  	tests := []struct {
   102  		name    string
   103  		fields  fields
   104  		args    args
   105  		wantErr bool
   106  	}{
   107  		{
   108  			name:    "test",
   109  			wantErr: true,
   110  		},
   111  	}
   112  	for _, tt := range tests {
   113  		t.Run(tt.name, func(t *testing.T) {
   114  			r := newEtcdV3Registry(tt.fields)
   115  			if err := r.DoUnregister(tt.args.root, tt.args.node); (err != nil) != tt.wantErr {
   116  				t.Errorf("DoUnregister() error = %v, wantErr %v", err, tt.wantErr)
   117  			}
   118  		})
   119  	}
   120  }
   121  
   122  */