Best Go-testdeep code snippet using td.Len
discovery_test.go
Source:discovery_test.go
1// Copyright 2018 TiKV Project 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 at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS IS" BASIS,11// See the License for the specific language governing permissions and12// limitations under the License.13package discovery14import (15 "fmt"16 "os"17 "strings"18 "testing"19 . "github.com/onsi/gomega"20 "github.com/pingcap/kvproto/pkg/pdpb"21 "github.com/tikv/tikv-operator/pkg/apis/tikv/v1alpha1"22 "github.com/tikv/tikv-operator/pkg/pdapi"23 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"24 kubefake "k8s.io/client-go/kubernetes/fake"25)26func TestDiscoveryDiscovery(t *testing.T) {27 g := NewGomegaWithT(t)28 type testcase struct {29 name string30 ns string31 url string32 clusters map[string]*clusterInfo33 tcFn func() (*v1alpha1.TikvCluster, error)34 getMembersFn func() (*pdapi.MembersInfo, error)35 expectFn func(*GomegaWithT, *pdDiscovery, string, error)36 }37 testFn := func(test *testcase, t *testing.T) {38 t.Log(test.name)39 kubeCli := kubefake.NewSimpleClientset()40 fakePDControl := pdapi.NewFakePDControl(kubeCli)41 pdClient := pdapi.NewFakePDClient()42 tc, err := test.tcFn()43 if err == nil {44 fakePDControl.SetPDClient(pdapi.Namespace(tc.GetNamespace()), tc.GetName(), pdClient)45 }46 pdClient.AddReaction(pdapi.GetMembersActionType, func(action *pdapi.Action) (interface{}, error) {47 return test.getMembersFn()48 })49 td := &pdDiscovery{50 pdControl: fakePDControl,51 tcGetFn: func(ns, tcName string) (*v1alpha1.TikvCluster, error) {52 return tc, err53 },54 clusters: test.clusters,55 }56 os.Setenv("MY_POD_NAMESPACE", test.ns)57 re, err := td.Discover(test.url)58 test.expectFn(g, td, re, err)59 }60 tests := []testcase{61 {62 name: "advertisePeerUrl is empty",63 ns: "default",64 url: "",65 clusters: map[string]*clusterInfo{},66 tcFn: newTC,67 expectFn: func(g *GomegaWithT, td *pdDiscovery, s string, err error) {68 g.Expect(err).To(HaveOccurred())69 g.Expect(strings.Contains(err.Error(), "advertisePeerUrl is empty")).To(BeTrue())70 g.Expect(len(td.clusters)).To(BeZero())71 },72 },73 {74 name: "advertisePeerUrl is wrong",75 ns: "default",76 url: "demo-pd-0.demo-pd-peer.default:2380",77 clusters: map[string]*clusterInfo{},78 tcFn: newTC,79 expectFn: func(g *GomegaWithT, td *pdDiscovery, s string, err error) {80 g.Expect(err).To(HaveOccurred())81 g.Expect(strings.Contains(err.Error(), "advertisePeerUrl format is wrong: ")).To(BeTrue())82 g.Expect(len(td.clusters)).To(BeZero())83 },84 },85 {86 name: "namespace is wrong",87 ns: "default1",88 url: "demo-pd-0.demo-pd-peer.default.svc:2380",89 clusters: map[string]*clusterInfo{},90 tcFn: newTC,91 expectFn: func(g *GomegaWithT, td *pdDiscovery, s string, err error) {92 g.Expect(err).To(HaveOccurred())93 g.Expect(strings.Contains(err.Error(), "is not equal to discovery namespace:")).To(BeTrue())94 g.Expect(len(td.clusters)).To(BeZero())95 },96 },97 {98 name: "failed to get tidbcluster",99 ns: "default",100 url: "demo-pd-0.demo-pd-peer.default.svc:2380",101 clusters: map[string]*clusterInfo{},102 tcFn: func() (*v1alpha1.TikvCluster, error) {103 return nil, fmt.Errorf("failed to get tidbcluster")104 },105 expectFn: func(g *GomegaWithT, td *pdDiscovery, s string, err error) {106 g.Expect(err).To(HaveOccurred())107 g.Expect(strings.Contains(err.Error(), "failed to get tidbcluster")).To(BeTrue())108 g.Expect(len(td.clusters)).To(BeZero())109 },110 },111 {112 name: "failed to get members",113 ns: "default",114 url: "demo-pd-0.demo-pd-peer.default.svc:2380",115 clusters: map[string]*clusterInfo{},116 tcFn: newTC,117 getMembersFn: func() (*pdapi.MembersInfo, error) {118 return nil, fmt.Errorf("get members failed")119 },120 expectFn: func(g *GomegaWithT, td *pdDiscovery, s string, err error) {121 g.Expect(err).To(HaveOccurred())122 g.Expect(strings.Contains(err.Error(), "get members failed")).To(BeTrue())123 g.Expect(len(td.clusters)).To(Equal(1))124 g.Expect(len(td.clusters["default/demo"].peers)).To(Equal(1))125 g.Expect(td.clusters["default/demo"].peers["demo-pd-0"]).To(Equal(struct{}{}))126 },127 },128 {129 name: "resourceVersion changed",130 ns: "default",131 url: "demo-pd-0.demo-pd-peer.default.svc:2380",132 tcFn: newTC,133 getMembersFn: func() (*pdapi.MembersInfo, error) {134 return nil, fmt.Errorf("getMembers failed")135 },136 clusters: map[string]*clusterInfo{137 "default/demo": {138 resourceVersion: "2",139 peers: map[string]struct{}{140 "demo-pd-0": {},141 "demo-pd-1": {},142 },143 },144 },145 expectFn: func(g *GomegaWithT, td *pdDiscovery, s string, err error) {146 g.Expect(err).To(HaveOccurred())147 g.Expect(strings.Contains(err.Error(), "getMembers failed")).To(BeTrue())148 g.Expect(len(td.clusters)).To(Equal(1))149 g.Expect(len(td.clusters["default/demo"].peers)).To(Equal(1))150 g.Expect(td.clusters["default/demo"].peers["demo-pd-0"]).To(Equal(struct{}{}))151 },152 },153 {154 name: "1 cluster, first ordinal, there are no pd members",155 ns: "default",156 url: "demo-pd-0.demo-pd-peer.default.svc:2380",157 clusters: map[string]*clusterInfo{},158 tcFn: newTC,159 getMembersFn: func() (*pdapi.MembersInfo, error) {160 return nil, fmt.Errorf("there are no pd members")161 },162 expectFn: func(g *GomegaWithT, td *pdDiscovery, s string, err error) {163 g.Expect(err).To(HaveOccurred())164 g.Expect(strings.Contains(err.Error(), "there are no pd members")).To(BeTrue())165 g.Expect(len(td.clusters)).To(Equal(1))166 g.Expect(len(td.clusters["default/demo"].peers)).To(Equal(1))167 g.Expect(td.clusters["default/demo"].peers["demo-pd-0"]).To(Equal(struct{}{}))168 },169 },170 {171 name: "1 cluster, second ordinal, there are no pd members",172 ns: "default",173 url: "demo-pd-1.demo-pd-peer.default.svc:2380",174 tcFn: newTC,175 getMembersFn: func() (*pdapi.MembersInfo, error) {176 return nil, fmt.Errorf("there are no pd members 2")177 },178 clusters: map[string]*clusterInfo{179 "default/demo": {180 resourceVersion: "1",181 peers: map[string]struct{}{182 "demo-pd-0": {},183 },184 },185 },186 expectFn: func(g *GomegaWithT, td *pdDiscovery, s string, err error) {187 g.Expect(err).To(HaveOccurred())188 g.Expect(strings.Contains(err.Error(), "there are no pd members 2")).To(BeTrue())189 g.Expect(len(td.clusters)).To(Equal(1))190 g.Expect(len(td.clusters["default/demo"].peers)).To(Equal(2))191 g.Expect(td.clusters["default/demo"].peers["demo-pd-0"]).To(Equal(struct{}{}))192 g.Expect(td.clusters["default/demo"].peers["demo-pd-1"]).To(Equal(struct{}{}))193 },194 },195 {196 name: "1 cluster, third ordinal, return the initial-cluster args",197 ns: "default",198 url: "demo-pd-2.demo-pd-peer.default.svc:2380",199 tcFn: newTC,200 clusters: map[string]*clusterInfo{201 "default/demo": {202 resourceVersion: "1",203 peers: map[string]struct{}{204 "demo-pd-0": {},205 "demo-pd-1": {},206 },207 },208 },209 expectFn: func(g *GomegaWithT, td *pdDiscovery, s string, err error) {210 g.Expect(err).NotTo(HaveOccurred())211 g.Expect(len(td.clusters)).To(Equal(1))212 g.Expect(len(td.clusters["default/demo"].peers)).To(Equal(2))213 g.Expect(td.clusters["default/demo"].peers["demo-pd-0"]).To(Equal(struct{}{}))214 g.Expect(td.clusters["default/demo"].peers["demo-pd-1"]).To(Equal(struct{}{}))215 g.Expect(s).To(Equal("--initial-cluster=demo-pd-2=http://demo-pd-2.demo-pd-peer.default.svc:2380"))216 },217 },218 {219 name: "1 cluster, the first ordinal second request, get members failed",220 ns: "default",221 url: "demo-pd-0.demo-pd-peer.default.svc:2380",222 tcFn: newTC,223 getMembersFn: func() (*pdapi.MembersInfo, error) {224 return nil, fmt.Errorf("there are no pd members 3")225 },226 clusters: map[string]*clusterInfo{227 "default/demo": {228 resourceVersion: "1",229 peers: map[string]struct{}{230 "demo-pd-0": {},231 "demo-pd-1": {},232 },233 },234 },235 expectFn: func(g *GomegaWithT, td *pdDiscovery, s string, err error) {236 g.Expect(err).To(HaveOccurred())237 g.Expect(strings.Contains(err.Error(), "there are no pd members 3")).To(BeTrue())238 g.Expect(len(td.clusters)).To(Equal(1))239 g.Expect(len(td.clusters["default/demo"].peers)).To(Equal(2))240 g.Expect(td.clusters["default/demo"].peers["demo-pd-0"]).To(Equal(struct{}{}))241 g.Expect(td.clusters["default/demo"].peers["demo-pd-1"]).To(Equal(struct{}{}))242 },243 },244 {245 name: "1 cluster, the first ordinal third request, get members success",246 ns: "default",247 url: "demo-pd-0.demo-pd-peer.default.svc:2380",248 tcFn: newTC,249 getMembersFn: func() (*pdapi.MembersInfo, error) {250 return &pdapi.MembersInfo{251 Members: []*pdpb.Member{252 {253 PeerUrls: []string{"demo-pd-2.demo-pd-peer.default.svc:2380"},254 },255 },256 }, nil257 },258 clusters: map[string]*clusterInfo{259 "default/demo": {260 resourceVersion: "1",261 peers: map[string]struct{}{262 "demo-pd-0": {},263 "demo-pd-1": {},264 },265 },266 },267 expectFn: func(g *GomegaWithT, td *pdDiscovery, s string, err error) {268 g.Expect(err).NotTo(HaveOccurred())269 g.Expect(len(td.clusters)).To(Equal(1))270 g.Expect(len(td.clusters["default/demo"].peers)).To(Equal(1))271 g.Expect(td.clusters["default/demo"].peers["demo-pd-1"]).To(Equal(struct{}{}))272 g.Expect(s).To(Equal("--join=demo-pd-2.demo-pd-peer.default.svc:2379"))273 },274 },275 {276 name: "1 cluster, the second ordinal second request, get members success",277 ns: "default",278 url: "demo-pd-1.demo-pd-peer.default.svc:2380",279 tcFn: newTC,280 getMembersFn: func() (*pdapi.MembersInfo, error) {281 return &pdapi.MembersInfo{282 Members: []*pdpb.Member{283 {284 PeerUrls: []string{"demo-pd-0.demo-pd-peer.default.svc:2380"},285 },286 {287 PeerUrls: []string{"demo-pd-2.demo-pd-peer.default.svc:2380"},288 },289 },290 }, nil291 },292 clusters: map[string]*clusterInfo{293 "default/demo": {294 resourceVersion: "1",295 peers: map[string]struct{}{296 "demo-pd-1": {},297 },298 },299 },300 expectFn: func(g *GomegaWithT, td *pdDiscovery, s string, err error) {301 g.Expect(err).NotTo(HaveOccurred())302 g.Expect(len(td.clusters)).To(Equal(1))303 g.Expect(len(td.clusters["default/demo"].peers)).To(Equal(0))304 g.Expect(s).To(Equal("--join=demo-pd-0.demo-pd-peer.default.svc:2379,demo-pd-2.demo-pd-peer.default.svc:2379"))305 },306 },307 {308 name: "1 cluster, the fourth ordinal request, get members success",309 ns: "default",310 url: "demo-pd-3.demo-pd-peer.default.svc:2380",311 tcFn: func() (*v1alpha1.TikvCluster, error) {312 tc, _ := newTC()313 tc.Spec.PD.Replicas = 5314 return tc, nil315 },316 getMembersFn: func() (*pdapi.MembersInfo, error) {317 return &pdapi.MembersInfo{318 Members: []*pdpb.Member{319 {320 PeerUrls: []string{"demo-pd-0.demo-pd-peer.default.svc:2380"},321 },322 {323 PeerUrls: []string{"demo-pd-1.demo-pd-peer.default.svc:2380"},324 },325 {326 PeerUrls: []string{"demo-pd-2.demo-pd-peer.default.svc:2380"},327 },328 },329 }, nil330 },331 clusters: map[string]*clusterInfo{332 "default/demo": {333 resourceVersion: "1",334 peers: map[string]struct{}{},335 },336 },337 expectFn: func(g *GomegaWithT, td *pdDiscovery, s string, err error) {338 g.Expect(err).NotTo(HaveOccurred())339 g.Expect(len(td.clusters)).To(Equal(1))340 g.Expect(len(td.clusters["default/demo"].peers)).To(Equal(0))341 g.Expect(s).To(Equal("--join=demo-pd-0.demo-pd-peer.default.svc:2379,demo-pd-1.demo-pd-peer.default.svc:2379,demo-pd-2.demo-pd-peer.default.svc:2379"))342 },343 },344 {345 name: "2 clusters, the five ordinal request, get members success",346 ns: "default",347 url: "demo-pd-3.demo-pd-peer.default.svc:2380",348 tcFn: func() (*v1alpha1.TikvCluster, error) {349 tc, _ := newTC()350 tc.Spec.PD.Replicas = 5351 return tc, nil352 },353 getMembersFn: func() (*pdapi.MembersInfo, error) {354 return &pdapi.MembersInfo{355 Members: []*pdpb.Member{356 {357 PeerUrls: []string{"demo-pd-0.demo-pd-peer.default.svc:2380"},358 },359 {360 PeerUrls: []string{"demo-pd-1.demo-pd-peer.default.svc:2380"},361 },362 {363 PeerUrls: []string{"demo-pd-2.demo-pd-peer.default.svc:2380"},364 },365 {366 PeerUrls: []string{"demo-pd-3.demo-pd-peer.default.svc:2380"},367 },368 },369 }, nil370 },371 clusters: map[string]*clusterInfo{372 "default/demo": {373 resourceVersion: "1",374 peers: map[string]struct{}{},375 },376 "default/demo-1": {377 peers: map[string]struct{}{378 "demo-1-pd-0": {},379 "demo-1-pd-1": {},380 "demo-1-pd-2": {},381 },382 },383 },384 expectFn: func(g *GomegaWithT, td *pdDiscovery, s string, err error) {385 g.Expect(err).NotTo(HaveOccurred())386 g.Expect(len(td.clusters)).To(Equal(2))387 g.Expect(len(td.clusters["default/demo"].peers)).To(Equal(0))388 g.Expect(len(td.clusters["default/demo-1"].peers)).To(Equal(3))389 g.Expect(s).To(Equal("--join=demo-pd-0.demo-pd-peer.default.svc:2379,demo-pd-1.demo-pd-peer.default.svc:2379,demo-pd-2.demo-pd-peer.default.svc:2379,demo-pd-3.demo-pd-peer.default.svc:2379"))390 },391 },392 }393 for i := range tests {394 testFn(&tests[i], t)395 }396}397func newTC() (*v1alpha1.TikvCluster, error) {398 return &v1alpha1.TikvCluster{399 TypeMeta: metav1.TypeMeta{Kind: "TikvCluster", APIVersion: "v1alpha1"},400 ObjectMeta: metav1.ObjectMeta{401 Name: "demo",402 Namespace: metav1.NamespaceDefault,403 ResourceVersion: "1",404 },405 Spec: v1alpha1.TikvClusterSpec{406 PD: v1alpha1.PDSpec{Replicas: 3},407 },408 }, nil409}...
data.go
Source:data.go
...35 td[i] = zeroValueTriangleData36 }37 return &td38}39// Len returns the number of vertices in TrianglesData.40func (td *TrianglesData) Len() int {41 return len(*td)42}43// SetLen resizes TrianglesData to len, while keeping the original content.44//45// If len is greater than TrianglesData's current length, the new data is filled with default46// values ((0, 0), white, (0, 0), 0).47func (td *TrianglesData) SetLen(len int) {48 if len > td.Len() {49 needAppend := len - td.Len()50 for i := 0; i < needAppend; i++ {51 *td = append(*td, zeroValueTriangleData)52 }53 }54 if len < td.Len() {55 *td = (*td)[:len]56 }57}58// Slice returns a sub-Triangles of this TrianglesData.59func (td *TrianglesData) Slice(i, j int) Triangles {60 s := TrianglesData((*td)[i:j])61 return &s62}63func (td *TrianglesData) updateData(t Triangles) {64 // fast path optimization65 if t, ok := t.(*TrianglesData); ok {66 copy(*td, *t)67 return68 }69 // slow path manual copy70 if t, ok := t.(TrianglesPosition); ok {71 for i := range *td {72 (*td)[i].Position = t.Position(i)73 }74 }75 if t, ok := t.(TrianglesColor); ok {76 for i := range *td {77 (*td)[i].Color = t.Color(i)78 }79 }80 if t, ok := t.(TrianglesPicture); ok {81 for i := range *td {82 (*td)[i].Picture, (*td)[i].Intensity = t.Picture(i)83 }84 }85 if t, ok := t.(TrianglesClipped); ok {86 for i := range *td {87 (*td)[i].ClipRect, (*td)[i].IsClipped = t.ClipRect(i)88 }89 }90}91// Update copies vertex properties from the supplied Triangles into this TrianglesData.92//93// TrianglesPosition, TrianglesColor and TrianglesTexture are supported.94func (td *TrianglesData) Update(t Triangles) {95 if td.Len() != t.Len() {96 panic(fmt.Errorf("(%T).Update: invalid triangles length", td))97 }98 td.updateData(t)99}100// Copy returns an exact independent copy of this TrianglesData.101func (td *TrianglesData) Copy() Triangles {102 copyTd := MakeTrianglesData(td.Len())103 copyTd.Update(td)104 return copyTd105}106// Position returns the position property of i-th vertex.107func (td *TrianglesData) Position(i int) Vec {108 return (*td)[i].Position109}110// Color returns the color property of i-th vertex.111func (td *TrianglesData) Color(i int) RGBA {112 return (*td)[i].Color113}114// Picture returns the picture property of i-th vertex.115func (td *TrianglesData) Picture(i int) (pic Vec, intensity float64) {116 return (*td)[i].Picture, (*td)[i].Intensity...
ir_impl.go
Source:ir_impl.go
...13 rows *sql.Rows14 hasNext bool15 args []interface{}16}17func newRowIter(rows *sql.Rows, argLen int) *rowIter {18 r := &rowIter{19 rows: rows,20 hasNext: false,21 args: make([]interface{}, argLen),22 }23 r.hasNext = r.rows.Next()24 return r25}26func (iter *rowIter) Close() error {27 return iter.rows.Close()28}29func (iter *rowIter) Decode(row RowReceiver) error {30 return decodeFromRows(iter.rows, iter.args, row)31}32func (iter *rowIter) Error() error {33 return errors.Trace(iter.rows.Err())34}35func (iter *rowIter) Next() {36 iter.hasNext = iter.rows.Next()37}38func (iter *rowIter) HasNext() bool {39 return iter.hasNext40}41// multiQueriesChunkIter implements the SQLRowIter interface.42// Note: To create a rowIter, please use `newRowIter()` instead of struct literal.43type multiQueriesChunkIter struct {44 tctx *tcontext.Context45 conn *sql.Conn46 rows *sql.Rows47 hasNext bool48 id int49 queries []string50 args []interface{}51 err error52}53func newMultiQueryChunkIter(tctx *tcontext.Context, conn *sql.Conn, queries []string, argLen int) *multiQueriesChunkIter {54 r := &multiQueriesChunkIter{55 tctx: tctx,56 conn: conn,57 queries: queries,58 id: 0,59 args: make([]interface{}, argLen),60 }61 r.nextRows()62 return r63}64func (iter *multiQueriesChunkIter) nextRows() {65 if iter.id >= len(iter.queries) {66 iter.hasNext = false67 return68 }69 var err error70 defer func() {71 if err != nil {72 iter.hasNext = false73 iter.err = errors.Trace(err)74 }75 }()76 tctx, conn := iter.tctx, iter.conn77 // avoid the empty chunk78 for iter.id < len(iter.queries) {79 rows := iter.rows80 if rows != nil {81 err = rows.Close()82 if err != nil {83 return84 }85 err = rows.Err()86 if err != nil {87 return88 }89 }90 tctx.L().Debug("try to start nextRows", zap.String("query", iter.queries[iter.id]))91 rows, err = conn.QueryContext(tctx, iter.queries[iter.id])92 if err != nil {93 return94 }95 if err = rows.Err(); err != nil {96 return97 }98 iter.id++99 iter.rows = rows100 iter.hasNext = iter.rows.Next()101 if iter.hasNext {102 return103 }104 }105}106func (iter *multiQueriesChunkIter) Close() error {107 if iter.err != nil {108 return iter.err109 }110 if iter.rows != nil {111 return iter.rows.Close()112 }113 return nil114}115func (iter *multiQueriesChunkIter) Decode(row RowReceiver) error {116 if iter.err != nil {117 return iter.err118 }119 if iter.rows == nil {120 return errors.Errorf("no valid rows found, id: %d", iter.id)121 }122 return decodeFromRows(iter.rows, iter.args, row)123}124func (iter *multiQueriesChunkIter) Error() error {125 if iter.err != nil {126 return iter.err127 }128 if iter.rows != nil {129 return errors.Trace(iter.rows.Err())130 }131 return nil132}133func (iter *multiQueriesChunkIter) Next() {134 if iter.err == nil {135 iter.hasNext = iter.rows.Next()136 if !iter.hasNext {137 iter.nextRows()138 }139 }140}141func (iter *multiQueriesChunkIter) HasNext() bool {142 return iter.hasNext143}144type stringIter struct {145 idx int146 ss []string147}148func newStringIter(ss ...string) StringIter {149 return &stringIter{150 idx: 0,151 ss: ss,152 }153}154func (m *stringIter) Next() string {155 if m.idx >= len(m.ss) {156 return ""157 }158 ret := m.ss[m.idx]159 m.idx++160 return ret161}162func (m *stringIter) HasNext() bool {163 return m.idx < len(m.ss)164}165type tableData struct {166 query string167 rows *sql.Rows168 colLen int169 needColTypes bool170 colTypes []string171 SQLRowIter172}173func newTableData(query string, colLength int, needColTypes bool) *tableData {174 return &tableData{175 query: query,176 colLen: colLength,177 needColTypes: needColTypes,178 }179}180func (td *tableData) Start(tctx *tcontext.Context, conn *sql.Conn) error {181 tctx.L().Debug("try to start tableData", zap.String("query", td.query))182 rows, err := conn.QueryContext(tctx, td.query)183 if err != nil {184 return errors.Annotatef(err, "sql: %s", td.query)185 }186 if err = rows.Err(); err != nil {187 return errors.Annotatef(err, "sql: %s", td.query)188 }189 td.SQLRowIter = nil190 td.rows = rows191 if td.needColTypes {192 ns, err := rows.Columns()193 if err != nil {194 return errors.Trace(err)195 }196 td.colLen = len(ns)197 td.colTypes = make([]string, 0, td.colLen)198 colTps, err := rows.ColumnTypes()199 if err != nil {200 return errors.Trace(err)201 }202 for _, c := range colTps {203 td.colTypes = append(td.colTypes, c.DatabaseTypeName())204 }205 }206 return nil207}208func (td *tableData) Rows() SQLRowIter {209 if td.SQLRowIter == nil {210 td.SQLRowIter = newRowIter(td.rows, td.colLen)211 }212 return td.SQLRowIter213}214func (td *tableData) Close() error {215 return td.SQLRowIter.Close()216}217func (td *tableData) RawRows() *sql.Rows {218 return td.rows219}220type tableMeta struct {221 database string222 table string223 colTypes []*sql.ColumnType224 selectedField string225 selectedLen int226 specCmts []string227 showCreateTable string228 showCreateView string229 avgRowLength uint64230 hasImplicitRowID bool231}232func (tm *tableMeta) ColumnTypes() []string {233 colTypes := make([]string, len(tm.colTypes))234 for i, ct := range tm.colTypes {235 colTypes[i] = ct.DatabaseTypeName()236 }237 return colTypes238}239func (tm *tableMeta) ColumnNames() []string {240 colNames := make([]string, len(tm.colTypes))241 for i, ct := range tm.colTypes {242 colNames[i] = ct.Name()243 }244 return colNames245}246func (tm *tableMeta) DatabaseName() string {247 return tm.database248}249func (tm *tableMeta) TableName() string {250 return tm.table251}252func (tm *tableMeta) ColumnCount() uint {253 return uint(len(tm.colTypes))254}255func (tm *tableMeta) SelectedField() string {256 return tm.selectedField257}258func (tm *tableMeta) SelectedLen() int {259 return tm.selectedLen260}261func (tm *tableMeta) SpecialComments() StringIter {262 return newStringIter(tm.specCmts...)263}264func (tm *tableMeta) ShowCreateTable() string {265 return tm.showCreateTable266}267func (tm *tableMeta) ShowCreateView() string {268 return tm.showCreateView269}270func (tm *tableMeta) AvgRowLength() uint64 {271 return tm.avgRowLength272}273func (tm *tableMeta) HasImplicitRowID() bool {274 return tm.hasImplicitRowID275}276type metaData struct {277 target string278 metaSQL string279 specCmts []string280}281func (m *metaData) SpecialComments() StringIter {282 return newStringIter(m.specCmts...)283}284func (m *metaData) TargetName() string {285 return m.target286}287func (m *metaData) MetaSQL() string {288 if !strings.HasSuffix(m.metaSQL, ";\n") {289 m.metaSQL += ";\n"290 }291 return m.metaSQL292}293type multiQueriesChunk struct {294 tctx *tcontext.Context295 conn *sql.Conn296 queries []string297 colLen int298 SQLRowIter299}300func newMultiQueriesChunk(queries []string, colLength int) *multiQueriesChunk {301 return &multiQueriesChunk{302 queries: queries,303 colLen: colLength,304 }305}306func (td *multiQueriesChunk) Start(tctx *tcontext.Context, conn *sql.Conn) error {307 td.tctx = tctx308 td.conn = conn309 return nil310}311func (td *multiQueriesChunk) Rows() SQLRowIter {312 if td.SQLRowIter == nil {313 td.SQLRowIter = newMultiQueryChunkIter(td.tctx, td.conn, td.queries, td.colLen)314 }315 return td.SQLRowIter316}317func (td *multiQueriesChunk) Close() error {318 return td.SQLRowIter.Close()319}320func (td *multiQueriesChunk) RawRows() *sql.Rows {321 return nil322}...
Len
Using AI Code Generation
1import (2type td struct {3}4func (t td) Len() int {5}6func main() {7 t := td{3, 4}8 fmt.Println(t.Len())9}10import (11type td struct {12}13func (t td) Len() int {14}15func main() {16 t := td{3, 4}17 fmt.Println(t.Len())18}19import (20type td struct {21}22func (t td) Len() int {23}24func main() {25 t := td{3, 4}26 fmt.Println(t.Len())27}28import (29type td struct {30}31func (t td) Len() int {32}33func main() {34 t := td{3, 4}35 fmt.Println(t.Len())36}37import (38type td struct {39}40func (t td) Len() int {41}42func main() {43 t := td{3, 4}44 fmt.Println(t.Len())45}46import (47type td struct {48}49func (t td) Len() int {50}51func main() {52 t := td{3, 4}53 fmt.Println(t.Len())54}55import (56type td struct {57}58func (t td) Len() int {59}60func main() {61 t := td{3, 4}62 fmt.Println(t.Len())63}
Len
Using AI Code Generation
1import "fmt"2type td struct {3}4func (t td) Len() float64 {5 return float64(t.x * t.y)6}7func main() {8 t := td{3, 4}9 fmt.Println(t.Len())10}11import "fmt"12type td struct {13}14func (t td) Len() float64 {15 return float64(t.x * t.y)16}17func main() {18 t := td{3, 4}19 fmt.Println(t.Len())20}21import "fmt"22type td struct {23}24func (t td) Len() float64 {25 return float64(t.x * t.y)26}27func main() {28 t := td{3, 4}29 fmt.Println(t.Len())30}31import "fmt"32type td struct {33}34func (t td) Len() float64 {35 return float64(t.x * t.y)36}37func main() {38 t := td{3, 4}39 fmt.Println(t.Len())40}41import "fmt"42type td struct {43}44func (t td) Len() float64 {45 return float64(t.x * t.y)46}47func main() {48 t := td{3, 4}49 fmt.Println(t.Len())50}51import "fmt"52type td struct {53}54func (t td) Len() float64 {55 return float64(t.x * t.y)56}57func main() {58 t := td{3, 4}59 fmt.Println(t.Len())60}
Len
Using AI Code Generation
1import (2type td struct {3}4func main() {5 t := td{1, 2}6 fmt.Println(t.Len())7}8import (9type td struct {10}11func (t td) Len() int {12}13func main() {14 t := td{1, 2}15 fmt.Println(t.Len())16}17import (18type td struct {19}20func (t *td) Len() int {21}22func main() {23 t := td{1, 2}24 fmt.Println(t.Len())25}26import (27type td struct {28}29func (t *td) Len() int {30}31func main() {32 t := &td{1, 2}33 fmt.Println(t.Len())34}35import (36type td struct {37}38func (t td) Len() int {39}40func main() {41 t := &td{1, 2}42 fmt.Println(t.Len())43}44import (45type td struct {46}47func (t td) Len() int {48}49func main() {50 t := td{1, 2}51 fmt.Println((&t).Len())52}53import (54type td struct {55}56func (t *td) Len() int {57}58func main() {59 t := &td{1, 2}60 fmt.Println(t.Len())61}62import (63type td struct {
Len
Using AI Code Generation
1import "fmt"2func main() {3 t := td{10, 20}4 fmt.Println(t.Len())5}6import "fmt"7func main() {8 t := td{10, 20}9 fmt.Println(t.Perimeter())10}11import "fmt"12func main() {13 t := td{10, 20}14 fmt.Println(t.Area())15}16import "fmt"17func main() {18 t := td{10, 20}19 t.Scale(2)20 fmt.Println(t)21}22import "fmt"23func main() {24 t := td{10, 20}25 t.Scale(2)26 fmt.Println(t)27}28import "fmt"29func main() {30 t := td{10, 20}31 t.Scale(2)32 fmt.Println(t)33}34import "fmt"35func main() {36 t := td{10, 20}37 t.Scale(2)38 fmt.Println(t)39}40import "fmt"41func main() {42 t := td{10, 20}43 t.Scale(2)44 fmt.Println(t)45}46import "fmt"47func main() {48 t := td{10, 20}49 t.Scale(2)50 fmt.Println(t)51}52import "fmt"53func main() {54 t := td{10, 20}55 t.Scale(2)56 fmt.Println(t)57}58import "fmt"59func main() {60 t := td{10, 20}61 t.Scale(2)62 fmt.Println(t)63}
Len
Using AI Code Generation
1import "fmt"2type td struct {3}4func (t td) Len() int {5}6func main() {7 t := td{10, 20}8 fmt.Println(t.Len())9}10import "fmt"11type td struct {12}13func (t td) Len() int {14}15func main() {16 t := td{10, 20}17 fmt.Println(t.Len())18}19import "fmt"20type td struct {21}22func (t td) Len() int {23}24func main() {25 t := td{10, 20}26 fmt.Println(t.Len())27}28import "fmt"29type td struct {30}31func (t td) Len() int {32}33func main() {34 t := td{10, 20}35 fmt.Println(t.Len())36}37import "fmt"38type td struct {39}40func (t td) Len() int {41}42func main() {43 t := td{10, 20}44 fmt.Println(t.Len())45}46import "fmt"47type td struct {48}49func (t td) Len() int {50}51func main() {52 t := td{10, 20}53 fmt.Println(t.Len())54}55import "fmt"56type td struct {57}58func (t td
Len
Using AI Code Generation
1import (2func main() {3 a = td.TD{1, 2}4 fmt.Println(a.Len())5}6import (7func main() {8 a = td.TD{1, 2}9 fmt.Println(a.Len())10}11import (12func main() {13 a = td.TD{1, 2}14 fmt.Println(a.Len())15}16import (17func main() {18 a = td.TD{1, 2}19 fmt.Println(a.Len())20}21import (22func main() {23 a = td.TD{1, 2}24 fmt.Println(a.Len())25}26import (27func main() {28 a = td.TD{1, 2}29 fmt.Println(a.Len())30}31import (32func main() {33 a = td.TD{1, 2}34 fmt.Println(a.Len())35}36import (37func main() {38 a = td.TD{1, 2}39 fmt.Println(a.Len())40}41import (42func main() {43 a = td.TD{1, 2}44 fmt.Println(a.Len())45}
Len
Using AI Code Generation
1import (2func main() {3 fmt.Println(strings.Count(str, "l"))4 fmt.Println(strings.Count(str, "ll"))5 fmt.Println(strings.Count(str, "o"))6 fmt.Println(strings.Count(str, "lo"))7 fmt.Println(strings.Count(str, "o "))8 fmt.Println(strings.Count(str, "o "))9 fmt.Println(strings.Count(str, " "))10 fmt.Println(strings.Count(str, ""))11 fmt.Println(strings.Count(str, "o l"))12}13import (14func main() {15 fmt.Println(strings.Count(str, "l"))16 fmt.Println(strings.Count(str, "ll"))17 fmt.Println(strings.Count(str, "o"))18 fmt.Println(strings.Count(str, "lo"))19 fmt.Println(strings.Count(str, "o "))20 fmt.Println(strings.Count(str, "o "))21 fmt.Println(strings.Count(str, " "))22 fmt.Println(strings.Count(str, ""))23 fmt.Println(strings.Count(str, "o l"))24}25import (26func main() {27 fmt.Println(strings.Count(str, "l"))28 fmt.Println(strings.Count(str, "ll"))29 fmt.Println(strings.Count(str, "o"))30 fmt.Println(strings.Count(str, "lo"))31 fmt.Println(strings.Count(str, "o "))32 fmt.Println(strings.Count(str, "o "))33 fmt.Println(strings.Count(str, " "))34 fmt.Println(strings.Count(str, ""))35 fmt.Println(strings.Count(str, "o l"))36}37import (38func main() {
Len
Using AI Code Generation
1import (2type td struct {3}4func (t td) Len() int {5}6func main() {7 t := td{1, 2}8 fmt.Println(t.Len())9}10import (11type td struct {12}13func (t td) Len() int {14}15func main() {16 t := td{1, 2}17 fmt.Println(t.Len())18}19import (20type td struct {21}22func (t td) Len() int {23}24func main() {25 t := td{1, 2}26 fmt.Println(t.Len())27}28import (29type td struct {30}31func (t td) Len() int {32}33func main() {34 t := td{1, 2}35 fmt.Println(t.Len())36}37import (38type td struct {39}40func (t td) Len() int {41}42func main() {43 t := td{1, 2}44 fmt.Println(t.Len())45}46import (47type td struct {48}49func (t td) Len() int {
Len
Using AI Code Generation
1import (2type td struct {3}4func (t td) Len() int {5}6func main() {7 t := td{3, 4}8 fmt.Println(t.Len())9}
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!!