k8s.io/apiserver@v0.31.1/pkg/storage/etcd3/testing/test_server.go (about)

     1  /*
     2  Copyright 2015 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package testing
    18  
    19  import (
    20  	"testing"
    21  
    22  	clientv3 "go.etcd.io/etcd/client/v3"
    23  
    24  	"k8s.io/apiserver/pkg/storage/etcd3/testserver"
    25  	"k8s.io/apiserver/pkg/storage/storagebackend"
    26  )
    27  
    28  // EtcdTestServer encapsulates the datastructures needed to start local instance for testing
    29  type EtcdTestServer struct {
    30  	V3Client *clientv3.Client
    31  }
    32  
    33  func (e *EtcdTestServer) Terminate(t *testing.T) {
    34  	// no-op, server termination moved to test cleanup
    35  }
    36  
    37  // NewUnsecuredEtcd3TestClientServer creates a new client and server for testing
    38  func NewUnsecuredEtcd3TestClientServer(t *testing.T) (*EtcdTestServer, *storagebackend.Config) {
    39  	server := &EtcdTestServer{}
    40  	server.V3Client = testserver.RunEtcd(t, nil)
    41  	config := &storagebackend.Config{
    42  		Type:   "etcd3",
    43  		Prefix: PathPrefix(),
    44  		Transport: storagebackend.TransportConfig{
    45  			ServerList: server.V3Client.Endpoints(),
    46  		},
    47  	}
    48  	return server, config
    49  }