From 4e237dd91a20c862830539de0a585714872aaca5 Mon Sep 17 00:00:00 2001 From: Jake Nelson Date: Fri, 29 Oct 2021 00:13:34 +0000 Subject: [PATCH 1/3] Add pipeline description to spec to match API --- codefresh/resource_pipeline.go | 4 ++++ codefresh/resource_pipeline_test.go | 15 ++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/codefresh/resource_pipeline.go b/codefresh/resource_pipeline.go index 86f7af1..022e4e6 100644 --- a/codefresh/resource_pipeline.go +++ b/codefresh/resource_pipeline.go @@ -106,6 +106,10 @@ func resourcePipeline() *schema.Resource { Optional: true, Default: "github", }, + "description": { + Type: schema.TypeString, + Optional: true, + }, }, }, }, diff --git a/codefresh/resource_pipeline_test.go b/codefresh/resource_pipeline_test.go index a08ca82..6d14be7 100644 --- a/codefresh/resource_pipeline_test.go +++ b/codefresh/resource_pipeline_test.go @@ -23,7 +23,7 @@ func TestAccCodefreshPipeline_basic(t *testing.T) { CheckDestroy: testAccCheckCodefreshPipelineDestroy, Steps: []resource.TestStep{ { - Config: testAccCodefreshPipelineBasicConfig(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git"), + Config: testAccCodefreshPipelineBasicConfig(name, "My pipeline", "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git"), Check: resource.ComposeTestCheckFunc( testAccCheckCodefreshPipelineExists(resourceName), resource.TestCheckResourceAttr(resourceName, "name", name), @@ -289,7 +289,7 @@ func TestAccCodefreshPipeline_Revision(t *testing.T) { CheckDestroy: testAccCheckCodefreshPipelineDestroy, Steps: []resource.TestStep{ { - Config: testAccCodefreshPipelineBasicConfig(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git"), + Config: testAccCodefreshPipelineBasicConfig(name, "My pipeline", "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git"), Check: resource.ComposeTestCheckFunc( testAccCheckCodefreshPipelineExists(resourceName), resource.TestCheckResourceAttr(resourceName, "revision", "0"), @@ -301,7 +301,7 @@ func TestAccCodefreshPipeline_Revision(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccCodefreshPipelineBasicConfig(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "development", "git"), + Config: testAccCodefreshPipelineBasicConfig(name, "My pipeline", "codefresh-contrib/react-sample-app", "./codefresh.yml", "development", "git"), Check: resource.ComposeTestCheckFunc( testAccCheckCodefreshPipelineExists(resourceName), resource.TestCheckResourceAttr(resourceName, "revision", "1"), @@ -321,7 +321,7 @@ func TestAccCodefreshPipeline_IsPublic(t *testing.T) { CheckDestroy: testAccCheckCodefreshPipelineDestroy, Steps: []resource.TestStep{ { - Config: testAccCodefreshPipelineBasicConfig(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git"), + Config: testAccCodefreshPipelineBasicConfig(name, "My pipeline","codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git"), Check: resource.ComposeTestCheckFunc( testAccCheckCodefreshPipelineExists(resourceName), resource.TestCheckResourceAttr(resourceName, "is_public", "false"), @@ -366,7 +366,7 @@ func TestAccCodefreshPipelineOnCreateBranchIgnoreTrigger(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccCodefreshPipelineBasicConfig(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git"), + Config: testAccCodefreshPipelineBasicConfig(name, "My pipeline", "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git"), Check: resource.ComposeTestCheckFunc( testAccCheckCodefreshPipelineExists(resourceName), resource.TestCheckResourceAttr(resourceName, "name", name), @@ -427,7 +427,7 @@ func testAccCheckCodefreshPipelineDestroy(s *terraform.State) error { } // CONFIGS -func testAccCodefreshPipelineBasicConfig(rName, repo, path, revision, context string) string { +func testAccCodefreshPipelineBasicConfig(rName, repo, description, path, revision, context string) string { return fmt.Sprintf(` resource "codefresh_pipeline" "test" { @@ -440,6 +440,7 @@ resource "codefresh_pipeline" "test" { name = "%s" spec { + description = "%s" spec_template { repo = %q path = %q @@ -448,7 +449,7 @@ resource "codefresh_pipeline" "test" { } } } -`, rName, repo, path, revision, context) +`, rName, description, repo, path, revision, context) } func testAccCodefreshPipelineBasicConfigTags(rName, repo, path, revision, context, tag1, tag2 string) string { From f20b0a5415a0d30b405c2a503631d0b3f3fcd8a8 Mon Sep 17 00:00:00 2001 From: Jake Nelson Date: Fri, 29 Oct 2021 00:29:51 +0000 Subject: [PATCH 2/3] Reduce number of test changes --- codefresh/resource_pipeline_test.go | 66 +++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 8 deletions(-) diff --git a/codefresh/resource_pipeline_test.go b/codefresh/resource_pipeline_test.go index 6d14be7..defe85c 100644 --- a/codefresh/resource_pipeline_test.go +++ b/codefresh/resource_pipeline_test.go @@ -23,7 +23,7 @@ func TestAccCodefreshPipeline_basic(t *testing.T) { CheckDestroy: testAccCheckCodefreshPipelineDestroy, Steps: []resource.TestStep{ { - Config: testAccCodefreshPipelineBasicConfig(name, "My pipeline", "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git"), + Config: testAccCodefreshPipelineBasicConfig(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git"), Check: resource.ComposeTestCheckFunc( testAccCheckCodefreshPipelineExists(resourceName), resource.TestCheckResourceAttr(resourceName, "name", name), @@ -289,7 +289,7 @@ func TestAccCodefreshPipeline_Revision(t *testing.T) { CheckDestroy: testAccCheckCodefreshPipelineDestroy, Steps: []resource.TestStep{ { - Config: testAccCodefreshPipelineBasicConfig(name, "My pipeline", "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git"), + Config: testAccCodefreshPipelineBasicConfig(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git"), Check: resource.ComposeTestCheckFunc( testAccCheckCodefreshPipelineExists(resourceName), resource.TestCheckResourceAttr(resourceName, "revision", "0"), @@ -301,7 +301,7 @@ func TestAccCodefreshPipeline_Revision(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccCodefreshPipelineBasicConfig(name, "My pipeline", "codefresh-contrib/react-sample-app", "./codefresh.yml", "development", "git"), + Config: testAccCodefreshPipelineBasicConfig(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "development", "git"), Check: resource.ComposeTestCheckFunc( testAccCheckCodefreshPipelineExists(resourceName), resource.TestCheckResourceAttr(resourceName, "revision", "1"), @@ -321,7 +321,7 @@ func TestAccCodefreshPipeline_IsPublic(t *testing.T) { CheckDestroy: testAccCheckCodefreshPipelineDestroy, Steps: []resource.TestStep{ { - Config: testAccCodefreshPipelineBasicConfig(name, "My pipeline","codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git"), + Config: testAccCodefreshPipelineBasicConfig(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git"), Check: resource.ComposeTestCheckFunc( testAccCheckCodefreshPipelineExists(resourceName), resource.TestCheckResourceAttr(resourceName, "is_public", "false"), @@ -366,7 +366,7 @@ func TestAccCodefreshPipelineOnCreateBranchIgnoreTrigger(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccCodefreshPipelineBasicConfig(name, "My pipeline", "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git"), + Config: testAccCodefreshPipelineBasicConfig(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git"), Check: resource.ComposeTestCheckFunc( testAccCheckCodefreshPipelineExists(resourceName), resource.TestCheckResourceAttr(resourceName, "name", name), @@ -427,7 +427,7 @@ func testAccCheckCodefreshPipelineDestroy(s *terraform.State) error { } // CONFIGS -func testAccCodefreshPipelineBasicConfig(rName, repo, description, path, revision, context string) string { +func testAccCodefreshPipelineBasicConfig(rName, repo, path, revision, context string) string { return fmt.Sprintf(` resource "codefresh_pipeline" "test" { @@ -440,7 +440,6 @@ resource "codefresh_pipeline" "test" { name = "%s" spec { - description = "%s" spec_template { repo = %q path = %q @@ -449,7 +448,7 @@ resource "codefresh_pipeline" "test" { } } } -`, rName, description, repo, path, revision, context) +`, rName, repo, path, revision, context) } func testAccCodefreshPipelineBasicConfigTags(rName, repo, path, revision, context, tag1, tag2 string) string { @@ -732,6 +731,57 @@ resource "codefresh_pipeline" "test" { `, rName, originalYamlString) } +func testAccCodefreshPipelineBasicConfigDescription(rName, repo, path, revision, context, description string) string { + return fmt.Sprintf(` +resource "codefresh_pipeline" "test" { + + lifecycle { + ignore_changes = [ + revision + ] + } + + name = "%s" + + spec { + spec_template { + repo = %q + path = %q + revision = %q + context = %q + } + + description = "%s" + } +} +`, rName, repo, path, revision, context, description) +} + +func TestAccCodefreshPipeline_Description(t *testing.T) { + name := pipelineNamePrefix + acctest.RandString(10) + resourceName := "codefresh_pipeline.test" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCodefreshPipelineDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCodefreshPipelineBasicConfigDescription(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git", "This is my pipeline, there are many like it but this one is mine"), + Check: resource.ComposeTestCheckFunc( + testAccCheckCodefreshPipelineExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "spec.0.description", "This is my pipeline, there are many like it but this one is mine"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccCodefreshPipeline_Contexts(t *testing.T) { name := pipelineNamePrefix + acctest.RandString(10) resourceName := "codefresh_pipeline.test" From dce70e028dad91acb8713e5758e7f028b047a847 Mon Sep 17 00:00:00 2001 From: Jake Nelson Date: Mon, 1 Nov 2021 01:59:56 +0000 Subject: [PATCH 3/3] Add description field to pipeline spec example --- examples/pipelines.md | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/pipelines.md b/examples/pipelines.md index 9ba47b4..42de3bb 100644 --- a/examples/pipelines.md +++ b/examples/pipelines.md @@ -34,6 +34,7 @@ resource "codefresh_pipeline" "test" { spec { concurrency = 1 priority = 5 + description = "This is my pipeline, there are many like it, but this one is mine." spec_template { repo = "codefresh-contrib/react-sample-app"