|
5 | 5 | "context" |
6 | 6 | "encoding/json" |
7 | 7 | "fmt" |
| 8 | + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/configuration" |
8 | 9 | "net/url" |
9 | 10 | "testing" |
10 | 11 | "time" |
@@ -134,6 +135,14 @@ func TestDeployCreate_AskQuestions(t *testing.T) { |
134 | 135 | }) |
135 | 136 |
|
136 | 137 | api.ExpectRequest(t, "GET", "/api/Spaces-1/projects/"+fireProjectID+"/releases/"+release.Version).RespondWith(release) |
| 138 | + api.ExpectRequest(t, "GET", "/api/configuration/feature-toggles?Name=indicate-missing-packages-for-release").RespondWith(&configuration.FeatureToggleConfigurationResponse{ |
| 139 | + FeatureToggles: []configuration.ConfiguredFeatureToggle{ |
| 140 | + { |
| 141 | + Name: "indicate-missing-packages-for-release", |
| 142 | + IsEnabled: false, |
| 143 | + }, |
| 144 | + }, |
| 145 | + }) |
137 | 146 |
|
138 | 147 | api.ExpectRequest(t, "GET", "/api/Spaces-1/variables/"+vars.ID).RespondWith(&vars) |
139 | 148 |
|
@@ -197,6 +206,15 @@ func TestDeployCreate_AskQuestions(t *testing.T) { |
197 | 206 | Options: []string{release20.Version, release19.Version}, |
198 | 207 | }).AnswerWith(release19.Version) |
199 | 208 |
|
| 209 | + api.ExpectRequest(t, "GET", "/api/configuration/feature-toggles?Name=indicate-missing-packages-for-release").RespondWith(&configuration.FeatureToggleConfigurationResponse{ |
| 210 | + FeatureToggles: []configuration.ConfiguredFeatureToggle{ |
| 211 | + { |
| 212 | + Name: "indicate-missing-packages-for-release", |
| 213 | + IsEnabled: false, |
| 214 | + }, |
| 215 | + }, |
| 216 | + }) |
| 217 | + |
200 | 218 | api.ExpectRequest(t, "GET", "/api/Spaces-1/releases/"+release19.ID+"/progression").RespondWith(&releases.LifecycleProgression{ |
201 | 219 | Phases: []*releases.LifecycleProgressionPhase{ |
202 | 220 | {Name: "Dev", Progress: releases.PhaseProgressCurrent, AutomaticDeploymentTargets: []string{scratchEnvironment.ID}, OptionalDeploymentTargets: []string{devEnvironment.ID}}, |
@@ -269,6 +287,14 @@ func TestDeployCreate_AskQuestions(t *testing.T) { |
269 | 287 | }) |
270 | 288 |
|
271 | 289 | api.ExpectRequest(t, "GET", "/api/Spaces-1/projects/"+fireProjectID+"/releases/"+release19.Version).RespondWith(release19) |
| 290 | + api.ExpectRequest(t, "GET", "/api/configuration/feature-toggles?Name=indicate-missing-packages-for-release").RespondWith(&configuration.FeatureToggleConfigurationResponse{ |
| 291 | + FeatureToggles: []configuration.ConfiguredFeatureToggle{ |
| 292 | + { |
| 293 | + Name: "indicate-missing-packages-for-release", |
| 294 | + IsEnabled: false, |
| 295 | + }, |
| 296 | + }, |
| 297 | + }) |
272 | 298 |
|
273 | 299 | // doesn't lookup the progression or env names because it already has them |
274 | 300 |
|
@@ -336,6 +362,14 @@ func TestDeployCreate_AskQuestions(t *testing.T) { |
336 | 362 | }) |
337 | 363 |
|
338 | 364 | api.ExpectRequest(t, "GET", "/api/Spaces-1/projects/"+fireProjectID+"/releases/"+release20.Version).RespondWith(release20) |
| 365 | + api.ExpectRequest(t, "GET", "/api/configuration/feature-toggles?Name=indicate-missing-packages-for-release").RespondWith(&configuration.FeatureToggleConfigurationResponse{ |
| 366 | + FeatureToggles: []configuration.ConfiguredFeatureToggle{ |
| 367 | + { |
| 368 | + Name: "indicate-missing-packages-for-release", |
| 369 | + IsEnabled: false, |
| 370 | + }, |
| 371 | + }, |
| 372 | + }) |
339 | 373 |
|
340 | 374 | // now it's going to go looking for prompted variables; we don't have any prompted variables here so it skips |
341 | 375 | api.ExpectRequest(t, "GET", "/api/Spaces-1/variables/"+variableSnapshotWithPromptedVariables.ID).RespondWith(&variableSnapshotWithPromptedVariables) |
@@ -409,6 +443,14 @@ func TestDeployCreate_AskQuestions(t *testing.T) { |
409 | 443 | }) |
410 | 444 |
|
411 | 445 | api.ExpectRequest(t, "GET", "/api/Spaces-1/projects/"+fireProjectID+"/releases/"+release20.Version).RespondWith(release20) |
| 446 | + api.ExpectRequest(t, "GET", "/api/configuration/feature-toggles?Name=indicate-missing-packages-for-release").RespondWith(&configuration.FeatureToggleConfigurationResponse{ |
| 447 | + FeatureToggles: []configuration.ConfiguredFeatureToggle{ |
| 448 | + { |
| 449 | + Name: "indicate-missing-packages-for-release", |
| 450 | + IsEnabled: false, |
| 451 | + }, |
| 452 | + }, |
| 453 | + }) |
412 | 454 |
|
413 | 455 | // now it's going to go looking for prompted variables; we don't have any prompted variables here so it skips |
414 | 456 | api.ExpectRequest(t, "GET", "/api/Spaces-1/variables/"+variableSnapshotWithPromptedVariables.ID).RespondWith(&variableSnapshotWithPromptedVariables) |
@@ -479,6 +521,14 @@ func TestDeployCreate_AskQuestions(t *testing.T) { |
479 | 521 | }) |
480 | 522 |
|
481 | 523 | api.ExpectRequest(t, "GET", "/api/Spaces-1/projects/"+fireProjectID+"/releases/"+release19.Version).RespondWith(release19) |
| 524 | + api.ExpectRequest(t, "GET", "/api/configuration/feature-toggles?Name=indicate-missing-packages-for-release").RespondWith(&configuration.FeatureToggleConfigurationResponse{ |
| 525 | + FeatureToggles: []configuration.ConfiguredFeatureToggle{ |
| 526 | + { |
| 527 | + Name: "indicate-missing-packages-for-release", |
| 528 | + IsEnabled: false, |
| 529 | + }, |
| 530 | + }, |
| 531 | + }) |
482 | 532 |
|
483 | 533 | api.ExpectRequest(t, "GET", "/api/Spaces-1/releases/"+release19.ID+"/progression").RespondWith(&releases.LifecycleProgression{ |
484 | 534 | Phases: []*releases.LifecycleProgressionPhase{ |
@@ -582,6 +632,14 @@ func TestDeployCreate_AskQuestions(t *testing.T) { |
582 | 632 | }).AnswerWith("Tenanted") |
583 | 633 |
|
584 | 634 | api.ExpectRequest(t, "GET", "/api/Spaces-1/projects/"+fireProjectID+"/releases/"+release19.Version).RespondWith(release19) |
| 635 | + api.ExpectRequest(t, "GET", "/api/configuration/feature-toggles?Name=indicate-missing-packages-for-release").RespondWith(&configuration.FeatureToggleConfigurationResponse{ |
| 636 | + FeatureToggles: []configuration.ConfiguredFeatureToggle{ |
| 637 | + { |
| 638 | + Name: "indicate-missing-packages-for-release", |
| 639 | + IsEnabled: false, |
| 640 | + }, |
| 641 | + }, |
| 642 | + }) |
585 | 643 |
|
586 | 644 | // find environments via progression |
587 | 645 | api.ExpectRequest(t, "GET", "/api/Spaces-1/releases/"+release19.ID+"/progression").RespondWith(&releases.LifecycleProgression{ |
@@ -683,6 +741,115 @@ func TestDeployCreate_AskQuestions(t *testing.T) { |
683 | 741 | }).AnswerWith("Untenanted") |
684 | 742 |
|
685 | 743 | api.ExpectRequest(t, "GET", "/api/Spaces-1/projects/"+fireProjectID+"/releases/"+release19.Version).RespondWith(release19) |
| 744 | + api.ExpectRequest(t, "GET", "/api/configuration/feature-toggles?Name=indicate-missing-packages-for-release").RespondWith(&configuration.FeatureToggleConfigurationResponse{ |
| 745 | + FeatureToggles: []configuration.ConfiguredFeatureToggle{ |
| 746 | + { |
| 747 | + Name: "indicate-missing-packages-for-release", |
| 748 | + IsEnabled: false, |
| 749 | + }, |
| 750 | + }, |
| 751 | + }) |
| 752 | + |
| 753 | + // find environments via progression |
| 754 | + api.ExpectRequest(t, "GET", "/api/Spaces-1/releases/"+release19.ID+"/progression").RespondWith(&releases.LifecycleProgression{ |
| 755 | + Phases: []*releases.LifecycleProgressionPhase{ |
| 756 | + {Name: "Dev", Progress: releases.PhaseProgressCurrent, AutomaticDeploymentTargets: []string{scratchEnvironment.ID}, OptionalDeploymentTargets: []string{devEnvironment.ID}}, |
| 757 | + {Name: "Prod", Progress: releases.PhaseProgressPending, OptionalDeploymentTargets: []string{prodEnvironment.ID}}, // should scope this out due to pending |
| 758 | + }, |
| 759 | + NextDeployments: []string{devEnvironment.ID}, |
| 760 | + }) |
| 761 | + api.ExpectRequest(t, "GET", fmt.Sprintf("/api/Spaces-1/environments?ids=%s%%2C%s", scratchEnvironment.ID, devEnvironment.ID)).RespondWith(resources.Resources[*environments.Environment]{ |
| 762 | + Items: []*environments.Environment{scratchEnvironment, devEnvironment}, |
| 763 | + }) |
| 764 | + |
| 765 | + // Note: scratch comes first but default should be dev, due to NextDeployments |
| 766 | + _ = qa.ExpectQuestion(t, &survey.MultiSelect{ |
| 767 | + Message: "Select environment(s)", |
| 768 | + Options: []string{scratchEnvironment.Name, devEnvironment.Name}, |
| 769 | + Default: []string{devEnvironment.Name}, |
| 770 | + }).AnswerWith([]surveyCore.OptionAnswer{ |
| 771 | + {Value: devEnvironment.Name, Index: 0}, |
| 772 | + }) |
| 773 | + |
| 774 | + // now it's going to go looking for prompted variables; we don't have any prompted variables here so it skips |
| 775 | + api.ExpectRequest(t, "GET", "/api/Spaces-1/variables/"+variableSnapshotNoVars.ID).RespondWith(&variableSnapshotNoVars) |
| 776 | + emptyDeploymentPreviews := fixtures.EmptyDeploymentPreviews() |
| 777 | + api.ExpectRequest(t, "POST", "/api/Spaces-1/releases/"+release19.ID+"/deployments/previews").RespondWith(&emptyDeploymentPreviews) |
| 778 | + |
| 779 | + assert.Equal(t, heredoc.Doc(` |
| 780 | + Project Fire Project |
| 781 | + Release 1.9 |
| 782 | + `), stdout.String()) |
| 783 | + stdout.Reset() |
| 784 | + |
| 785 | + q := qa.ExpectQuestion(t, &survey.Select{ |
| 786 | + Message: "Change additional options?", |
| 787 | + Options: []string{"Proceed to deploy", "Change"}, |
| 788 | + }) |
| 789 | + assert.Regexp(t, "Additional Options", stdout.String()) // actual options tested in PrintAdvancedSummary |
| 790 | + _ = q.AnswerWith("Proceed to deploy") |
| 791 | + |
| 792 | + err := <-errReceiver |
| 793 | + assert.Nil(t, err) |
| 794 | + |
| 795 | + // check that the question-asking process has filled out the things we told it to |
| 796 | + assert.Equal(t, &executor.TaskOptionsDeployRelease{ |
| 797 | + ProjectName: "Fire Project", |
| 798 | + ReleaseVersion: "1.9", |
| 799 | + Environments: []string{"dev"}, |
| 800 | + GuidedFailureMode: "", |
| 801 | + Variables: make(map[string]string, 0), |
| 802 | + ReleaseID: release19.ID, |
| 803 | + }, options) |
| 804 | + }}, |
| 805 | + |
| 806 | + {"prompt if feature toggle is on and a release has missing packages", func(t *testing.T, api *testutil.MockHttpServer, qa *testutil.AskMocker, stdout *bytes.Buffer) { |
| 807 | + options := &executor.TaskOptionsDeployRelease{ |
| 808 | + ProjectName: "fire project", |
| 809 | + ReleaseVersion: "1.9", |
| 810 | + } |
| 811 | + |
| 812 | + errReceiver := testutil.GoBegin(func() error { |
| 813 | + defer testutil.Close(api, qa) |
| 814 | + // NewClient makes network calls so we have to run it in the goroutine |
| 815 | + octopus, _ := octopusApiClient.NewClient(testutil.NewMockHttpClientWithTransport(api), serverUrl, placeholderApiKey, "") |
| 816 | + return deploy.AskQuestions(octopus, stdout, qa.AsAsker(), space1, options, now) |
| 817 | + }) |
| 818 | + |
| 819 | + api.ExpectRequest(t, "GET", "/api/").RespondWith(rootResource) |
| 820 | + api.ExpectRequest(t, "GET", "/api/spaces").RespondWith(rootResource) |
| 821 | + |
| 822 | + api.ExpectRequest(t, "GET", "/api/Spaces-1/projects/fire project").RespondWithStatus(404, "NotFound", nil) |
| 823 | + api.ExpectRequest(t, "GET", "/api/Spaces-1/projects?partialName=fire+project"). |
| 824 | + RespondWith(resources.Resources[*projects.Project]{ |
| 825 | + Items: []*projects.Project{fireProjectMaybeTenanted}, |
| 826 | + }) |
| 827 | + |
| 828 | + _ = qa.ExpectQuestion(t, &survey.Select{ |
| 829 | + Message: "Select Tenanted or Untenanted deployment", |
| 830 | + Options: []string{"Tenanted", "Untenanted"}, |
| 831 | + }).AnswerWith("Untenanted") |
| 832 | + |
| 833 | + api.ExpectRequest(t, "GET", "/api/Spaces-1/projects/"+fireProjectID+"/releases/"+release19.Version).RespondWith(release19) |
| 834 | + api.ExpectRequest(t, "GET", "/api/configuration/feature-toggles?Name=indicate-missing-packages-for-release").RespondWith(&configuration.FeatureToggleConfigurationResponse{ |
| 835 | + FeatureToggles: []configuration.ConfiguredFeatureToggle{ |
| 836 | + { |
| 837 | + Name: "indicate-missing-packages-for-release", |
| 838 | + IsEnabled: true, |
| 839 | + }, |
| 840 | + }, |
| 841 | + }) |
| 842 | + api.ExpectRequest(t, "GET", "/api/Spaces-1/releases/"+release19.ID+"/missingpackages").RespondWith(&releases.MissingPackages{ |
| 843 | + Packages: []releases.MissingPackageInfo{ |
| 844 | + {ID: "apples", Version: "1.0.0"}, |
| 845 | + {ID: "bananas", Version: "2.0.0"}, |
| 846 | + }, |
| 847 | + }) |
| 848 | + |
| 849 | + _ = qa.ExpectQuestion(t, &survey.Confirm{ |
| 850 | + Message: "Do you want to continue?", |
| 851 | + Default: false, |
| 852 | + }).AnswerWith("true") |
686 | 853 |
|
687 | 854 | // find environments via progression |
688 | 855 | api.ExpectRequest(t, "GET", "/api/Spaces-1/releases/"+release19.ID+"/progression").RespondWith(&releases.LifecycleProgression{ |
@@ -713,6 +880,11 @@ func TestDeployCreate_AskQuestions(t *testing.T) { |
713 | 880 | assert.Equal(t, heredoc.Doc(` |
714 | 881 | Project Fire Project |
715 | 882 | Release 1.9 |
| 883 | + Warning: The following packages are missing from the built-in feed for this release: |
| 884 | + - apples (Version: 1.0.0) |
| 885 | + - bananas (Version: 2.0.0) |
| 886 | +
|
| 887 | + This might cause the deployment to fail. |
716 | 888 | `), stdout.String()) |
717 | 889 | stdout.Reset() |
718 | 890 |
|
@@ -743,14 +915,6 @@ func TestDeployCreate_AskQuestions(t *testing.T) { |
743 | 915 | errReceiver := testutil.GoBegin(func() error { |
744 | 916 | defer testutil.Close(api, qa) |
745 | 917 | octopus, _ := octopusApiClient.NewClient(testutil.NewMockHttpClientWithTransport(api), serverUrl, placeholderApiKey, "") |
746 | | - // |
747 | | - //api.ExpectRequest(t, "GET", "/api/Spaces-1/environments/all").RespondWith([]*environments.Environment{ |
748 | | - // devEnvironment, scratchEnvironment, |
749 | | - //}) |
750 | | - // |
751 | | - //emptyDeploymentPreviews := fixtures.EmptyDeploymentPreviews() |
752 | | - //api.ExpectRequest(t, "POST", "/api/Spaces-1/releases/"+release19.ID+"/deployments/previews").RespondWith(&emptyDeploymentPreviews) |
753 | | - |
754 | 918 | return deploy.AskQuestions(octopus, stdout, qa.AsAsker(), space1, options, now) |
755 | 919 | }) |
756 | 920 |
|
@@ -871,6 +1035,14 @@ func TestDeployCreate_AskQuestions(t *testing.T) { |
871 | 1035 | }) |
872 | 1036 |
|
873 | 1037 | api.ExpectRequest(t, "GET", "/api/Spaces-1/projects/"+fireProjectID+"/releases/"+release19.Version).RespondWith(release19) |
| 1038 | + api.ExpectRequest(t, "GET", "/api/configuration/feature-toggles?Name=indicate-missing-packages-for-release").RespondWith(&configuration.FeatureToggleConfigurationResponse{ |
| 1039 | + FeatureToggles: []configuration.ConfiguredFeatureToggle{ |
| 1040 | + { |
| 1041 | + Name: "indicate-missing-packages-for-release", |
| 1042 | + IsEnabled: false, |
| 1043 | + }, |
| 1044 | + }, |
| 1045 | + }) |
874 | 1046 |
|
875 | 1047 | api.ExpectRequest(t, "GET", "/api/Spaces-1/releases/"+release19.ID+"/progression").RespondWith(&releases.LifecycleProgression{ |
876 | 1048 | Phases: []*releases.LifecycleProgressionPhase{ |
@@ -1689,6 +1861,14 @@ func TestDeployCreate_GenerationOfAutomationCommand_MasksSensitiveVariables(t *t |
1689 | 1861 | }) |
1690 | 1862 |
|
1691 | 1863 | api.ExpectRequest(t, "GET", "/api/Spaces-1/projects/"+fireProjectID+"/releases/"+release20.Version).RespondWith(release20) |
| 1864 | + api.ExpectRequest(t, "GET", "/api/configuration/feature-toggles?Name=indicate-missing-packages-for-release").RespondWith(&configuration.FeatureToggleConfigurationResponse{ |
| 1865 | + FeatureToggles: []configuration.ConfiguredFeatureToggle{ |
| 1866 | + { |
| 1867 | + Name: "indicate-missing-packages-for-release", |
| 1868 | + IsEnabled: false, |
| 1869 | + }, |
| 1870 | + }, |
| 1871 | + }) |
1692 | 1872 |
|
1693 | 1873 | // now it's going to go looking for prompted variables; we don't have any prompted variables here so it skips |
1694 | 1874 | api.ExpectRequest(t, "GET", "/api/Spaces-1/variables/"+variableSnapshotWithPromptedVariables.ID).RespondWith(&variableSnapshotWithPromptedVariables) |
|
0 commit comments