github.com/henvic/wedeploycli@v1.7.6-0.20200319005353-3630f582f284/deployment/internal/repodiscovery/tiny/tiny_test.go (about)

     1  package tiny
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  
     7  	"github.com/henvic/wedeploycli/deployment/internal/repodiscovery"
     8  )
     9  
    10  type convertCase struct {
    11  	info Info
    12  	want Tiny
    13  }
    14  
    15  var convertCases = []convertCase{
    16  	convertCase{
    17  		Info{
    18  			Deploy: true,
    19  			Repositories: []repodiscovery.Repository{
    20  				repodiscovery.Repository{
    21  					Services:          []string{"service", "nested"},
    22  					Path:              "mocks/project-with-git",
    23  					Origin:            "https://github.com/example/project-with-git",
    24  					Commit:            "5fb64d23dc767fda01416ba0f89375ee88688a74",
    25  					CommitAuthor:      "Example",
    26  					CommitAuthorEmail: "good@example.com",
    27  					CommitMessage:     "deployment: create microformat to list repos used during a deployment.",
    28  					CommitDate:        "2018-08-27 02:23:14 -0600 -0600",
    29  					Branch:            "master",
    30  				},
    31  			},
    32  		},
    33  		Tiny{
    34  			Deploy: true,
    35  			Commit: &commitInfo{
    36  				Repository:  "https://github.com/example/project-with-git",
    37  				SHA:         "5fb64d23dc767fda01416ba0f89375ee88688a74",
    38  				Branch:      "master",
    39  				Message:     "deployment: create microformat to list repos used during a deployment.",
    40  				AuthorName:  "Example",
    41  				AuthorEmail: "good@example.com",
    42  				Date:        "2018-08-27 02:23:14 -0600 -0600",
    43  			},
    44  		},
    45  	},
    46  	convertCase{
    47  		Info{
    48  			Deploy: true,
    49  			Repositories: []repodiscovery.Repository{
    50  				repodiscovery.Repository{
    51  					Services:          []string{"service"},
    52  					Path:              "mocks/service-with-git",
    53  					Origin:            "https://github.com/example/service-with-git",
    54  					Commit:            "5fb64d23dc767fda01416ba0f89375ee88688a74",
    55  					CommitAuthor:      "Example",
    56  					CommitAuthorEmail: "good@example.com",
    57  					CommitMessage:     "deployment: create microformat to list repos used during a deployment.",
    58  					CommitDate:        "2018-08-27 02:23:14 -0600 -0600",
    59  					Branch:            "master",
    60  				},
    61  				repodiscovery.Repository{
    62  					Services:          []string{"foo"},
    63  					Path:              "mocks/another-service",
    64  					Origin:            "https://github.com/example/another-service",
    65  					Commit:            "4b6865baded49855a6b2c4b1160b7460b4a4c9f7",
    66  					CommitAuthor:      "Example",
    67  					CommitAuthorEmail: "good@example.com",
    68  					CommitMessage:     "Adding https://github.com/src-d/go-git.",
    69  					CommitDate:        "2018-08-24 02:23:14 -0600 -0600",
    70  					Branch:            "master",
    71  				},
    72  			},
    73  		},
    74  		Tiny{
    75  			Deploy: true,
    76  		},
    77  	},
    78  	convertCase{
    79  		Info{
    80  			Repositories: []repodiscovery.Repository{
    81  				repodiscovery.Repository{
    82  					Services:          []string{"service", "nested"},
    83  					Path:              "mocks/project-with-git",
    84  					Origin:            "https://github.com/example/service-with-git",
    85  					Commit:            "ecd69078d879f8c53d68c8d7521b1dd04a1b9cd1",
    86  					CommitAuthor:      "Example",
    87  					CommitAuthorEmail: "good@example.com",
    88  					CommitMessage:     "abcd.",
    89  					CommitDate:        "2018-08-24 02:23:14 -0600 -0600",
    90  					Branch:            "master",
    91  				},
    92  			},
    93  			Repoless: []string{"foo"},
    94  		},
    95  		Tiny{},
    96  	},
    97  }
    98  
    99  func TestConvert(t *testing.T) {
   100  	for _, c := range convertCases {
   101  		var got = Convert(c.info)
   102  
   103  		if !reflect.DeepEqual(got, c.want) {
   104  			t.Errorf("Expected tiny info to be %+v, got %+v instead", c.want, got)
   105  		}
   106  	}
   107  }