How to use EXPECT method of source Package

Best Mock code snippet using source.EXPECT

historian_test.go

Source:historian_test.go Github

copy

Full Screen

1package historian_test2//3 // Copyright (c) 2019 ARM Limited.4 //5 // SPDX-License-Identifier: MIT6 //7 // Permission is hereby granted, free of charge, to any person obtaining a copy8 // of this software and associated documentation files (the "Software"), to9 // deal in the Software without restriction, including without limitation the10 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or11 // sell copies of the Software, and to permit persons to whom the Software is12 // furnished to do so, subject to the following conditions:13 //14 // The above copyright notice and this permission notice shall be included in all15 // copies or substantial portions of the Software.16 //17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE23 // SOFTWARE.24 //25import (26 "fmt"27 28 . "github.com/armPelionEdge/devicedb/historian"29 . "github.com/armPelionEdge/devicedb/storage"30 . "github.com/armPelionEdge/devicedb/util"31 . "github.com/onsi/ginkgo"32 . "github.com/onsi/gomega"33)34var _ = Describe("Historian", func() {35 var (36 storageEngine StorageDriver37 historian *Historian38 )39 40 BeforeEach(func() {41 storageEngine = MakeNewStorageDriver()42 storageEngine.Open()43 44 historian = NewHistorian(storageEngine, 101, 0, 1000)45 })46 47 AfterEach(func() {48 storageEngine.Close()49 })50 51 Context("There are 100 logged events of 4 different varieties in the history from three different sources", func() {52 BeforeEach(func() {53 for i := 0; i < 100; i += 1 {54 historian.LogEvent(&Event{55 Timestamp: uint64(i),56 SourceID: fmt.Sprintf("source-%d", (i % 3)),57 Type: fmt.Sprintf("type-%d", (i % 4)),58 Data: fmt.Sprintf("data-%d", i >> 4),59 })60 }61 })62 63 Describe("performing a query filtering only by time range", func() {64 It("should return only events that happened between [50, 100) after the purge", func() {65 Expect(historian.Purge(&HistoryQuery{ Before: 50 })).Should(BeNil())66 67 iter, err := historian.Query(&HistoryQuery{ })68 69 Expect(err).Should(BeNil())70 Expect(historian.LogSize()).Should(Equal(uint64(50)))71 Expect(historian.LogSerial()).Should(Equal(uint64(101)))72 73 for i := 50; i < 100; i += 1 {74 Expect(iter.Next()).Should(BeTrue())75 Expect(iter.Error()).Should(BeNil())76 Expect(iter.Event()).Should(Not(BeNil()))77 Expect(iter.Event().Timestamp).Should(Equal(uint64(i)))78 Expect(iter.Event().SourceID).Should(Equal(fmt.Sprintf("source-%d", (i % 3))))79 Expect(iter.Event().Type).Should(Equal(fmt.Sprintf("type-%d", (i % 4))))80 Expect(iter.Event().Data).Should(Equal(fmt.Sprintf("data-%d", (i >> 4))))81 }82 83 Expect(iter.Next()).Should(BeFalse())84 Expect(iter.Error()).Should(BeNil())85 Expect(iter.Event()).Should(BeNil())86 })87 88 It("should return only events that happened between [50, 100)", func() {89 var minSerial uint64 = 5090 iter, err := historian.Query(&HistoryQuery{ MinSerial: &minSerial })91 92 Expect(err).Should(BeNil())93 Expect(historian.LogSize()).Should(Equal(uint64(100)))94 Expect(historian.LogSerial()).Should(Equal(uint64(101)))95 96 for i := 49; i < 100; i += 1 {97 Expect(iter.Next()).Should(BeTrue())98 Expect(iter.Error()).Should(BeNil())99 Expect(iter.Event()).Should(Not(BeNil()))100 Expect(iter.Event().Timestamp).Should(Equal(uint64(i)))101 Expect(iter.Event().SourceID).Should(Equal(fmt.Sprintf("source-%d", (i % 3))))102 Expect(iter.Event().Type).Should(Equal(fmt.Sprintf("type-%d", (i % 4))))103 Expect(iter.Event().Data).Should(Equal(fmt.Sprintf("data-%d", (i >> 4))))104 }105 106 Expect(iter.Next()).Should(BeFalse())107 Expect(iter.Error()).Should(BeNil())108 Expect(iter.Event()).Should(BeNil())109 })110 111 It("should return ten events from least to most recent when a time range between [0, 10) is queried and an ascending order is specified implictly", func() {112 iter, err := historian.Query(&HistoryQuery{113 After: 0,114 Before: 10,115 })116 117 Expect(err).Should(BeNil())118 119 for i := 0; i < 10; i += 1 {120 Expect(iter.Next()).Should(BeTrue())121 Expect(iter.Error()).Should(BeNil())122 Expect(iter.Event()).Should(Not(BeNil()))123 Expect(iter.Event().Timestamp).Should(Equal(uint64(i)))124 Expect(iter.Event().SourceID).Should(Equal(fmt.Sprintf("source-%d", (i % 3))))125 Expect(iter.Event().Type).Should(Equal(fmt.Sprintf("type-%d", (i % 4))))126 Expect(iter.Event().Data).Should(Equal(fmt.Sprintf("data-%d", (i >> 4))))127 }128 129 Expect(iter.Next()).Should(BeFalse())130 Expect(iter.Error()).Should(BeNil())131 Expect(iter.Event()).Should(BeNil())132 })133 134 It("should return ten events from least to most recent when a time range between [0, 10) is queried and an ascending order is specified explicitly", func() {135 iter, err := historian.Query(&HistoryQuery{136 After: 0,137 Before: 10,138 Order: "asc",139 })140 141 Expect(err).Should(BeNil())142 143 for i := 0; i < 10; i += 1 {144 Expect(iter.Next()).Should(BeTrue())145 Expect(iter.Error()).Should(BeNil())146 Expect(iter.Event()).Should(Not(BeNil()))147 Expect(iter.Event().Timestamp).Should(Equal(uint64(i)))148 Expect(iter.Event().SourceID).Should(Equal(fmt.Sprintf("source-%d", (i % 3))))149 Expect(iter.Event().Type).Should(Equal(fmt.Sprintf("type-%d", (i % 4))))150 Expect(iter.Event().Data).Should(Equal(fmt.Sprintf("data-%d", (i >> 4))))151 }152 153 Expect(iter.Next()).Should(BeFalse())154 Expect(iter.Error()).Should(BeNil())155 Expect(iter.Event()).Should(BeNil())156 })157 158 It("should return ten events from most to least recent when a time range between [0, 10) is queried and a descending order is specified", func() {159 iter, err := historian.Query(&HistoryQuery{160 After: 0,161 Before: 10,162 Order: "desc",163 })164 165 Expect(err).Should(BeNil())166 167 for i := 9; i >= 0; i -= 1 {168 Expect(iter.Next()).Should(BeTrue())169 Expect(iter.Error()).Should(BeNil())170 Expect(iter.Event()).Should(Not(BeNil()))171 Expect(iter.Event().Timestamp).Should(Equal(uint64(i)))172 Expect(iter.Event().SourceID).Should(Equal(fmt.Sprintf("source-%d", (i % 3))))173 Expect(iter.Event().Type).Should(Equal(fmt.Sprintf("type-%d", (i % 4))))174 Expect(iter.Event().Data).Should(Equal(fmt.Sprintf("data-%d", (i >> 4))))175 }176 177 Expect(iter.Next()).Should(BeFalse())178 Expect(iter.Error()).Should(BeNil())179 Expect(iter.Event()).Should(BeNil())180 })181 })182 183 Describe("performing a query filtering only by source", func() {184 It("should return all events from source-0 in ascending order", func() {185 iter, err := historian.Query(&HistoryQuery{186 Sources: []string{ "source-0" },187 })188 189 Expect(err).Should(BeNil())190 191 for i := 0; i < 100; i += 1 {192 if i % 3 != 0 {193 continue194 }195 196 Expect(iter.Next()).Should(BeTrue())197 Expect(iter.Error()).Should(BeNil())198 Expect(iter.Event()).Should(Not(BeNil()))199 Expect(iter.Event().Timestamp).Should(Equal(uint64(i)))200 Expect(iter.Event().SourceID).Should(Equal(fmt.Sprintf("source-%d", (i % 3))))201 Expect(iter.Event().Type).Should(Equal(fmt.Sprintf("type-%d", (i % 4))))202 Expect(iter.Event().Data).Should(Equal(fmt.Sprintf("data-%d", (i >> 4))))203 }204 205 Expect(iter.Next()).Should(BeFalse())206 Expect(iter.Error()).Should(BeNil())207 Expect(iter.Event()).Should(BeNil())208 })209 210 It("should return all events from source-0 in ascending order", func() {211 iter, err := historian.Query(&HistoryQuery{212 Sources: []string{ "source-0" },213 Order: "asc",214 })215 216 Expect(err).Should(BeNil())217 218 for i := 0; i < 100; i += 1 {219 if i % 3 != 0 {220 continue221 }222 223 Expect(iter.Next()).Should(BeTrue())224 Expect(iter.Error()).Should(BeNil())225 Expect(iter.Event()).Should(Not(BeNil()))226 Expect(iter.Event().Timestamp).Should(Equal(uint64(i)))227 Expect(iter.Event().SourceID).Should(Equal(fmt.Sprintf("source-%d", (i % 3))))228 Expect(iter.Event().Type).Should(Equal(fmt.Sprintf("type-%d", (i % 4))))229 Expect(iter.Event().Data).Should(Equal(fmt.Sprintf("data-%d", (i >> 4))))230 }231 232 Expect(iter.Next()).Should(BeFalse())233 Expect(iter.Error()).Should(BeNil())234 Expect(iter.Event()).Should(BeNil())235 })236 237 It("should return all events from source-0 in descending order", func() {238 iter, err := historian.Query(&HistoryQuery{239 Sources: []string{ "source-0" },240 Order: "desc",241 })242 243 Expect(err).Should(BeNil())244 245 for i := 99; i >= 0; i -= 1 {246 if i % 3 != 0 {247 continue248 }249 250 Expect(iter.Next()).Should(BeTrue())251 Expect(iter.Error()).Should(BeNil())252 Expect(iter.Event()).Should(Not(BeNil()))253 Expect(iter.Event().Timestamp).Should(Equal(uint64(i)))254 Expect(iter.Event().SourceID).Should(Equal(fmt.Sprintf("source-%d", (i % 3))))255 Expect(iter.Event().Type).Should(Equal(fmt.Sprintf("type-%d", (i % 4))))256 Expect(iter.Event().Data).Should(Equal(fmt.Sprintf("data-%d", (i >> 4))))257 }258 259 Expect(iter.Next()).Should(BeFalse())260 Expect(iter.Error()).Should(BeNil())261 Expect(iter.Event()).Should(BeNil())262 })263 264 It("should return all events from source-0 and source-2 in ascending order", func() {265 iter, err := historian.Query(&HistoryQuery{266 Sources: []string{ "source-0", "source-2" },267 })268 269 Expect(err).Should(BeNil())270 271 for i := 0; i < 100; i += 1 {272 if i % 3 != 0 {273 continue274 }275 276 Expect(iter.Next()).Should(BeTrue())277 Expect(iter.Error()).Should(BeNil())278 Expect(iter.Event()).Should(Not(BeNil()))279 Expect(iter.Event().Timestamp).Should(Equal(uint64(i)))280 Expect(iter.Event().SourceID).Should(Equal(fmt.Sprintf("source-%d", (i % 3))))281 Expect(iter.Event().Type).Should(Equal(fmt.Sprintf("type-%d", (i % 4))))282 Expect(iter.Event().Data).Should(Equal(fmt.Sprintf("data-%d", (i >> 4))))283 }284 285 for i := 0; i < 100; i += 1 {286 if i % 3 != 2 {287 continue288 }289 290 Expect(iter.Next()).Should(BeTrue())291 Expect(iter.Error()).Should(BeNil())292 Expect(iter.Event()).Should(Not(BeNil()))293 Expect(iter.Event().Timestamp).Should(Equal(uint64(i)))294 Expect(iter.Event().SourceID).Should(Equal(fmt.Sprintf("source-%d", (i % 3))))295 Expect(iter.Event().Type).Should(Equal(fmt.Sprintf("type-%d", (i % 4))))296 Expect(iter.Event().Data).Should(Equal(fmt.Sprintf("data-%d", (i >> 4))))297 }298 299 Expect(iter.Next()).Should(BeFalse())300 Expect(iter.Error()).Should(BeNil())301 Expect(iter.Event()).Should(BeNil())302 })303 304 It("should return all events from source-0 and source-2 in ascending order", func() {305 iter, err := historian.Query(&HistoryQuery{306 Sources: []string{ "source-2", "source-0" },307 })308 309 Expect(err).Should(BeNil())310 311 for i := 0; i < 100; i += 1 {312 if i % 3 != 0 {313 continue314 }315 316 Expect(iter.Next()).Should(BeTrue())317 Expect(iter.Error()).Should(BeNil())318 Expect(iter.Event()).Should(Not(BeNil()))319 Expect(iter.Event().Timestamp).Should(Equal(uint64(i)))320 Expect(iter.Event().SourceID).Should(Equal(fmt.Sprintf("source-%d", (i % 3))))321 Expect(iter.Event().Type).Should(Equal(fmt.Sprintf("type-%d", (i % 4))))322 Expect(iter.Event().Data).Should(Equal(fmt.Sprintf("data-%d", (i >> 4))))323 }324 325 for i := 0; i < 100; i += 1 {326 if i % 3 != 2 {327 continue328 }329 330 Expect(iter.Next()).Should(BeTrue())331 Expect(iter.Error()).Should(BeNil())332 Expect(iter.Event()).Should(Not(BeNil()))333 Expect(iter.Event().Timestamp).Should(Equal(uint64(i)))334 Expect(iter.Event().SourceID).Should(Equal(fmt.Sprintf("source-%d", (i % 3))))335 Expect(iter.Event().Type).Should(Equal(fmt.Sprintf("type-%d", (i % 4))))336 Expect(iter.Event().Data).Should(Equal(fmt.Sprintf("data-%d", (i >> 4))))337 }338 339 Expect(iter.Next()).Should(BeFalse())340 Expect(iter.Error()).Should(BeNil())341 Expect(iter.Event()).Should(BeNil())342 })343 })344 345 Describe("performing a query filtering by source and time", func() {346 It("should return all events from source-0 and source-2 in ascending order between times [0, 50)", func() {347 iter, err := historian.Query(&HistoryQuery{348 Sources: []string{ "source-0", "source-2" },349 After: 0,350 Before: 50,351 })352 353 Expect(err).Should(BeNil())354 355 for i := 0; i < 50; i += 1 {356 if i % 3 != 0 {357 continue358 }359 360 Expect(iter.Next()).Should(BeTrue())361 Expect(iter.Error()).Should(BeNil())362 Expect(iter.Event()).Should(Not(BeNil()))363 Expect(iter.Event().Timestamp).Should(Equal(uint64(i)))364 Expect(iter.Event().SourceID).Should(Equal(fmt.Sprintf("source-%d", (i % 3))))365 Expect(iter.Event().Type).Should(Equal(fmt.Sprintf("type-%d", (i % 4))))366 Expect(iter.Event().Data).Should(Equal(fmt.Sprintf("data-%d", (i >> 4))))367 }368 369 for i := 0; i < 50; i += 1 {370 if i % 3 != 2 {371 continue372 }373 374 Expect(iter.Next()).Should(BeTrue())375 Expect(iter.Error()).Should(BeNil())376 Expect(iter.Event()).Should(Not(BeNil()))377 Expect(iter.Event().Timestamp).Should(Equal(uint64(i)))378 Expect(iter.Event().SourceID).Should(Equal(fmt.Sprintf("source-%d", (i % 3))))379 Expect(iter.Event().Type).Should(Equal(fmt.Sprintf("type-%d", (i % 4))))380 Expect(iter.Event().Data).Should(Equal(fmt.Sprintf("data-%d", (i >> 4))))381 }382 383 Expect(iter.Next()).Should(BeFalse())384 Expect(iter.Error()).Should(BeNil())385 Expect(iter.Event()).Should(BeNil())386 })387 })388 389 Describe("performing a query filtering by source, time and data", func() {390 It("should return all events from source-0 and source-2 in ascending order between times [0, 50) whose data is data-0", func() {391 var data = "data-0"392 393 iter, err := historian.Query(&HistoryQuery{394 Sources: []string{ "source-0", "source-2" },395 After: 0,396 Before: 50,397 Data: &data,398 })399 400 Expect(err).Should(BeNil())401 402 for i := 0; i < 50; i += 1 {403 if i % 3 != 0 || i >> 4 != 0 {404 continue405 }406 407 Expect(iter.Next()).Should(BeTrue())408 Expect(iter.Error()).Should(BeNil())409 Expect(iter.Event()).Should(Not(BeNil()))410 Expect(iter.Event().Timestamp).Should(Equal(uint64(i)))411 Expect(iter.Event().SourceID).Should(Equal(fmt.Sprintf("source-%d", (i % 3))))412 Expect(iter.Event().Type).Should(Equal(fmt.Sprintf("type-%d", (i % 4))))413 Expect(iter.Event().Data).Should(Equal(fmt.Sprintf("data-%d", (i >> 4))))414 }415 416 for i := 0; i < 50; i += 1 {417 if i % 3 != 2 || i >> 4 != 0 {418 continue419 }420 421 Expect(iter.Next()).Should(BeTrue())422 Expect(iter.Error()).Should(BeNil())423 Expect(iter.Event()).Should(Not(BeNil()))424 Expect(iter.Event().Timestamp).Should(Equal(uint64(i)))425 Expect(iter.Event().SourceID).Should(Equal(fmt.Sprintf("source-%d", (i % 3))))426 Expect(iter.Event().Type).Should(Equal(fmt.Sprintf("type-%d", (i % 4))))427 Expect(iter.Event().Data).Should(Equal(fmt.Sprintf("data-%d", (i >> 4))))428 }429 430 Expect(iter.Next()).Should(BeFalse())431 Expect(iter.Error()).Should(BeNil())432 Expect(iter.Event()).Should(BeNil())433 })434 })435 })436})...

