| 1 | package activitypub |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "reflect" |
| 6 | "testing" |
| 7 | "time" |
| 8 | ) |
| 9 | |
| 10 | func assertObjectWithTesting(fn canErrorFunc, expected Item) WithObjectFn { |
| 11 | return func(p *Object) error { |
| 12 | if !assertDeepEquals(fn, p, expected) { |
| 13 | return fmt.Errorf("not equal") |
| 14 | } |
| 15 | return nil |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | func TestOnObject(t *testing.T) { |
| 20 | testObject := Object{ |
| 21 | ID: "https://example.com", |
| 22 | } |
| 23 | type args struct { |
| 24 | it Item |
| 25 | fn func(canErrorFunc, Item) WithObjectFn |
| 26 | } |
| 27 | tests := []struct { |
| 28 | name string |
| 29 | args args |
| 30 | expected Item |
| 31 | wantErr bool |
| 32 | }{ |
| 33 | { |
| 34 | name: "single", |
| 35 | args: args{testObject, assertObjectWithTesting}, |
| 36 | expected: &testObject, |
| 37 | wantErr: false, |
| 38 | }, |
| 39 | { |
| 40 | name: "single fails", |
| 41 | args: args{Object{ID: "https://not-equals"}, assertObjectWithTesting}, |
| 42 | expected: &testObject, |
| 43 | wantErr: true, |
| 44 | }, |
| 45 | { |
| 46 | name: "collectionOfObjects", |
| 47 | args: args{ItemCollection{testObject, testObject}, assertObjectWithTesting}, |
| 48 | expected: &testObject, |
| 49 | wantErr: false, |
| 50 | }, |
| 51 | { |
| 52 | name: "collectionOfObjects fails", |
| 53 | args: args{ItemCollection{testObject, Object{ID: "https://not-equals"}}, assertObjectWithTesting}, |
| 54 | expected: &testObject, |
| 55 | wantErr: true, |
| 56 | }, |
| 57 | } |
| 58 | for _, tt := range tests { |
| 59 | var logFn canErrorFunc |
| 60 | if tt.wantErr { |
| 61 | logFn = t.Logf |
| 62 | } else { |
| 63 | logFn = t.Errorf |
| 64 | } |
| 65 | t.Run(tt.name, func(t *testing.T) { |
| 66 | if err := OnObject(tt.args.it, tt.args.fn(logFn, tt.expected)); (err != nil) != tt.wantErr { |
| 67 | t.Errorf("OnObject() error = %v, wantErr %v", err, tt.wantErr) |
| 68 | } |
| 69 | }) |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | func assertActivityWithTesting(fn canErrorFunc, expected Item) WithActivityFn { |
| 74 | return func(p *Activity) error { |
| 75 | if !assertDeepEquals(fn, p, expected) { |
| 76 | return fmt.Errorf("not equal") |
| 77 | } |
| 78 | return nil |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | func TestOnActivity(t *testing.T) { |
| 83 | testActivity := Activity{ |
| 84 | ID: "https://example.com", |
| 85 | } |
| 86 | type args struct { |
| 87 | it Item |
| 88 | fn func(canErrorFunc, Item) WithActivityFn |
| 89 | } |
| 90 | tests := []struct { |
| 91 | name string |
| 92 | args args |
| 93 | expected Item |
| 94 | wantErr bool |
| 95 | }{ |
| 96 | { |
| 97 | name: "single", |
| 98 | args: args{testActivity, assertActivityWithTesting}, |
| 99 | expected: &testActivity, |
| 100 | wantErr: false, |
| 101 | }, |
| 102 | { |
| 103 | name: "single fails", |
| 104 | args: args{Activity{ID: "https://not-equals"}, assertActivityWithTesting}, |
| 105 | expected: &testActivity, |
| 106 | wantErr: true, |
| 107 | }, |
| 108 | { |
| 109 | name: "collectionOfActivitys", |
| 110 | args: args{ItemCollection{testActivity, testActivity}, assertActivityWithTesting}, |
| 111 | expected: &testActivity, |
| 112 | wantErr: false, |
| 113 | }, |
| 114 | { |
| 115 | name: "collectionOfActivitys fails", |
| 116 | args: args{ItemCollection{testActivity, Activity{ID: "https://not-equals"}}, assertActivityWithTesting}, |
| 117 | expected: &testActivity, |
| 118 | wantErr: true, |
| 119 | }, |
| 120 | } |
| 121 | for _, tt := range tests { |
| 122 | var logFn canErrorFunc |
| 123 | if tt.wantErr { |
| 124 | logFn = t.Logf |
| 125 | } else { |
| 126 | logFn = t.Errorf |
| 127 | } |
| 128 | t.Run(tt.name, func(t *testing.T) { |
| 129 | if err := OnActivity(tt.args.it, tt.args.fn(logFn, tt.expected)); (err != nil) != tt.wantErr { |
| 130 | t.Errorf("OnActivity() error = %v, wantErr %v", err, tt.wantErr) |
| 131 | } |
| 132 | }) |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | func assertIntransitiveActivityWithTesting(fn canErrorFunc, expected Item) WithIntransitiveActivityFn { |
| 137 | return func(p *IntransitiveActivity) error { |
| 138 | if !assertDeepEquals(fn, p, expected) { |
| 139 | return fmt.Errorf("not equal") |
| 140 | } |
| 141 | return nil |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | func TestOnIntransitiveActivity(t *testing.T) { |
| 146 | testIntransitiveActivity := IntransitiveActivity{ |
| 147 | ID: "https://example.com", |
| 148 | } |
| 149 | type args struct { |
| 150 | it Item |
| 151 | fn func(canErrorFunc, Item) WithIntransitiveActivityFn |
| 152 | } |
| 153 | tests := []struct { |
| 154 | name string |
| 155 | args args |
| 156 | expected Item |
| 157 | wantErr bool |
| 158 | }{ |
| 159 | { |
| 160 | name: "single", |
| 161 | args: args{testIntransitiveActivity, assertIntransitiveActivityWithTesting}, |
| 162 | expected: &testIntransitiveActivity, |
| 163 | wantErr: false, |
| 164 | }, |
| 165 | { |
| 166 | name: "single fails", |
| 167 | args: args{IntransitiveActivity{ID: "https://not-equals"}, assertIntransitiveActivityWithTesting}, |
| 168 | expected: &testIntransitiveActivity, |
| 169 | wantErr: true, |
| 170 | }, |
| 171 | { |
| 172 | name: "collectionOfIntransitiveActivitys", |
| 173 | args: args{ItemCollection{testIntransitiveActivity, testIntransitiveActivity}, assertIntransitiveActivityWithTesting}, |
| 174 | expected: &testIntransitiveActivity, |
| 175 | wantErr: false, |
| 176 | }, |
| 177 | { |
| 178 | name: "collectionOfIntransitiveActivitys fails", |
| 179 | args: args{ItemCollection{testIntransitiveActivity, IntransitiveActivity{ID: "https://not-equals"}}, assertIntransitiveActivityWithTesting}, |
| 180 | expected: &testIntransitiveActivity, |
| 181 | wantErr: true, |
| 182 | }, |
| 183 | } |
| 184 | for _, tt := range tests { |
| 185 | var logFn canErrorFunc |
| 186 | if tt.wantErr { |
| 187 | logFn = t.Logf |
| 188 | } else { |
| 189 | logFn = t.Errorf |
| 190 | } |
| 191 | t.Run(tt.name, func(t *testing.T) { |
| 192 | if err := OnIntransitiveActivity(tt.args.it, tt.args.fn(logFn, tt.expected)); (err != nil) != tt.wantErr { |
| 193 | t.Errorf("OnIntransitiveActivity() error = %v, wantErr %v", err, tt.wantErr) |
| 194 | } |
| 195 | }) |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | func assertQuestionWithTesting(fn canErrorFunc, expected Item) WithQuestionFn { |
| 200 | return func(p *Question) error { |
| 201 | if !assertDeepEquals(fn, p, expected) { |
| 202 | return fmt.Errorf("not equal") |
| 203 | } |
| 204 | return nil |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | func TestOnQuestion(t *testing.T) { |
| 209 | testQuestion := Question{ |
| 210 | ID: "https://example.com", |
| 211 | } |
| 212 | type args struct { |
| 213 | it Item |
| 214 | fn func(canErrorFunc, Item) WithQuestionFn |
| 215 | } |
| 216 | tests := []struct { |
| 217 | name string |
| 218 | args args |
| 219 | expected Item |
| 220 | wantErr bool |
| 221 | }{ |
| 222 | { |
| 223 | name: "single", |
| 224 | args: args{testQuestion, assertQuestionWithTesting}, |
| 225 | expected: &testQuestion, |
| 226 | wantErr: false, |
| 227 | }, |
| 228 | { |
| 229 | name: "single fails", |
| 230 | args: args{Question{ID: "https://not-equals"}, assertQuestionWithTesting}, |
| 231 | expected: &testQuestion, |
| 232 | wantErr: true, |
| 233 | }, |
| 234 | { |
| 235 | name: "collectionOfQuestions", |
| 236 | args: args{ItemCollection{testQuestion, testQuestion}, assertQuestionWithTesting}, |
| 237 | expected: &testQuestion, |
| 238 | wantErr: false, |
| 239 | }, |
| 240 | { |
| 241 | name: "collectionOfQuestions fails", |
| 242 | args: args{ItemCollection{testQuestion, Question{ID: "https://not-equals"}}, assertQuestionWithTesting}, |
| 243 | expected: &testQuestion, |
| 244 | wantErr: true, |
| 245 | }, |
| 246 | } |
| 247 | for _, tt := range tests { |
| 248 | var logFn canErrorFunc |
| 249 | if tt.wantErr { |
| 250 | logFn = t.Logf |
| 251 | } else { |
| 252 | logFn = t.Errorf |
| 253 | } |
| 254 | t.Run(tt.name, func(t *testing.T) { |
| 255 | if err := OnQuestion(tt.args.it, tt.args.fn(logFn, tt.expected)); (err != nil) != tt.wantErr { |
| 256 | t.Errorf("OnQuestion() error = %v, wantErr %v", err, tt.wantErr) |
| 257 | } |
| 258 | }) |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | func TestOnCollection(t *testing.T) { |
| 263 | t.Skipf("TODO") |
| 264 | } |
| 265 | |
| 266 | func TestOnCollectionPage(t *testing.T) { |
| 267 | t.Skipf("TODO") |
| 268 | } |
| 269 | |
| 270 | func TestOnOrderedCollectionPage(t *testing.T) { |
| 271 | t.Skipf("TODO") |
| 272 | } |
| 273 | |
| 274 | type args[T Objects] struct { |
| 275 | it T |
| 276 | fn func(fn canErrorFunc, expected T) func(*T) error |
| 277 | } |
| 278 | |
| 279 | type testPair[T Objects] struct { |
| 280 | name string |
| 281 | args args[T] |
| 282 | expected T |
| 283 | wantErr bool |
| 284 | } |
| 285 | |
| 286 | func assert[T Objects](fn canErrorFunc, expected T) func(*T) error { |
| 287 | return func(p *T) error { |
| 288 | if !assertDeepEquals(fn, *p, expected) { |
| 289 | return fmt.Errorf("not equal") |
| 290 | } |
| 291 | return nil |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | func TestOn(t *testing.T) { |
| 296 | var tests = []testPair[Object]{ |
| 297 | { |
| 298 | name: "single object", |
| 299 | args: args[Object]{Object{ID: "https://example.com"}, assert[Object]}, |
| 300 | expected: Object{ID: "https://example.com"}, |
| 301 | wantErr: false, |
| 302 | }, |
| 303 | { |
| 304 | name: "single image", |
| 305 | args: args[Image]{Image{ID: "http://example.com"}, assert[Image]}, |
| 306 | expected: Image{ID: "http://example.com"}, |
| 307 | wantErr: false, |
| 308 | }, |
| 309 | } |
| 310 | for _, tt := range tests { |
| 311 | var logFn canErrorFunc |
| 312 | if tt.wantErr { |
| 313 | logFn = t.Logf |
| 314 | } else { |
| 315 | logFn = t.Errorf |
| 316 | } |
| 317 | t.Run(tt.name, func(t *testing.T) { |
| 318 | if err := On(tt.args.it, tt.args.fn(logFn, tt.expected)); (err != nil) != tt.wantErr { |
| 319 | t.Errorf("On[%T]() error = %v, wantErr %v", tt.args.it, err, tt.wantErr) |
| 320 | } |
| 321 | }) |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | var ( |
| 326 | emptyPrintFn = func(string, ...any) {} |
| 327 | |
| 328 | fnPrintObj = func(printFn func(string, ...any)) func(_ *Object) error { |
| 329 | return func(o *Object) error { |
| 330 | printFn("%v", o) |
| 331 | return nil |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | fnObj = func(_ *Object) error { return nil } |
| 336 | fnAct = func(_ *Actor) error { return nil } |
| 337 | fnA = func(_ *Activity) error { return nil } |
| 338 | fnIA = func(_ *IntransitiveActivity) error { return nil } |
| 339 | |
| 340 | maybeObject Item = new(Object) |
| 341 | notObject Item = new(Activity) |
| 342 | maybeActor Item = new(Actor) |
| 343 | maybeActivity Item = new(Activity) |
| 344 | notIntransitiveActivity Item = new(Activity) |
| 345 | maybeIntransitiveActivity Item = new(IntransitiveActivity) |
| 346 | colOfObjects Item = ItemCollection{Object{ID: "unum"}, Object{ID: "duo"}} |
| 347 | colOfNotObjects Item = ItemCollection{Activity{ID: "unum"}, Activity{ID: "duo"}} |
| 348 | ) |
| 349 | |
| 350 | func Benchmark_ToObject(b *testing.B) { |
| 351 | for i := 0; i < b.N; i++ { |
| 352 | ToObject(maybeObject) |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | func Benchmark_To_T_Object(b *testing.B) { |
| 357 | for i := 0; i < b.N; i++ { |
| 358 | To[Object](maybeObject) |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | func Benchmark_ToActor(b *testing.B) { |
| 363 | for i := 0; i < b.N; i++ { |
| 364 | ToActor(maybeActor) |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | func Benchmark_To_T_Actor(b *testing.B) { |
| 369 | for i := 0; i < b.N; i++ { |
| 370 | To[Actor](maybeActor) |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | func Benchmark_ToActivity(b *testing.B) { |
| 375 | for i := 0; i < b.N; i++ { |
| 376 | ToActivity(maybeActivity) |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | func Benchmark_To_T_Activity(b *testing.B) { |
| 381 | for i := 0; i < b.N; i++ { |
| 382 | To[Activity](maybeActivity) |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | func Benchmark_ToIntransitiveActivityHappy(b *testing.B) { |
| 387 | for i := 0; i < b.N; i++ { |
| 388 | ToIntransitiveActivity(maybeIntransitiveActivity) |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | func Benchmark_To_T_IntransitiveActivityHappy(b *testing.B) { |
| 393 | for i := 0; i < b.N; i++ { |
| 394 | To[IntransitiveActivity](maybeIntransitiveActivity) |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | func Benchmark_ToIntransitiveActivityNotHappy(b *testing.B) { |
| 399 | for i := 0; i < b.N; i++ { |
| 400 | ToIntransitiveActivity(notIntransitiveActivity) |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | func Benchmark_To_T_IntransitiveActivityNotHappy(b *testing.B) { |
| 405 | for i := 0; i < b.N; i++ { |
| 406 | To[IntransitiveActivity](notIntransitiveActivity) |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | func Benchmark_OnObject(b *testing.B) { |
| 411 | for i := 0; i < b.N; i++ { |
| 412 | OnObject(maybeObject, fnObj) |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | func Benchmark_On_T_Object(b *testing.B) { |
| 417 | for i := 0; i < b.N; i++ { |
| 418 | On[Object](maybeObject, fnObj) |
| 419 | } |
| 420 | } |
| 421 | func Benchmark_OnActor(b *testing.B) { |
| 422 | for i := 0; i < b.N; i++ { |
| 423 | OnActor(maybeObject, fnAct) |
| 424 | } |
| 425 | } |
| 426 | func Benchmark_On_T_Actor(b *testing.B) { |
| 427 | for i := 0; i < b.N; i++ { |
| 428 | On[Actor](maybeObject, fnAct) |
| 429 | } |
| 430 | } |
| 431 | func Benchmark_OnActivity(b *testing.B) { |
| 432 | for i := 0; i < b.N; i++ { |
| 433 | OnActivity(maybeObject, fnA) |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | func Benchmark_On_T_Activity(b *testing.B) { |
| 438 | for i := 0; i < b.N; i++ { |
| 439 | On[Activity](maybeObject, fnA) |
| 440 | } |
| 441 | } |
| 442 | func Benchmark_OnIntransitiveActivity(b *testing.B) { |
| 443 | for i := 0; i < b.N; i++ { |
| 444 | OnIntransitiveActivity(maybeObject, fnIA) |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | func Benchmark_On_T_IntransitiveActivity(b *testing.B) { |
| 449 | for i := 0; i < b.N; i++ { |
| 450 | On[IntransitiveActivity](maybeObject, fnIA) |
| 451 | } |
| 452 | } |
| 453 | func Benchmark_OnObjectNotHappy(b *testing.B) { |
| 454 | for i := 0; i < b.N; i++ { |
| 455 | OnObject(notObject, fnObj) |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | func Benchmark_On_T_ObjectNotHappy(b *testing.B) { |
| 460 | for i := 0; i < b.N; i++ { |
| 461 | On[Object](notObject, fnObj) |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | func Benchmark_OnObjectHappyCol(b *testing.B) { |
| 466 | for i := 0; i < b.N; i++ { |
| 467 | OnObject(colOfObjects, fnObj) |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | func Benchmark_On_T_ObjectHappyCol(b *testing.B) { |
| 472 | for i := 0; i < b.N; i++ { |
| 473 | On[Object](colOfObjects, fnObj) |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | func Benchmark_OnObjectNotHappyCol(b *testing.B) { |
| 478 | for i := 0; i < b.N; i++ { |
| 479 | OnObject(colOfNotObjects, fnObj) |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | func Benchmark_On_T_ObjectNotHappyCol(b *testing.B) { |
| 484 | for i := 0; i < b.N; i++ { |
| 485 | On[Object](colOfNotObjects, fnObj) |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | func TestDerefItem(t *testing.T) { |
| 490 | tests := []struct { |
| 491 | name string |
| 492 | arg Item |
| 493 | want ItemCollection |
| 494 | }{ |
| 495 | { |
| 496 | name: "empty", |
| 497 | }, |
| 498 | { |
| 499 | name: "simple object", |
| 500 | arg: &Object{ID: "https://example.com"}, |
| 501 | want: ItemCollection{&Object{ID: "https://example.com"}}, |
| 502 | }, |
| 503 | { |
| 504 | name: "simple IRI", |
| 505 | arg: IRI("https://example.com"), |
| 506 | want: ItemCollection{IRI("https://example.com")}, |
| 507 | }, |
| 508 | { |
| 509 | name: "IRI collection", |
| 510 | arg: IRIs{IRI("https://example.com"), IRI("https://example.com/~jdoe")}, |
| 511 | want: ItemCollection{IRI("https://example.com"), IRI("https://example.com/~jdoe")}, |
| 512 | }, |
| 513 | { |
| 514 | name: "Item collection", |
| 515 | arg: ItemCollection{ |
| 516 | &Object{ID: "https://example.com"}, |
| 517 | &Actor{ID: "https://example.com/~jdoe"}, |
| 518 | }, |
| 519 | want: ItemCollection{ |
| 520 | &Object{ID: "https://example.com"}, |
| 521 | &Actor{ID: "https://example.com/~jdoe"}, |
| 522 | }, |
| 523 | }, |
| 524 | { |
| 525 | name: "mixed item collection", |
| 526 | arg: ItemCollection{ |
| 527 | &Object{ID: "https://example.com"}, |
| 528 | IRI("https://example.com/666"), |
| 529 | &Actor{ID: "https://example.com/~jdoe"}, |
| 530 | }, |
| 531 | want: ItemCollection{ |
| 532 | &Object{ID: "https://example.com"}, |
| 533 | IRI("https://example.com/666"), |
| 534 | &Actor{ID: "https://example.com/~jdoe"}, |
| 535 | }, |
| 536 | }, |
| 537 | } |
| 538 | for _, tt := range tests { |
| 539 | t.Run(tt.name, func(t *testing.T) { |
| 540 | if got := DerefItem(tt.arg); !reflect.DeepEqual(got, tt.want) { |
| 541 | t.Errorf("DerefItem() = %v, want %v", got, tt.want) |
| 542 | } |
| 543 | }) |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | func TestItemOrderTimestamp(t *testing.T) { |
| 548 | early1 := time.Date(2001, 6, 6, 6, 0, 0, 0, time.UTC) |
| 549 | early2 := time.Date(2001, 6, 6, 6, 0, 1, 0, time.UTC) |
| 550 | late1 := time.Date(2001, 6, 6, 7, 0, 0, 0, time.UTC) |
| 551 | late2 := time.Date(2001, 6, 6, 7, 0, 1, 0, time.UTC) |
| 552 | type args struct { |
| 553 | i1 Item |
| 554 | i2 Item |
| 555 | } |
| 556 | tests := []struct { |
| 557 | name string |
| 558 | args args |
| 559 | want bool |
| 560 | }{ |
| 561 | { |
| 562 | name: "empty", |
| 563 | args: args{}, |
| 564 | want: false, |
| 565 | }, |
| 566 | { |
| 567 | name: "first empty", |
| 568 | args: args{ |
| 569 | i1: nil, |
| 570 | i2: &Object{}, |
| 571 | }, |
| 572 | want: true, |
| 573 | }, |
| 574 | { |
| 575 | name: "second empty", |
| 576 | args: args{ |
| 577 | i1: &Object{}, |
| 578 | i2: nil, |
| 579 | }, |
| 580 | want: false, |
| 581 | }, |
| 582 | { |
| 583 | name: "empty published/updated", |
| 584 | args: args{ |
| 585 | i1: &Object{}, |
| 586 | i2: &Object{}, |
| 587 | }, |
| 588 | want: false, |
| 589 | }, |
| 590 | { |
| 591 | name: "first has empty published/updated", |
| 592 | args: args{ |
| 593 | i1: &Object{}, |
| 594 | i2: &Object{Published: early1}, |
| 595 | }, |
| 596 | want: false, |
| 597 | }, |
| 598 | { |
| 599 | name: "check published equals", |
| 600 | args: args{ |
| 601 | i1: &Object{Published: early1}, |
| 602 | i2: &Object{Published: early1}, |
| 603 | }, |
| 604 | want: false, |
| 605 | }, |
| 606 | { |
| 607 | name: "check published/updated equals", |
| 608 | args: args{ |
| 609 | i1: &Object{Published: early2}, |
| 610 | i2: &Object{Updated: early2}, |
| 611 | }, |
| 612 | want: false, |
| 613 | }, |
| 614 | { |
| 615 | name: "check updated/published equals", |
| 616 | args: args{ |
| 617 | i1: &Object{Updated: late1}, |
| 618 | i2: &Object{Published: late1}, |
| 619 | }, |
| 620 | want: false, |
| 621 | }, |
| 622 | { |
| 623 | name: "check first published earlier", |
| 624 | args: args{ |
| 625 | i1: &Object{Published: early1}, |
| 626 | i2: &Object{Published: late1}, |
| 627 | }, |
| 628 | want: false, |
| 629 | }, |
| 630 | { |
| 631 | name: "check second published earlier", |
| 632 | args: args{ |
| 633 | i1: &Object{Published: late1}, |
| 634 | i2: &Object{Published: early1}, |
| 635 | }, |
| 636 | want: true, |
| 637 | }, |
| 638 | { |
| 639 | name: "check first updated earlier", |
| 640 | args: args{ |
| 641 | i1: &Object{Updated: early1}, |
| 642 | i2: &Object{Updated: late1}, |
| 643 | }, |
| 644 | want: false, |
| 645 | }, |
| 646 | { |
| 647 | name: "check second updated earlier", |
| 648 | args: args{ |
| 649 | i1: &Object{Updated: late1}, |
| 650 | i2: &Object{Updated: early1}, |
| 651 | }, |
| 652 | want: true, |
| 653 | }, |
| 654 | |
| 655 | { |
| 656 | name: "check first earlier", |
| 657 | args: args{ |
| 658 | i1: &Object{Published: early1, Updated: late1}, |
| 659 | i2: &Object{Published: early1, Updated: late2}, |
| 660 | }, |
| 661 | want: false, |
| 662 | }, |
| 663 | { |
| 664 | name: "check second earlier", |
| 665 | args: args{ |
| 666 | i1: &Object{Published: early1, Updated: late2}, |
| 667 | i2: &Object{Published: early1, Updated: late1}, |
| 668 | }, |
| 669 | want: true, |
| 670 | }, |
| 671 | } |
| 672 | for _, tt := range tests { |
| 673 | t.Run(tt.name, func(t *testing.T) { |
| 674 | if got := ItemOrderTimestamp(tt.args.i1, tt.args.i2); got != tt.want { |
| 675 | t.Errorf("ItemOrderTimestamp() = %v, want %v", got, tt.want) |
| 676 | } |
| 677 | }) |
| 678 | } |
| 679 | } |