@@ -385,61 +385,14 @@ func TestInitRun(t *testing.T) {
385385 }
386386}
387387
388- func TestSetReleaseTrigger (t * testing.T ) {
389- t .Parallel ()
390- for _ , test := range []struct {
391- name string
392- library * config.LibraryState
393- libraryID string
394- libraryVersion string
395- trigger bool
396- want * config.LibraryState
397- }{
398- {
399- name : "set trigger for a library" ,
400- library : & config.LibraryState {
401- ID : "one-example-id" ,
402- Version : "1.0.0" ,
403- },
404- trigger : true ,
405- want : & config.LibraryState {
406- ID : "one-example-id" ,
407- Version : "1.0.0" ,
408- ReleaseTriggered : true ,
409- },
410- },
411- {
412- name : "set trigger for one library and override version" ,
413- library : & config.LibraryState {
414- ID : "one-example-id" ,
415- Version : "1.0.0" ,
416- },
417- trigger : true ,
418- libraryVersion : "2.0.0" ,
419- want : & config.LibraryState {
420- ID : "one-example-id" ,
421- Version : "2.0.0" ,
422- ReleaseTriggered : true ,
423- },
424- },
425- } {
426- t .Run (test .name , func (t * testing.T ) {
427- setReleaseTrigger (test .library , test .libraryVersion , test .trigger )
428- if diff := cmp .Diff (test .want , test .library ); diff != "" {
429- t .Errorf ("state mismatch (-want +got):\n %s" , diff )
430- }
431- })
432- }
433- }
434-
435388func TestUpdateLibrary (t * testing.T ) {
436389 t .Parallel ()
437390 for _ , test := range []struct {
438391 name string
439392 pathAndMessages []pathAndMessage
440393 tags []string
441- runner * initRunner
442- state * config.LibrarianState
394+ libraryVersion string
395+ library * config.LibraryState
443396 repo gitrepo.Repository
444397 want * config.LibraryState
445398 wantErr bool
@@ -468,28 +421,13 @@ func TestUpdateLibrary(t *testing.T) {
468421 tags : []string {
469422 "one-id-1.2.3" ,
470423 },
471- runner : & initRunner {
472- cfg : & config.Config {
473- LibraryVersion : "2.0.0" ,
474- },
475- },
476- state : & config.LibrarianState {
477- Libraries : []* config.LibraryState {
478- {
479- ID : "another-id" ,
480- Version : "2.3.4" ,
481- SourceRoots : []string {
482- "another/path" ,
483- },
484- },
485- {
486- ID : "one-id" ,
487- Version : "1.2.3" ,
488- SourceRoots : []string {
489- "one/path" ,
490- "two/path" ,
491- },
492- },
424+ libraryVersion : "2.0.0" ,
425+ library : & config.LibraryState {
426+ ID : "one-id" ,
427+ Version : "1.2.3" ,
428+ SourceRoots : []string {
429+ "one/path" ,
430+ "two/path" ,
493431 },
494432 },
495433 want : & config.LibraryState {
@@ -532,26 +470,13 @@ func TestUpdateLibrary(t *testing.T) {
532470 },
533471 tags : []string {
534472 "one-id-1.2.3" ,
535- "another-id-2.3.4" ,
536473 },
537- runner : & initRunner {cfg : & config.Config {}},
538- state : & config.LibrarianState {
539- Libraries : []* config.LibraryState {
540- {
541- ID : "another-id" ,
542- Version : "2.3.4" ,
543- SourceRoots : []string {
544- "another/path" ,
545- },
546- },
547- {
548- ID : "one-id" ,
549- Version : "1.2.3" ,
550- SourceRoots : []string {
551- "one/path" ,
552- "two/path" ,
553- },
554- },
474+ library : & config.LibraryState {
475+ ID : "one-id" ,
476+ Version : "1.2.3" ,
477+ SourceRoots : []string {
478+ "one/path" ,
479+ "two/path" ,
555480 },
556481 },
557482 want : & config.LibraryState {
@@ -576,25 +501,13 @@ func TestUpdateLibrary(t *testing.T) {
576501 },
577502 },
578503 {
579- name : "failed to get commit history of one library" ,
580- runner : & initRunner {cfg : & config.Config {}},
581- state : & config.LibrarianState {
582- Libraries : []* config.LibraryState {
583- {
584- ID : "another-id" ,
585- Version : "2.3.4" ,
586- SourceRoots : []string {
587- "another/path" ,
588- },
589- },
590- {
591- ID : "one-id" ,
592- Version : "1.2.3" ,
593- SourceRoots : []string {
594- "one/path" ,
595- "two/path" ,
596- },
597- },
504+ name : "failed to get commit history of one library" ,
505+ library : & config.LibraryState {
506+ ID : "one-id" ,
507+ Version : "1.2.3" ,
508+ SourceRoots : []string {
509+ "one/path" ,
510+ "two/path" ,
598511 },
599512 },
600513 repo : & MockRepository {
@@ -606,12 +519,12 @@ func TestUpdateLibrary(t *testing.T) {
606519 } {
607520 t .Run (test .name , func (t * testing.T ) {
608521 var err error
522+ var updated * config.LibraryState
609523 if test .repo != nil {
610- test .runner .repo = test .repo
611- err = updateLibrary (test .runner , test .state , 1 )
524+ updated , err = updateLibrary (test .repo , test .library , test .libraryVersion )
612525 } else {
613- test . runner . repo = setupRepoForGetCommits (t , test .pathAndMessages , test .tags )
614- err = updateLibrary (test . runner , test .state , 1 )
526+ repo : = setupRepoForGetCommits (t , test .pathAndMessages , test .tags )
527+ updated , err = updateLibrary (repo , test .library , test . libraryVersion )
615528 }
616529
617530 if test .wantErr {
@@ -625,10 +538,11 @@ func TestUpdateLibrary(t *testing.T) {
625538
626539 return
627540 }
541+
628542 if err != nil {
629543 t .Errorf ("failed to run getChangesOf(): %q" , err .Error ())
630544 }
631- if diff := cmp .Diff (test .want , test . state . Libraries [ 1 ] , cmpopts .IgnoreFields (config.Change {}, "CommitHash" )); diff != "" {
545+ if diff := cmp .Diff (test .want , updated , cmpopts .IgnoreFields (config.Change {}, "CommitHash" )); diff != "" {
632546 t .Errorf ("state mismatch (-want +got):\n %s" , diff )
633547 }
634548 })
0 commit comments