Full Screen

Full Screen

fsstore_test.go

Source:fsstore_test.go Github

copy

Full Screen

1/*2Copyright 2017 The Kubernetes Authors.3Licensed under the Apache License, Version 2.0 (the "License");4you may not use this file except in compliance with the License.5You may obtain a copy of the License at6 http://www.apache.org/licenses/LICENSE-2.07Unless required by applicable law or agreed to in writing, software8distributed under the License is distributed on an "AS IS" BASIS,9WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.10See the License for the specific language governing permissions and11limitations under the License.12*/13package store14import (15 "fmt"16 "io/ioutil"17 "path/filepath"18 "reflect"19 "testing"20 "time"21 "github.com/davecgh/go-spew/spew"22 apiv1 "k8s.io/api/core/v1"23 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"24 "k8s.io/apimachinery/pkg/types"25 "k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig"26 "k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig/scheme"27 "k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig/v1beta1"28 "k8s.io/kubernetes/pkg/kubelet/kubeletconfig/checkpoint"29 utilcodec "k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/codec"30 utilfiles "k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/files"31 utiltest "k8s.io/kubernetes/pkg/kubelet/kubeletconfig/util/test"32 utilfs "k8s.io/kubernetes/pkg/util/filesystem"33)34var testdir string35func init() {36 tmp, err := ioutil.TempDir("", "fsstore-test")37 if err != nil {38 panic(err)39 }40 testdir = tmp41}42func newInitializedFakeFsStore() (*fsStore, error) {43 // Test with the default filesystem, the fake filesystem has an issue caused by afero: https://github.com/spf13/afero/issues/14144 // The default filesystem also behaves more like production, so we should probably not mock the filesystem for unit tests.45 fs := utilfs.DefaultFs{}46 tmpdir, err := fs.TempDir(testdir, "store-")47 if err != nil {48 return nil, err49 }50 store := NewFsStore(fs, tmpdir)51 if err := store.Initialize(); err != nil {52 return nil, err53 }54 return store.(*fsStore), nil55}56func TestFsStoreInitialize(t *testing.T) {57 store, err := newInitializedFakeFsStore()58 if err != nil {59 t.Fatalf("fsStore.Initialize() failed with error: %v", err)60 }61 // check that store.dir exists62 if _, err := store.fs.Stat(store.dir); err != nil {63 t.Fatalf("expect %q to exist, but stat failed with error: %v", store.dir, err)64 }65 // check that meta dir exists66 if _, err := store.fs.Stat(store.metaPath("")); err != nil {67 t.Fatalf("expect %q to exist, but stat failed with error: %v", store.metaPath(""), err)68 }69 // check that checkpoints dir exists70 if _, err := store.fs.Stat(store.checkpointPath("")); err != nil {71 t.Fatalf("expect %q to exist, but stat failed with error: %v", store.checkpointPath(""), err)72 }73 // check that currentFile exists74 if _, err := store.fs.Stat(store.metaPath(currentFile)); err != nil {75 t.Fatalf("expect %q to exist, but stat failed with error: %v", store.metaPath(currentFile), err)76 }77 // check that lastKnownGoodFile exists78 if _, err := store.fs.Stat(store.metaPath(lastKnownGoodFile)); err != nil {79 t.Fatalf("expect %q to exist, but stat failed with error: %v", store.metaPath(lastKnownGoodFile), err)80 }81}82func TestFsStoreExists(t *testing.T) {83 store, err := newInitializedFakeFsStore()84 if err != nil {85 t.Fatalf("error constructing store: %v", err)86 }87 // checkpoint a payload88 const uid = "uid"89 p, err := checkpoint.NewConfigMapPayload(&apiv1.ConfigMap{ObjectMeta: metav1.ObjectMeta{UID: uid}})90 if err != nil {91 t.Fatalf("could not construct checkpoint, error: %v", err)92 }93 store.Save(p)94 cases := []struct {95 desc string96 uid types.UID97 expect bool98 err string99 }{100 {"exists", uid, true, ""},101 {"does not exist", "bogus-uid", false, ""},102 }103 for _, c := range cases {104 t.Run(c.desc, func(t *testing.T) {105 source, _, err := checkpoint.NewRemoteConfigSource(&apiv1.NodeConfigSource{106 ConfigMapRef: &apiv1.ObjectReference{Name: "name", Namespace: "namespace", UID: c.uid}})107 if err != nil {108 t.Fatalf("error constructing remote config source: %v", err)109 }110 ok, err := store.Exists(source)111 utiltest.ExpectError(t, err, c.err)112 if err != nil {113 return114 }115 if c.expect != ok {116 t.Errorf("expect %t but got %t", c.expect, ok)117 }118 })119 }120}121func TestFsStoreSave(t *testing.T) {122 store, err := newInitializedFakeFsStore()123 if err != nil {124 t.Fatalf("error constructing store: %v", err)125 }126 nameTooLong := func() string {127 s := ""128 for i := 0; i < 256; i++ {129 s += "a"130 }131 return s132 }()133 cases := []struct {134 desc string135 files map[string]string136 err string137 }{138 {"valid payload", map[string]string{"foo": "foocontent", "bar": "barcontent"}, ""},139 {"empty key name", map[string]string{"": "foocontent"}, "must not be empty"},140 {"key name is not a base file name (foo/bar)", map[string]string{"foo/bar": "foocontent"}, "only base names are allowed"},141 {"key name is not a base file name (/foo)", map[string]string{"/bar": "foocontent"}, "only base names are allowed"},142 {"used .", map[string]string{".": "foocontent"}, "may not be '.' or '..'"},143 {"used ..", map[string]string{"..": "foocontent"}, "may not be '.' or '..'"},144 {"length violation", map[string]string{nameTooLong: "foocontent"}, "must be less than 255 characters"},145 }146 for _, c := range cases {147 t.Run(c.desc, func(t *testing.T) {148 // construct the payload149 p, err := checkpoint.NewConfigMapPayload(&apiv1.ConfigMap{150 ObjectMeta: metav1.ObjectMeta{UID: "uid"},151 Data: c.files,152 })153 if err != nil {154 t.Fatalf("error constructing payload: %v", err)155 }156 // save the payload157 err = store.Save(p)158 utiltest.ExpectError(t, err, c.err)159 if err != nil {160 return161 }162 // read the saved checkpoint163 m, err := mapFromCheckpoint(store, p.UID())164 if err != nil {165 t.Fatalf("error loading checkpoint to map: %v", err)166 }167 // compare our expectation to what got saved168 expect := p.Files()169 if !reflect.DeepEqual(expect, m) {170 t.Errorf("expect %v, but got %v", expect, m)171 }172 })173 }174}175func TestFsStoreLoad(t *testing.T) {176 store, err := newInitializedFakeFsStore()177 if err != nil {178 t.Fatalf("error constructing store: %v", err)179 }180 // encode a kubelet configuration that has all defaults set181 expect, err := newKubeletConfiguration()182 if err != nil {183 t.Fatalf("error constructing KubeletConfiguration: %v", err)184 }185 data, err := utilcodec.EncodeKubeletConfig(expect, v1beta1.SchemeGroupVersion)186 if err != nil {187 t.Fatalf("error encoding KubeletConfiguration: %v", err)188 }189 // construct a payload that contains the kubeletconfig190 const uid = "uid"191 p, err := checkpoint.NewConfigMapPayload(&apiv1.ConfigMap{192 ObjectMeta: metav1.ObjectMeta{UID: types.UID(uid)},193 Data: map[string]string{194 kubeletKey: string(data),195 },196 })197 if err != nil {198 t.Fatalf("error constructing payload: %v", err)199 }200 // save the payload201 err = store.Save(p)202 if err != nil {203 t.Fatalf("error saving payload: %v", err)204 }205 cases := []struct {206 desc string207 uid types.UID208 err string209 }{210 {"checkpoint exists", uid, ""},211 {"checkpoint does not exist", "bogus-uid", "no checkpoint for source"},212 }213 for _, c := range cases {214 t.Run(c.desc, func(t *testing.T) {215 source, _, err := checkpoint.NewRemoteConfigSource(&apiv1.NodeConfigSource{216 ConfigMapRef: &apiv1.ObjectReference{Name: "name", Namespace: "namespace", UID: c.uid}})217 if err != nil {218 t.Fatalf("error constructing remote config source: %v", err)219 }220 loaded, err := store.Load(source)221 utiltest.ExpectError(t, err, c.err)222 if err != nil {223 return224 }225 if !reflect.DeepEqual(expect, loaded) {226 t.Errorf("expect %#v, but got %#v", expect, loaded)227 }228 })229 }230}231func TestFsStoreCurrentModified(t *testing.T) {232 store, err := newInitializedFakeFsStore()233 if err != nil {234 t.Fatalf("error constructing store: %v", err)235 }236 // create an empty current file, this is good enough for testing237 saveTestSourceFile(t, store, currentFile, nil)238 // set the timestamps to the current time, so we can compare to result of store.CurrentModified239 now := time.Now()240 err = store.fs.Chtimes(store.metaPath(currentFile), now, now)241 if err != nil {242 t.Fatalf("could not change timestamps, error: %v", err)243 }244 // for now we hope that the system won't truncate the time to a less precise unit,245 // if this test fails on certain systems that may be the reason.246 modTime, err := store.CurrentModified()247 if err != nil {248 t.Fatalf("unable to determine modification time of current config source, error: %v", err)249 }250 if !now.Equal(modTime) {251 t.Errorf("expect %q but got %q", now.Format(time.RFC3339), modTime.Format(time.RFC3339))252 }253}254func TestFsStoreCurrent(t *testing.T) {255 store, err := newInitializedFakeFsStore()256 if err != nil {257 t.Fatalf("error constructing store: %v", err)258 }259 source, _, err := checkpoint.NewRemoteConfigSource(&apiv1.NodeConfigSource{260 ConfigMapRef: &apiv1.ObjectReference{Name: "name", Namespace: "namespace", UID: "uid"}})261 if err != nil {262 t.Fatalf("unexpected error: %v", err)263 }264 cases := []struct {265 desc string266 expect checkpoint.RemoteConfigSource267 err string268 }{269 {"default source", nil, ""},270 {"non-default source", source, ""},271 }272 for _, c := range cases {273 t.Run(c.desc, func(t *testing.T) {274 // save the last known good source275 saveTestSourceFile(t, store, currentFile, c.expect)276 // load last-known-good and compare to expected result277 source, err := store.Current()278 utiltest.ExpectError(t, err, c.err)279 if err != nil {280 return281 }282 if !checkpoint.EqualRemoteConfigSources(c.expect, source) {283 t.Errorf("case %q, expect %q but got %q", spew.Sdump(c.expect), spew.Sdump(c.expect), spew.Sdump(source))284 }285 })286 }287}288func TestFsStoreLastKnownGood(t *testing.T) {289 store, err := newInitializedFakeFsStore()290 if err != nil {291 t.Fatalf("error constructing store: %v", err)292 }293 source, _, err := checkpoint.NewRemoteConfigSource(&apiv1.NodeConfigSource{294 ConfigMapRef: &apiv1.ObjectReference{Name: "name", Namespace: "namespace", UID: "uid"}})295 if err != nil {296 t.Fatalf("unexpected error: %v", err)297 }298 cases := []struct {299 desc string300 expect checkpoint.RemoteConfigSource301 err string302 }{303 {"default source", nil, ""},304 {"non-default source", source, ""},305 }306 for _, c := range cases {307 t.Run(c.desc, func(t *testing.T) {308 // save the last known good source309 saveTestSourceFile(t, store, lastKnownGoodFile, c.expect)310 // load last-known-good and compare to expected result311 source, err := store.LastKnownGood()312 utiltest.ExpectError(t, err, c.err)313 if err != nil {314 return315 }316 if !checkpoint.EqualRemoteConfigSources(c.expect, source) {317 t.Errorf("case %q, expect %q but got %q", spew.Sdump(c.expect), spew.Sdump(c.expect), spew.Sdump(source))318 }319 })320 }321}322func TestFsStoreSetCurrent(t *testing.T) {323 store, err := newInitializedFakeFsStore()324 if err != nil {325 t.Fatalf("error constructing store: %v", err)326 }327 const uid = "uid"328 expect := fmt.Sprintf(`apiVersion: v1329configMapRef:330 name: name331 namespace: namespace332 uid: %s333kind: NodeConfigSource334`, uid)335 source, _, err := checkpoint.NewRemoteConfigSource(&apiv1.NodeConfigSource{ConfigMapRef: &apiv1.ObjectReference{336 Name: "name", Namespace: "namespace", UID: types.UID(uid)}})337 if err != nil {338 t.Fatalf("unexpected error: %v", err)339 }340 // save the current source341 if err := store.SetCurrent(source); err != nil {342 t.Fatalf("unexpected error: %v", err)343 }344 // check that the source saved as we would expect345 data := readTestSourceFile(t, store, currentFile)346 if expect != string(data) {347 t.Errorf("expect current source file to contain %q, but got %q", expect, string(data))348 }349}350func TestFsStoreSetLastKnownGood(t *testing.T) {351 store, err := newInitializedFakeFsStore()352 if err != nil {353 t.Fatalf("error constructing store: %v", err)354 }355 const uid = "uid"356 expect := fmt.Sprintf(`apiVersion: v1357configMapRef:358 name: name359 namespace: namespace360 uid: %s361kind: NodeConfigSource362`, uid)363 source, _, err := checkpoint.NewRemoteConfigSource(&apiv1.NodeConfigSource{ConfigMapRef: &apiv1.ObjectReference{364 Name: "name", Namespace: "namespace", UID: types.UID(uid)}})365 if err != nil {366 t.Fatalf("unexpected error: %v", err)367 }368 // save the last known good source369 if err := store.SetLastKnownGood(source); err != nil {370 t.Fatalf("unexpected error: %v", err)371 }372 // check that the source saved as we would expect373 data := readTestSourceFile(t, store, lastKnownGoodFile)374 if expect != string(data) {375 t.Errorf("expect last-known-good source file to contain %q, but got %q", expect, string(data))376 }377}378func TestFsStoreReset(t *testing.T) {379 store, err := newInitializedFakeFsStore()380 if err != nil {381 t.Fatalf("error constructing store: %v", err)382 }383 source, _, err := checkpoint.NewRemoteConfigSource(&apiv1.NodeConfigSource{ConfigMapRef: &apiv1.ObjectReference{Name: "name", Namespace: "namespace", UID: "uid"}})384 if err != nil {385 t.Fatalf("unexpected error: %v", err)386 }387 otherSource, _, err := checkpoint.NewRemoteConfigSource(&apiv1.NodeConfigSource{ConfigMapRef: &apiv1.ObjectReference{Name: "other-name", Namespace: "namespace", UID: "other-uid"}})388 if err != nil {389 t.Fatalf("unexpected error: %v", err)390 }391 cases := []struct {392 desc string393 current checkpoint.RemoteConfigSource394 lastKnownGood checkpoint.RemoteConfigSource395 updated bool396 }{397 {"nil -> nil", nil, nil, false},398 {"source -> nil", source, nil, true},399 {"nil -> source", nil, source, false},400 {"source -> source", source, source, true},401 {"source -> otherSource", source, otherSource, true},402 {"otherSource -> source", otherSource, source, true},403 }404 for _, c := range cases {405 t.Run(c.desc, func(t *testing.T) {406 // manually save the sources to their respective files407 saveTestSourceFile(t, store, currentFile, c.current)408 saveTestSourceFile(t, store, lastKnownGoodFile, c.lastKnownGood)409 // reset410 updated, err := store.Reset()411 if err != nil {412 t.Fatalf("unexpected error: %v", err)413 }414 // make sure the files were emptied415 if size := testSourceFileSize(t, store, currentFile); size > 0 {416 t.Errorf("case %q, expect source file %q to be empty but got %d bytes", c.desc, currentFile, size)417 }418 if size := testSourceFileSize(t, store, lastKnownGoodFile); size > 0 {419 t.Errorf("case %q, expect source file %q to be empty but got %d bytes", c.desc, lastKnownGoodFile, size)420 }421 // make sure Current() and LastKnownGood() both return nil422 current, err := store.Current()423 if err != nil {424 t.Fatalf("unexpected error: %v", err)425 }426 lastKnownGood, err := store.LastKnownGood()427 if err != nil {428 t.Fatalf("unexpected error: %v", err)429 }430 if current != nil || lastKnownGood != nil {431 t.Errorf("case %q, expect nil for current and last-known-good checkpoints, but still have %q and %q, respectively",432 c.desc, current, lastKnownGood)433 }434 if c.updated != updated {435 t.Errorf("case %q, expect reset to return %t, but got %t", c.desc, c.updated, updated)436 }437 })438 }439}440func TestFsStoreReadRemoteConfigSource(t *testing.T) {441 store, err := newInitializedFakeFsStore()442 if err != nil {443 t.Fatalf("error constructing store: %v", err)444 }445 source, _, err := checkpoint.NewRemoteConfigSource(&apiv1.NodeConfigSource{446 ConfigMapRef: &apiv1.ObjectReference{Name: "name", Namespace: "namespace", UID: "uid"}})447 if err != nil {448 t.Fatalf("unexpected error: %v", err)449 }450 cases := []struct {451 desc string452 expect checkpoint.RemoteConfigSource453 err string454 }{455 {"default source", nil, ""},456 {"non-default source", source, ""},457 }458 const name = "some-source-file"459 for _, c := range cases {460 t.Run(c.desc, func(t *testing.T) {461 saveTestSourceFile(t, store, name, c.expect)462 source, err := readRemoteConfigSource(store.fs, store.metaPath(name))463 utiltest.ExpectError(t, err, c.err)464 if err != nil {465 return466 }467 if !checkpoint.EqualRemoteConfigSources(c.expect, source) {468 t.Errorf("case %q, expect %q but got %q", spew.Sdump(c.expect), spew.Sdump(c.expect), spew.Sdump(source))469 }470 })471 }472}473func TestFsStoreWriteRemoteConfigSource(t *testing.T) {474 store, err := newInitializedFakeFsStore()475 if err != nil {476 t.Fatalf("error constructing store: %v", err)477 }478 source, _, err := checkpoint.NewRemoteConfigSource(&apiv1.NodeConfigSource{ConfigMapRef: &apiv1.ObjectReference{Name: "name", Namespace: "namespace", UID: "uid"}})479 if err != nil {480 t.Fatalf("unexpected error: %v", err)481 }482 cases := []struct {483 desc string484 source checkpoint.RemoteConfigSource485 }{486 {"nil source", nil},487 {"non-nil source", source},488 }489 const name = "some-source-file"490 for _, c := range cases {491 t.Run(c.desc, func(t *testing.T) {492 // set the source file493 err := writeRemoteConfigSource(store.fs, store.metaPath(name), c.source)494 if err != nil {495 t.Fatalf("unable to set source file, error: %v", err)496 }497 // read back the file498 data := readTestSourceFile(t, store, name)499 str := string(data)500 if c.source != nil {501 // expect the contents to match the encoding of the source502 data, err := c.source.Encode()503 expect := string(data)504 if err != nil {505 t.Fatalf("couldn't encode source, error: %v", err)506 }507 if expect != str {508 t.Errorf("case %q, expect %q but got %q", spew.Sdump(c.source), expect, str)509 }510 } else {511 // expect empty file512 expect := ""513 if expect != str {514 t.Errorf("case %q, expect %q but got %q", spew.Sdump(c.source), expect, str)515 }516 }517 })518 }519}520func mapFromCheckpoint(store *fsStore, uid string) (map[string]string, error) {521 files, err := store.fs.ReadDir(store.checkpointPath(uid))522 if err != nil {523 return nil, err524 }525 m := map[string]string{}526 for _, f := range files {527 // expect no subdirs, only regular files528 if !f.Mode().IsRegular() {529 return nil, fmt.Errorf("expect only regular files in checkpoint dir %q", uid)530 }531 // read the file contents and build the map532 data, err := store.fs.ReadFile(filepath.Join(store.checkpointPath(uid), f.Name()))533 if err != nil {534 return nil, err535 }536 m[f.Name()] = string(data)537 }538 return m, nil539}540func readTestSourceFile(t *testing.T, store *fsStore, relPath string) []byte {541 data, err := store.fs.ReadFile(store.metaPath(relPath))542 if err != nil {543 t.Fatalf("unable to read test source file, error: %v", err)544 }545 return data546}547func saveTestSourceFile(t *testing.T, store *fsStore, relPath string, source checkpoint.RemoteConfigSource) {548 if source != nil {549 data, err := source.Encode()550 if err != nil {551 t.Fatalf("unable to save test source file, error: %v", err)552 }553 err = utilfiles.ReplaceFile(store.fs, store.metaPath(relPath), data)554 if err != nil {555 t.Fatalf("unable to save test source file, error: %v", err)556 }557 } else {558 err := utilfiles.ReplaceFile(store.fs, store.metaPath(relPath), []byte{})559 if err != nil {560 t.Fatalf("unable to save test source file, error: %v", err)561 }562 }563}564func testSourceFileSize(t *testing.T, store *fsStore, relPath string) int64 {565 info, err := store.fs.Stat(store.metaPath(relPath))566 if err != nil {567 t.Fatalf("unexpected error: %v", err)568 }569 return info.Size()570}571// newKubeletConfiguration will create a new KubeletConfiguration with default values set572func newKubeletConfiguration() (*kubeletconfig.KubeletConfiguration, error) {573 s, _, err := scheme.NewSchemeAndCodecs()574 if err != nil {575 return nil, err576 }577 versioned := &v1beta1.KubeletConfiguration{}578 s.Default(versioned)579 config := &kubeletconfig.KubeletConfiguration{}580 if err := s.Convert(versioned, config, nil); err != nil {581 return nil, err582 }583 return config, nil584}...

Full Screen

Full Screen

unit_test.go

Source:unit_test.go Github

copy

Full Screen

1package parser2import (3 . "github.com/onsi/ginkgo"4 . "github.com/onsi/gomega"5 "github.com/jBugman/fun-lang/func-parse/fun"6 "github.com/jBugman/fun-lang/func-parse/fun/code"7)8var _ = Describe("parseExpression", func() {9 It("parses 'foo'", func() {10 source := newScanner("foo")11 x, s, err := parseExpression(source)12 Expect(err).ShouldNot(HaveOccurred())13 Expect(x).To(Equal(14 fun.ID("foo", pos(1, 1)),15 ))16 Expect(s.pos).To(Equal(17 pos(1, 4),18 ))19 Expect(s.cursor).To(Equal(3))20 })21 It("parses 'foo bar'", func() {22 source := newScanner("foo bar")23 x, s, err := parseExpression(source)24 Expect(err).ShouldNot(HaveOccurred())25 Expect(x).To(Equal(26 fun.ID("foo", pos(1, 1)),27 ))28 Expect(s.pos).To(Equal(29 pos(1, 5),30 ))31 Expect(s.cursor).To(Equal(4))32 })33})34var _ = Describe("parseIdent", func() {35 It("parses 'foo bar'", func() {36 source := newScanner("foo bar")37 x, s, err := parseIdent(source)38 Expect(err).ShouldNot(HaveOccurred())39 Expect(x).To(Equal(40 fun.ID("foo", pos(1, 1)),41 ))42 Expect(s.pos).To(Equal(43 pos(1, 4),44 ))45 Expect(s.cursor).To(Equal(3))46 })47 It("parses 'foo\\n\\nbar'", func() {48 source := newScanner("foo\n\nbar")49 x, s, err := parseIdent(source)50 Expect(err).ShouldNot(HaveOccurred())51 Expect(x).To(Equal(52 fun.ID("foo", pos(1, 1)),53 ))54 Expect(s.pos).To(Equal(55 pos(1, 4),56 ))57 Expect(s.cursor).To(Equal(3))58 })59 It("fails on non-letter first char", func() {60 source := newScanner("99bottles")61 _, s, err := parseIdent(source)62 Expect(err).Should(HaveOccurred())63 Expect(err).To(MatchError("expected letter or '_', found '9'"))64 Expect(err.Pos()).To(Equal(pos(1, 1)))65 Expect(s.pos).To(Equal(pos(1, 1)))66 Expect(s.cursor).To(Equal(0))67 })68})69var _ = Describe("skipSpace", func() {70 It("skips space", func() {71 source := newScanner(" \n\nbar")72 s := skipSpace(source)73 Expect(s.pos).To(Equal(74 pos(3, 1),75 ))76 Expect(s.cursor).To(Equal(4))77 })78})79var _ = Describe("parseList", func() {80 It("parses ()", func() {81 source := newScanner("()")82 x, s, err := parseList(source)83 Expect(err).ShouldNot(HaveOccurred())84 Expect(x).To(Equal(85 fun.LL(nil, pos(1, 1)),86 ))87 Expect(s.pos).To(Equal(88 pos(1, 3)))89 Expect(s.cursor).To(Equal(2))90 })91 It("parses (foo)", func() {92 source := newScanner("(foo)")93 x, s, err := parseList(source)94 Expect(err).ShouldNot(HaveOccurred())95 Expect(x).To(Equal(96 fun.L(pos(1, 1),97 fun.ID("foo", pos(1, 2)),98 ),99 ))100 Expect(s.pos).To(Equal(101 pos(1, 6),102 ))103 Expect(s.cursor).To(Equal(5))104 })105 It("parses (foo bar)", func() {106 source := newScanner("(foo bar)")107 x, s, err := parseList(source)108 Expect(err).ShouldNot(HaveOccurred())109 Expect(x).To(Equal(110 fun.L(pos(1, 1),111 fun.ID("foo", pos(1, 2)),112 fun.ID("bar", pos(1, 6)),113 ),114 ))115 Expect(s.pos).To(Equal(116 pos(1, 10),117 ))118 Expect(s.cursor).To(Equal(9))119 })120 It("parses (foo ())", func() {121 source := newScanner("(foo ())")122 x, s, err := parseList(source)123 Expect(err).ShouldNot(HaveOccurred())124 Expect(x).To(Equal(125 fun.L(pos(1, 1),126 fun.ID("foo", pos(1, 2)),127 fun.LL(nil, pos(1, 6)),128 ),129 ))130 Expect(s.pos).To(Equal(131 pos(1, 9),132 ))133 Expect(s.cursor).To(Equal(8))134 })135 It("parses (foo (a))", func() {136 source := newScanner("(foo (a))")137 x, s, err := parseList(source)138 Expect(err).ShouldNot(HaveOccurred())139 Expect(x).To(Equal(140 fun.L(pos(1, 1),141 fun.ID("foo", pos(1, 2)),142 fun.L(pos(1, 6),143 fun.ID("a", pos(1, 7)),144 ),145 ),146 ))147 Expect(s.pos).To(Equal(148 pos(1, 10),149 ))150 Expect(s.cursor).To(Equal(9))151 })152})153var _ = Describe("parseChar", func() {154 It("parses tick char", func() {155 source := newScanner(`'\''`)156 x, s, err := parseChar(source)157 Expect(err).ShouldNot(HaveOccurred())158 Expect(x).To(Equal(159 fun.CL(`\'`, pos(1, 1)),160 ))161 Expect(s.pos).To(Equal(162 pos(1, 5),163 ))164 Expect(s.cursor).To(Equal(4))165 })166 It("parses newline char", func() {167 source := newScanner(`'\n'`)168 x, s, err := parseChar(source)169 Expect(err).ShouldNot(HaveOccurred())170 Expect(x).To(Equal(171 fun.CL(`\n`, pos(1, 1)),172 ))173 Expect(s.pos).To(Equal(174 pos(1, 5),175 ))176 Expect(s.cursor).To(Equal(4))177 })178})179var _ = Describe("parseString", func() {180 It("fails on unclosed string", func() {181 source := newScanner(`"asd`)182 _, s, err := parseString(source)183 Expect(err).Should(HaveOccurred())184 Expect(err).To(MatchError("expected '\"', found EOF"))185 Expect(err.Pos()).To(Equal(pos(1, 5)))186 Expect(s.pos).To(Equal(pos(1, 1)))187 Expect(s.cursor).To(Equal(0))188 })189})190func pos(line, col int) code.Pos {191 return code.Pos{192 Line: line,193 Col: col,194 }195}...

Full Screen

Full Screen

EXPECT

Using AI Code Generation

copy

Full Screen

1import "github.com/onsi/gomega"2import "github.com/onsi/gomega/gstruct"3func test() {4 gomega.Expect(source).To(gstruct.MatchAllFields(gstruct.Fields{5 "Name": gomega.Equal("foo"),6 "Age": gomega.BeNumerically(">", 0),7 }))8}9import "github.com/onsi/gomega"10import "github.com/onsi/gomega/gstruct"11func test() {12 gomega.Expect(source).To(gstruct.MatchAllFields(gstruct.Fields{13 "Name": gomega.Equal("foo"),14 "Age": gomega.BeNumerically(">", 0),15 }))16}17import "github.com/onsi/gomega"18import "github.com/onsi/gomega/gstruct"19func test() {20 gomega.Expect(source).To(gstruct.MatchAllFields(gstruct.Fields{21 "Name": gomega.Equal("foo"),22 "Age": gomega.BeNumerically(">", 0),23 }))24}25import "github.com/onsi/gomega"26import "github.com/onsi/gomega/gstruct"27func test() {28 gomega.Expect(source).To(gstruct.MatchAllFields(gstruct.Fields{29 "Name": gomega.Equal("foo"),30 "Age": gomega.BeNumerically(">", 0),31 }))32}33import "github.com/onsi/gomega"34import "github.com/onsi/gomega/gstruct"35func test() {36 gomega.Expect(source).To(gstruct.MatchAllFields(gstruct.Fields{37 "Name": gomega.Equal("foo"),38 "Age": gomega.BeNumerically(">", 0),39 }))40}41import "github.com/onsi/gomega"42import "github.com/onsi/gomega/gstruct"43func test() {44 gomega.Expect(source).To(gstruct.MatchAllFields(gstruct.Fields{45 "Name": gomega.Equal("foo"),46 "Age": gomega.BeNumerically("

Full Screen

Full Screen

EXPECT

Using AI Code Generation

copy

Full Screen

1 source.EXPECT().Get(1).Return(1)2 destination.EXPECT().Put(1).Return(nil)3 source.EXPECT().Get(1).Return(1)4 destination.EXPECT().Put(1).Return(nil)5 source.EXPECT().Get(1).Return(1)6 destination.EXPECT().Put(1).Return(nil)7 source.EXPECT().Get(1).Return(1)8 destination.EXPECT().Put(1).Return(nil)9 source.EXPECT().Get(1).Return(1)10 destination.EXPECT().Put(1).Return(nil)11 source.EXPECT().Get(1).Return(1)12 destination.EXPECT().Put(1).Return(nil)13 source.EXPECT().Get(1).Return(1)14 destination.EXPECT().Put(1).Return(nil)15 source.EXPECT().Get(1).Return(1)16 destination.EXPECT().Put(1).Return(nil)17 source.EXPECT().Get(1).Return(1)18 destination.EXPECT().Put(1).Return(nil)19 source.EXPECT().Get(1).Return(1)20 destination.EXPECT().Put(

Full Screen

Full Screen

EXPECT

Using AI Code Generation

copy

Full Screen

1import (2func TestExpect(t *testing.T) {3 fmt.Println("TestExpect")4 source.Expect(1)5}6import (7type Source struct{}8func (s *Source) Expect(x int) {9 fmt.Println("Expect")10}11import (12func TestExpect(t *testing.T) {13 fmt.Println("TestExpect")14 source := new(Source)15 source.Expect(1)16}17import (18type Source struct{}19func (s *Source) Expect(x int) {20 fmt.Println("Expect")21}22import (23func TestExpect(t *testing.T) {24 fmt.Println("TestExpect")25 source := &Source{}26 source.Expect(1)27}28import (29type Source struct{}30func (s *Source) Expect(x int) {31 fmt.Println("Expect")32}33import (34func TestExpect(t *testing.T) {35 fmt.Println("TestExpect")36 source := &Source{}37 source.Expect(1)38}39import (40type Source struct{}41func (s *Source) Expect(x int) {42 fmt.Println("Expect")43}44import (45func TestExpect(t *testing.T) {46 fmt.Println("TestExpect")47 source := Source{}48 source.Expect(1)49}50import (51type Source struct{}52func (s *Source) Expect(x int) {53 fmt.Println("Expect")54}55import (56func TestExpect(t *testing.T)

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Mock automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful