github.com/go-kivik/kivik/v4@v4.3.2/mockdb/clientmock_test.go (about) 1 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 2 // use this file except in compliance with the License. You may obtain a copy of 3 // the License at 4 // 5 // http://www.apache.org/licenses/LICENSE-2.0 6 // 7 // Unless required by applicable law or agreed to in writing, software 8 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 9 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 10 // License for the specific language governing permissions and limitations under 11 // the License. 12 13 package mockdb 14 15 import ( 16 "errors" 17 "testing" 18 "time" 19 20 "gitlab.com/flimzy/testy" 21 22 kivik "github.com/go-kivik/kivik/v4" 23 ) 24 25 func TestReplication(t *testing.T) { 26 _, m, err := New() 27 if err != nil { 28 t.Fatal(err) 29 } 30 ts := time.Now() 31 eID := "a1" 32 eSource := "a2" 33 eTarget := "a3" 34 eStartTime := ts 35 eEndTime := ts.Add(time.Second) 36 eState := kivik.ReplicationComplete 37 eErr := "a5" 38 r := m.NewReplication(). 39 ID(eID). 40 Source(eSource). 41 Target(eTarget). 42 StartTime(eStartTime). 43 EndTime(eEndTime). 44 State(eState). 45 Err(errors.New(eErr)) 46 dr := &driverReplication{r} 47 t.Run("ID", func(t *testing.T) { 48 if id := dr.ReplicationID(); id != eID { 49 t.Errorf("Unexpected ID. Got %s, want %s", id, eID) 50 } 51 }) 52 t.Run("Source", func(t *testing.T) { 53 if s := dr.Source(); s != eSource { 54 t.Errorf("Unexpected Source. Got %s, want %s", s, eSource) 55 } 56 }) 57 t.Run("StartTime", func(t *testing.T) { 58 if ts := dr.StartTime(); !ts.Equal(eStartTime) { 59 t.Errorf("Unexpected StartTime. Got %s, want %s", ts, eStartTime) 60 } 61 }) 62 t.Run("EndTime", func(t *testing.T) { 63 if ts := dr.EndTime(); !ts.Equal(eEndTime) { 64 t.Errorf("Unexpected EndTime. Got %s, want %s", ts, eEndTime) 65 } 66 }) 67 t.Run("State", func(t *testing.T) { 68 if s := kivik.ReplicationState(dr.State()); s != eState { 69 t.Errorf("Unexpected State. Got %s, want %s", s, eState) 70 } 71 }) 72 t.Run("Err", func(t *testing.T) { 73 err := dr.Err() 74 if !testy.ErrorMatches(eErr, err) { 75 t.Errorf("Unexpected error: %s", err) 76 } 77 }) 78 }