github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/client/cli/store/snapshot/snapshot_test.go (about) 1 package snapshot 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/tickoalcantara12/micro/v3/service/store" 8 ) 9 10 func TestFileSnapshot(t *testing.T) { 11 f := NewFileSnapshot(Destination("invalid")) 12 if err := f.Init(); err == nil { 13 t.Error(err) 14 } 15 if err := f.Init(Destination("file:///tmp/test-snapshot")); err != nil { 16 t.Error(err) 17 } 18 19 recordChan, err := f.Start() 20 if err != nil { 21 t.Error(err) 22 } 23 24 for _, td := range testData { 25 recordChan <- td 26 } 27 close(recordChan) 28 f.Wait() 29 30 r := NewFileRestore(Source("invalid")) 31 if err := r.Init(); err == nil { 32 t.Error(err) 33 } 34 if err := r.Init(Source("file:///tmp/test-snapshot")); err != nil { 35 t.Error(err) 36 } 37 38 returnChan, err := r.Start() 39 if err != nil { 40 t.Error(err) 41 } 42 var receivedData []*store.Record 43 for r := range returnChan { 44 println("decoded", r.Key) 45 receivedData = append(receivedData, r) 46 } 47 48 } 49 50 var testData = []*store.Record{ 51 { 52 Key: "foo", 53 Value: []byte(`foo`), 54 Expiry: time.Until(time.Now().Add(5 * time.Second)), 55 }, 56 { 57 Key: "bar", 58 Value: []byte(`bar`), 59 Expiry: time.Until(time.Now().Add(5 * time.Second)), 60 }, 61 { 62 Key: "baz", 63 Value: []byte(`baz`), 64 Expiry: time.Until(time.Now().Add(5 * time.Second)), 65 }, 66 }