Best Gauge code snippet using cmd.appendTags
lock-rest-client.go
Source:lock-rest-client.go
1/*2 * MinIO Cloud Storage, (C) 2019 MinIO, Inc.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 at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * limitations under the License.15 */16package cmd17import (18 "bytes"19 "context"20 "crypto/tls"21 "encoding/gob"22 "errors"23 "io"24 "sync"25 "time"26 "net/url"27 "github.com/minio/dsync"28 "github.com/minio/minio/cmd/http"29 "github.com/minio/minio/cmd/logger"30 "github.com/minio/minio/cmd/rest"31 xnet "github.com/minio/minio/pkg/net"32)33// lockRESTClient is authenticable lock REST client34type lockRESTClient struct {35 lockSync sync.RWMutex36 host *xnet.Host37 restClient *rest.Client38 serverURL *url.URL39 connected bool40 timer *time.Timer41}42// ServerAddr - dsync.NetLocker interface compatible method.43func (client *lockRESTClient) ServerAddr() string {44 return client.serverURL.Host45}46// ServiceEndpoint - dsync.NetLocker interface compatible method.47func (client *lockRESTClient) ServiceEndpoint() string {48 return client.serverURL.Path49}50// check if the host is up or if it is fine51// to make a call to the lock rest server.52func (client *lockRESTClient) isHostUp() bool {53 client.lockSync.Lock()54 defer client.lockSync.Unlock()55 if client.connected {56 return true57 }58 select {59 case <-client.timer.C:60 client.connected = true61 client.timer = nil62 return true63 default:64 }65 return false66}67// Default retry constants.68const (69 defaultRetryUnit = time.Second // 1 second.70 defaultRetryCap = 30 * time.Second // 30 seconds.71)72// Mark the host as down if there is a Network error.73func (client *lockRESTClient) markHostDown() {74 client.lockSync.Lock()75 defer client.lockSync.Unlock()76 if !client.connected {77 return78 }79 client.connected = false80 client.timer = time.NewTimer(defaultRetryUnit * 5)81}82// Wrapper to restClient.Call to handle network errors, in case of network error the connection is marked disconnected83// permanently. The only way to restore the connection is at the xl-sets layer by xlsets.monitorAndConnectEndpoints()84// after verifying format.json85func (client *lockRESTClient) call(method string, values url.Values, body io.Reader, length int64) (respBody io.ReadCloser, err error) {86 if !client.isHostUp() {87 return nil, errors.New("Lock rest server node is down")88 }89 if values == nil {90 values = make(url.Values)91 }92 respBody, err = client.restClient.Call(method, values, body, length)93 if err == nil {94 return respBody, nil95 }96/*97 if isNetworkError(err) {98 client.markHostDown()99 }100*/101 return nil, err102}103// Stringer provides a canonicalized representation of node.104func (client *lockRESTClient) String() string {105 return client.host.String()106}107// IsOnline - returns whether REST client failed to connect or not.108func (client *lockRESTClient) IsOnline() bool {109 return client.connected110}111// Close - marks the client as closed.112func (client *lockRESTClient) Close() error {113 client.connected = false114 client.restClient.Close()115 return nil116}117// restCall makes a call to the lock REST server.118func (client *lockRESTClient) restCall(call string, args dsync.LockArgs) (reply bool, err error) {119 reader := bytes.NewBuffer(make([]byte, 0, 2048))120 err = gob.NewEncoder(reader).Encode(args)121 if err != nil {122 return false, err123 }124 respBody, err := client.call(call, nil, reader, -1)125 if err != nil {126 return false, err127 }128 var resp lockResponse129 defer http.DrainBody(respBody)130 err = gob.NewDecoder(respBody).Decode(&resp)131 if err != nil || !resp.Success {132 reqInfo := &logger.ReqInfo{}133 reqInfo.AppendTags("resource", args.Resource)134 reqInfo.AppendTags("serveraddress", args.ServerAddr)135 reqInfo.AppendTags("serviceendpoint", args.ServiceEndpoint)136 reqInfo.AppendTags("source", args.Source)137 reqInfo.AppendTags("uid", args.UID)138 ctx := logger.SetReqInfo(context.Background(), reqInfo)139 logger.LogIf(ctx, err)140 }141 return resp.Success, err142}143// RLock calls read lock REST API.144func (client *lockRESTClient) RLock(args dsync.LockArgs) (reply bool, err error) {145 return client.restCall(lockRESTMethodRLock, args)146}147// Lock calls lock REST API.148func (client *lockRESTClient) Lock(args dsync.LockArgs) (reply bool, err error) {149 return client.restCall(lockRESTMethodLock, args)150}151// RUnlock calls read unlock REST API.152func (client *lockRESTClient) RUnlock(args dsync.LockArgs) (reply bool, err error) {153 return client.restCall(lockRESTMethodRUnlock, args)154}155// Unlock calls write unlock RPC.156func (client *lockRESTClient) Unlock(args dsync.LockArgs) (reply bool, err error) {157 return client.restCall(lockRESTMethodUnlock, args)158}159// ForceUnlock calls force unlock RPC.160func (client *lockRESTClient) ForceUnlock(args dsync.LockArgs) (reply bool, err error) {161 return client.restCall(lockRESTMethodForceUnlock, args)162}163// Expired calls expired RPC.164func (client *lockRESTClient) Expired(args dsync.LockArgs) (reply bool, err error) {165 return client.restCall(lockRESTMethodExpired, args)166}167// Returns a lock rest client.168func newlockRESTClient(peer *xnet.Host) *lockRESTClient {169 scheme := "http"170 if globalIsSSL {171 scheme = "https"172 }173 serverURL := &url.URL{174 Scheme: scheme,175 Host: peer.String(),176 Path: lockRESTPath,177 }178 var tlsConfig *tls.Config179 if globalIsSSL {180 tlsConfig = &tls.Config{181 ServerName: peer.Name,182 RootCAs: globalRootCAs,183 NextProtos: []string{"http/1.1"}, // Force http1.1184 }185 }186 restClient, err := rest.NewClient(serverURL, tlsConfig, rest.DefaultRESTTimeout, newAuthToken)187 if err != nil {188 logger.LogIf(context.Background(), err)189 return &lockRESTClient{serverURL: serverURL, host: peer, restClient: restClient, connected: false, timer: time.NewTimer(defaultRetryUnit * 5)}190 }191 return &lockRESTClient{serverURL: serverURL, host: peer, restClient: restClient, connected: true}192}...
list.go
Source:list.go
...65}66func listTags(s []*gauge.Specification, f handleResult) {67 allTags := []string{}68 for _, spec := range s {69 allTags = appendTags(allTags, spec.Tags)70 for _, scenario := range spec.Scenarios {71 allTags = appendTags(allTags, scenario.Tags)72 }73 }74 f(sortedDistinctElements(allTags))75}76func listScenarios(s []*gauge.Specification, f handleResult) {77 allScenarios := filter.GetAllScenarios(s)78 f(sortedDistinctElements(allScenarios))79}80func listSpecifications(s []*gauge.Specification, f handleResult) {81 allSpecs := []string{}82 for _, spec := range s {83 allSpecs = append(allSpecs, spec.Heading.Value)84 }85 f(sortedDistinctElements(allSpecs))86}87func sortedDistinctElements(s []string) []string {88 unique := uniqueNonEmptyElementsOf(s)89 supersort.Strings(unique)90 return unique91}92func appendTags(s []string, tags *gauge.Tags) []string {93 if tags != nil {94 s = append(s, tags.Values()...)95 }96 return s97}98func uniqueNonEmptyElementsOf(input []string) []string {99 unique := make(map[string]bool, len(input))100 us := make([]string, len(unique))101 for _, elem := range input {102 if len(elem) != 0 && !unique[elem] {103 us = append(us, elem)104 unique[elem] = true105 }106 }...
appendTags
Using AI Code Generation
1import (2func main() {3 cmd1.appendTags("tag1")4 cmd1.appendTags("tag2")5 cmd1.appendTags("tag3")6 fmt.Println(cmd1.tags)7}8Click to share on Telegram (Opens in new window)
appendTags
Using AI Code Generation
1func main() {2 cmd := newCmd()3 cmd.appendTags("tag1", "tag2", "tag3")4}5func main() {6 cmd := newCmd()7 cmd.appendTags("tag4", "tag5", "tag6")8}9func main() {10 cmd := newCmd()11 cmd.appendTags("tag1", "tag2", "tag3")12}13func main() {14 cmd := newCmd()15 cmd.appendTags("tag4", "tag5", "tag6")16}17func main() {18 cmd := newCmd()19 cmd.appendTags("tag1", "tag2", "tag3")20}21func main() {22 cmd := newCmd()23 cmd.appendTags("tag4", "tag5", "tag6")24}25func main() {26 cmd := newCmd()27 cmd.appendTags("tag1", "tag2", "tag3")28}29func main()
appendTags
Using AI Code Generation
1import (2func main() {3 cmd := NewCmd()4 cmd.appendTags("tag1")5 cmd.appendTags("tag2")6 fmt.Println(cmd.Tags)7}8import (9func main() {10 cmd := NewCmd()11 cmd.appendTags("tag3")12 cmd.appendTags("tag4")13 fmt.Println(cmd.Tags)14}15import (16func main() {17 cmd := NewCmd()18 cmd.appendTags("tag1")19 cmd.appendTags("tag2")20 fmt.Println(cmd.Tags)21}22import (23func main() {24 cmd := NewCmd()25 cmd.appendTags("tag3")26 cmd.appendTags("tag4")27 fmt.Println(cmd.Tags)28}
appendTags
Using AI Code Generation
1func main() {2 c := cmd{tags: []string{"a", "b"}}3 c.appendTags("c", "d")4 fmt.Println(c.tags)5}6func main() {7 c := cmd{tags: []string{"a", "b"}}8 c.appendTags("c", "d")9 fmt.Println(c.tags)10}11func main() {12 c := cmd{tags: []string{"a", "b"}}13 c.appendTags("c", "d")14 fmt.Println(c.tags)15}16func main() {17 c := cmd{tags: []string{"a", "b"}}18 c.appendTags("c", "d")19 fmt.Println(c.tags)20}21func main() {22 c := cmd{tags: []string{"a", "b"}}23 c.appendTags("c", "d")24 fmt.Println(c.tags)25}26func main() {27 c := cmd{tags: []string{"a", "b"}}28 c.appendTags("c", "d")29 fmt.Println(c.tags)30}31func main() {32 c := cmd{tags: []string{"a", "b"}}33 c.appendTags("c", "d")34 fmt.Println(c.tags)35}36func main() {37 c := cmd{tags: []string{"a", "b"}}38 c.appendTags("c", "d")39 fmt.Println(c.tags)40}
appendTags
Using AI Code Generation
1import (2type cmd struct {3}4func main() {5 c := cmd{}6 c.appendTags("tag1", "tag2", "tag3")7 fmt.Println(c.Args)8}9import "reflect"10type cmd struct {11}12func (c *cmd) appendTags(tags ...string) {13 c.Args = append(c.Args, tags...)14}15func main() {16 c := cmd{}17 c.appendTags("tag1", "tag2", "tag3")18 fmt.Println(c.Args)19}
appendTags
Using AI Code Generation
1import (2type cmd struct {3}4func (c *cmd) appendTags(tags []string) {5 c.tags = append(c.tags, tags...)6}7func main() {8 c.appendTags([]string{"a", "b", "c"})9 fmt.Println(c.tags)10}11c.tags = append(c.tags, "a", "b", "c")
appendTags
Using AI Code Generation
1cmd := NewCmd()2cmd.appendTags("newTag1", "newTag2")3cmd.appendTags("newTag3", "newTag4")4cmd.appendTags("newTag5", "newTag6")5cmd.appendTags("newTag7", "newTag8")6cmd.appendTags("newTag9", "newTag10")7cmd.appendTags("newTag11", "newTag12")8cmd.appendTags("newTag13", "newTag14")9cmd.appendTags("newTag15", "newTag16")10cmd.appendTags("newTag17", "newTag18")11cmd.appendTags("newTag19", "newTag20")12cmd.appendTags("newTag21", "newTag22")13cmd.appendTags("newTag23", "newTag24")14cmd.appendTags("newTag25", "newTag26")15cmd.appendTags("newTag27", "newTag28")16cmd.appendTags("newTag29", "newTag30")17cmd.appendTags("newTag31", "newTag32")18cmd.appendTags("newTag33", "newTag34")19cmd.appendTags("newTag35", "newTag36")20cmd.appendTags("newTag37", "newTag38")21cmd.appendTags("newTag39", "newTag40")22cmd.appendTags("newTag41", "newTag42")23cmd.appendTags("newTag43", "newTag44")24cmd.appendTags("newTag45", "newTag46")25cmd.appendTags("newTag47", "newTag48")26cmd.appendTags("newTag49", "newTag50")27cmd.appendTags("newTag51", "newTag52")28cmd.appendTags("newTag53", "newTag54")29cmd.appendTags("newTag55", "newTag56")30cmd.appendTags("newTag57", "newTag58")31cmd.appendTags("newTag59", "newTag60")32cmd.appendTags("newTag61", "newTag62")33cmd.appendTags("newTag63", "newTag64")34cmd.appendTags("newTag65", "newTag66")35cmd.appendTags("newTag67", "newTag68")36cmd.appendTags("newTag69", "newTag70")37cmd.appendTags("newTag71", "newTag72")38cmd.appendTags("newTag73", "newTag74")39cmd.appendTags("newTag75", "newTag76
appendTags
Using AI Code Generation
1import (2func main() {3 cmd := new(cmd)4 cmd.appendTags([]string{"tag1", "tag2"})5 fmt.Println(cmd.tags)6 os.Exit(0)7}8import (9func main() {10 cmd := new(cmd)11 cmd.appendTags([]string{"tag1", "tag2"})12 fmt.Println(cmd.tags)13 os.Exit(0)14}15import (16func main() {17 cmd := new(cmd)18 cmd.appendTags([]string{"tag1", "tag2"})19 fmt.Println(cmd.tags)20 os.Exit(0)21}22import (23func main() {24 cmd := new(cmd)25 cmd.appendTags([]string{"tag1", "tag2"})26 fmt.Println(cmd.tags)27 os.Exit(0)28}29import (30func main() {31 cmd := new(cmd)32 cmd.appendTags([]string{"tag1", "tag2"})33 fmt.Println(cmd.tags)34 os.Exit(0)35}36import (37func main() {38 cmd := new(cmd)39 cmd.appendTags([]string{"tag1", "tag2"})40 fmt.Println(cmd.tags)41 os.Exit(0)42}43import (44func main() {45 cmd := new(cmd)46 cmd.appendTags([]string{"tag1", "tag2"})47 fmt.Println(cmd.tags)48 os.Exit(0)49}50import (51func main() {52 cmd := new(cmd)53 cmd.appendTags([]string{"tag1", "tag2"})54 fmt.Println(cmd.tags)55 os.Exit(0)56}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!