From 877b5f0b2fc343d3456f5159e0eef7fe0a7003e2 Mon Sep 17 00:00:00 2001 From: Danny Ranson Date: Wed, 14 Aug 2024 11:37:57 +0100 Subject: [PATCH] test title and body separately --- cmd/create_prs/create_prs_test.go | 47 +++++++++++++++++++++++++++-- internal/testsupport/testsupport.go | 8 +++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/cmd/create_prs/create_prs_test.go b/cmd/create_prs/create_prs_test.go index 24bd371..7dab17e 100644 --- a/cmd/create_prs/create_prs_test.go +++ b/cmd/create_prs/create_prs_test.go @@ -22,6 +22,7 @@ import ( "github.com/skyscanner/turbolift/internal/prompt" "github.com/skyscanner/turbolift/internal/testsupport" "github.com/stretchr/testify/assert" + "path/filepath" "testing" ) @@ -33,8 +34,50 @@ func TestItWarnsIfDescriptionFileTemplateIsUnchanged(t *testing.T) { fakePrompt := prompt.NewFakePromptNo() p = fakePrompt - dir := testsupport.PrepareTempCampaign(true, "org/repo1", "org/repo2") - testsupport.UseDefaultPrDescription(dir) + dirName := testsupport.PrepareTempCampaign(true, "org/repo1", "org/repo2") + testsupport.UseDefaultPrDescription(dirName) + + out, err := runCommand() + assert.NoError(t, err) + assert.NotContains(t, out, "Creating PR in org/repo1") + assert.NotContains(t, out, "Creating PR in org/repo2") + assert.NotContains(t, out, "turbolift create-prs completed") + assert.NotContains(t, out, "2 OK, 0 skipped") + + fakePrompt.AssertCalledWith(t, "It looks like the PR title and/or description may not have been updated in README.md. Are you sure you want to proceed?") +} + +func TestItWarnsIfOnlyPrTitleIsUnchanged(t *testing.T) { + fakeGitHub := github.NewAlwaysFailsFakeGitHub() + gh = fakeGitHub + fakeGit := git.NewAlwaysSucceedsFakeGit() + g = fakeGit + fakePrompt := prompt.NewFakePromptNo() + p = fakePrompt + + dirName := testsupport.PrepareTempCampaign(true, "org/repo1", "org/repo2") + testsupport.UsePrTitleTodoOnly(filepath.Base(dirName)) + + out, err := runCommand() + assert.NoError(t, err) + assert.NotContains(t, out, "Creating PR in org/repo1") + assert.NotContains(t, out, "Creating PR in org/repo2") + assert.NotContains(t, out, "turbolift create-prs completed") + assert.NotContains(t, out, "2 OK, 0 skipped") + + fakePrompt.AssertCalledWith(t, "It looks like the PR title and/or description may not have been updated in README.md. Are you sure you want to proceed?") +} + +func TestItWarnsIfOnlyPrBodyIsUnchanged(t *testing.T) { + fakeGitHub := github.NewAlwaysFailsFakeGitHub() + gh = fakeGitHub + fakeGit := git.NewAlwaysSucceedsFakeGit() + g = fakeGit + fakePrompt := prompt.NewFakePromptNo() + p = fakePrompt + + testsupport.PrepareTempCampaign(true, "org/repo1", "org/repo2") + testsupport.UsePrBodyTodoOnly() out, err := runCommand() assert.NoError(t, err) diff --git a/internal/testsupport/testsupport.go b/internal/testsupport/testsupport.go index 63105fd..4c15d6d 100644 --- a/internal/testsupport/testsupport.go +++ b/internal/testsupport/testsupport.go @@ -87,3 +87,11 @@ func UseDefaultPrDescription(dirName string) { originalPrBodyTodo := "TODO: This file will serve as both a README and the description of the PR." CreateOrUpdatePrDescriptionFile("README.md", originalPrTitleTodo, originalPrBodyTodo) } + +func UsePrTitleTodoOnly(dirName string) { + CreateOrUpdatePrDescriptionFile("README.md", fmt.Sprintf("TODO: Title of Pull Request (%s)", dirName), "updated PR body") +} + +func UsePrBodyTodoOnly() { + CreateOrUpdatePrDescriptionFile("README.md", "updated PR title", "TODO: This file will serve as both a README and the description of the PR.") +}