github.com/lfch/etcd-io/tests/v3@v3.0.0-20221004140520-eac99acd3e9d/integration/clientv3/examples/example_test.go (about) 1 // Copyright 2016 The etcd Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package clientv3_test 16 17 import ( 18 "context" 19 "log" 20 21 "github.com/lfch/etcd-io/client/pkg/v3/transport" 22 ) 23 24 func mockConfig_insecure() {} 25 26 func ExampleConfig_insecure() { 27 forUnitTestsRunInMockedContext(mockConfig_insecure, func() { 28 cli, err := clientv3.New(clientv3.Config{ 29 Endpoints: exampleEndpoints(), 30 DialTimeout: dialTimeout, 31 }) 32 if err != nil { 33 log.Fatal(err) 34 } 35 defer cli.Close() // make sure to close the client 36 37 _, err = cli.Put(context.TODO(), "foo", "bar") 38 if err != nil { 39 log.Fatal(err) 40 } 41 }) 42 43 // Without the line below the test is not being executed 44 45 // Output: 46 } 47 48 func mockConfig_withTLS() {} 49 50 func ExampleConfig_withTLS() { 51 forUnitTestsRunInMockedContext(mockConfig_withTLS, func() { 52 tlsInfo := transport.TLSInfo{ 53 CertFile: "/tmp/test-certs/test-name-1.pem", 54 KeyFile: "/tmp/test-certs/test-name-1-key.pem", 55 TrustedCAFile: "/tmp/test-certs/trusted-ca.pem", 56 } 57 tlsConfig, err := tlsInfo.ClientConfig() 58 if err != nil { 59 log.Fatal(err) 60 } 61 cli, err := clientv3.New(clientv3.Config{ 62 Endpoints: exampleEndpoints(), 63 DialTimeout: dialTimeout, 64 TLS: tlsConfig, 65 }) 66 if err != nil { 67 log.Fatal(err) 68 } 69 defer cli.Close() // make sure to close the client 70 71 _, err = cli.Put(context.TODO(), "foo", "bar") 72 if err != nil { 73 log.Fatal(err) 74 } 75 }) 76 // Without the line below the test is not being executed 77 // Output: 78 }