TestRevAndVersion tests marshalling and unmarshalling rev and current version
(t *testing.T)
| 306 | |
| 307 | // TestRevAndVersion tests marshalling and unmarshalling rev and current version |
| 308 | func TestRevAndVersion(t *testing.T) { |
| 309 | |
| 310 | ctx := base.TestCtx(t) |
| 311 | testCases := []struct { |
| 312 | testName string |
| 313 | revTreeID string |
| 314 | source string |
| 315 | version string |
| 316 | }{ |
| 317 | { |
| 318 | testName: "rev_and_version", |
| 319 | revTreeID: "1-abc", |
| 320 | source: "source1", |
| 321 | version: "0x0100000000000000", |
| 322 | }, |
| 323 | { |
| 324 | testName: "both_empty", |
| 325 | revTreeID: "", |
| 326 | source: "", |
| 327 | version: "0", |
| 328 | }, |
| 329 | { |
| 330 | testName: "revTreeID_only", |
| 331 | revTreeID: "1-abc", |
| 332 | source: "", |
| 333 | version: "0", |
| 334 | }, |
| 335 | { |
| 336 | testName: "currentVersion_only", |
| 337 | revTreeID: "", |
| 338 | source: "source1", |
| 339 | version: "0x0100000000000000", |
| 340 | }, |
| 341 | } |
| 342 | |
| 343 | var expectedSequence = uint64(100) |
| 344 | for _, test := range testCases { |
| 345 | t.Run(test.testName, func(t *testing.T) { |
| 346 | syncData := &SyncData{ |
| 347 | RevAndVersion: channels.RevAndVersion{ |
| 348 | RevTreeID: test.revTreeID, |
| 349 | CurrentSource: test.source, |
| 350 | CurrentVersion: test.version, |
| 351 | }, |
| 352 | Sequence: expectedSequence, |
| 353 | } |
| 354 | // SyncData test |
| 355 | marshalledSyncData, err := base.JSONMarshal(syncData) |
| 356 | require.NoError(t, err) |
| 357 | log.Printf("marshalled:%s", marshalledSyncData) |
| 358 | |
| 359 | // Document test |
| 360 | document := NewDocument("docID") |
| 361 | document.SetRevTreeID(test.revTreeID) |
| 362 | document.SyncData.Sequence = expectedSequence |
| 363 | document.HLV = &HybridLogicalVector{ |
| 364 | SourceID: test.source, |
| 365 | Version: base.HexCasToUint64(test.version), |
nothing calls this directly
no test coverage detected