예제 #1
0
// Commits returns a slice of github.RepositoryCommit of len==3 which
// happened at times 7, 8, 9
func Commits() []github.RepositoryCommit {
	return github_test.Commits(3, 7)
}
예제 #2
0
func TestGetLastModified(t *testing.T) {
	tests := []struct {
		commits      []github.RepositoryCommit
		expectedTime *time.Time
	}{
		{
			commits:      github_test.Commits(1, 10),
			expectedTime: timePtr(time.Unix(10, 0)),
		},
		{
			// remember the order of github_test.Commits() is non-deterministic
			commits:      github_test.Commits(3, 10),
			expectedTime: timePtr(time.Unix(12, 0)),
		},
		{
			// so this is probably not quite the same test...
			commits:      github_test.Commits(3, 8),
			expectedTime: timePtr(time.Unix(10, 0)),
		},
		{
			//  We can't represent the same time in 2 commits using github_test.Commits()
			commits: []github.RepositoryCommit{
				{
					SHA: stringPtr("mysha1"),
					Commit: &github.Commit{
						SHA: stringPtr("mysha1"),
						Committer: &github.CommitAuthor{
							Date: timePtr(time.Unix(9, 0)),
						},
					},
				},
				{
					SHA: stringPtr("mysha2"),
					Commit: &github.Commit{
						SHA: stringPtr("mysha2"),
						Committer: &github.CommitAuthor{
							Date: timePtr(time.Unix(10, 0)),
						},
					},
				},
				{
					SHA: stringPtr("mysha3"),
					Commit: &github.Commit{
						SHA: stringPtr("mysha3"),
						Committer: &github.CommitAuthor{
							Date: timePtr(time.Unix(9, 0)),
						},
					},
				},
			},
			expectedTime: timePtr(time.Unix(10, 0)),
		},
	}
	for _, test := range tests {
		client, server, _ := github_test.InitServer(t, nil, nil, nil, test.commits, nil, nil)
		config := &Config{}
		config.Org = "o"
		config.Project = "r"
		config.SetClient(client)

		obj := &MungeObject{
			config: config,
			Issue:  github_test.Issue("bob", 1, nil, true),
		}
		ts := obj.LastModifiedTime()
		if !ts.Equal(*test.expectedTime) {
			t.Errorf("expected: %v, saw: %v for: %v", test.expectedTime, ts, test)
		}
		server.Close()
	}
}