From a376883192bcabf73db5d5b3c9a0fd1457dc0c7c Mon Sep 17 00:00:00 2001 From: ssrish Date: Tue, 29 Jun 2021 08:22:36 -0700 Subject: [PATCH 1/4] add test file --- GNUmakefile | 4 + mso/resource_mso_schema_template_anp.go | 2 +- mso/resource_mso_schema_template_anp_test.go | 338 ++++++++++++++++++- 3 files changed, 335 insertions(+), 9 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index cacb6c97..41fabe59 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -17,6 +17,10 @@ test: fmtcheck testacc: fmtcheck TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m +testacccoverage: fmtcheck + -TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m -race -covermode=atomic -coverprofile=coverage.out + go tool cover -html=coverage.out + vet: @echo "go vet ." @go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \ diff --git a/mso/resource_mso_schema_template_anp.go b/mso/resource_mso_schema_template_anp.go index ee9331f2..fa5cc329 100644 --- a/mso/resource_mso_schema_template_anp.go +++ b/mso/resource_mso_schema_template_anp.go @@ -239,7 +239,7 @@ func resourceMSOSchemaTemplateAnpRead(d *schema.ResourceData, m interface{}) err log.Println("currentanpname", currentAnpName) if currentAnpName == anpName { log.Println("found correct anpname") - d.SetId(currentAnpName) + d.SetId(schemaId + "/templates/" + currentTemplateName + "/anps/" + currentAnpName) d.Set("name", currentAnpName) if anpCont.Exists("displayName") { d.Set("display_name", models.StripQuotes(anpCont.S("displayName").String())) diff --git a/mso/resource_mso_schema_template_anp_test.go b/mso/resource_mso_schema_template_anp_test.go index de4b6719..fafeac2b 100644 --- a/mso/resource_mso_schema_template_anp_test.go +++ b/mso/resource_mso_schema_template_anp_test.go @@ -2,6 +2,7 @@ package mso import ( "fmt" + "log" "testing" "github.com/ciscoecosystem/mso-go-client/client" @@ -10,7 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccSchemaTemplateAnp_Basic(t *testing.T) { +func TestAccMSOSchemaTemplateAnp_Basic(t *testing.T) { var s SchemaTemplateAnpTest resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -24,11 +25,130 @@ func TestAccSchemaTemplateAnp_Basic(t *testing.T) { testAccCheckMsoSchemaTemplateAnpAttributes("test1", &s), ), }, + { + //Config: testSchemaTemplateAnpConfig("anp123"), + ResourceName: "mso_schema_template_anp.anp1", + ImportState: true, + ImportStateVerify: true, + }, }, }) } -func TestAccMsoSchemaTemplateAnp_Update(t *testing.T) { +func TestAccMSOSchemaTemplateAnp_Basic2(t *testing.T) { + var s SchemaTemplateAnpTest + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckMsoSchemaTemplateAnpDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCheckMsoSchemaTemplateAnpConfig_basic2("test1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckMsoSchemaTemplateAnpExists("mso_schema.schema1", "mso_schema_template_anp.anp1", &s), + testAccCheckMsoSchemaTemplateAnpAttributes("test1", &s), + ), + }, + { + //Config: testSchemaTemplateAnpConfig("anp123"), + ResourceName: "mso_schema_template_anp.anp1", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +// func TestAccMSOSchemaTemplateAnp_ImportBasic(t *testing.T) { +// var s SchemaTemplateAnpTest +// resource.Test(t, resource.TestCase{ +// PreCheck: func() { testAccPreCheck(t) }, +// Providers: testAccProviders, +// CheckDestroy: testAccCheckMsoSchemaTemplateAnpDestroy, +// Steps: []resource.TestStep{ +// { +// Config: testAccCheckMsoSchemaTemplateAnpConfig_basic("anp123"), +// Check: resource.ComposeTestCheckFunc( +// testAccCheckMsoSchemaTemplateAnpExists("mso_schema.schema1", "mso_schema_template_anp.anp1", &s), +// ), +// }, +// { +// ResourceName: "mso_schema_template_anp.anp1", +// ImportState: true, +// ImportStateVerify: true, +// }, +// }, +// }) +// } + +// func testAccCheckMsoSchemaTemplateAnpConfig_importbasic(name string) string { +// return fmt.Sprintf(` + +// resource "mso_schema" "schema12" { +// name = "Schema2" +// template_name = "Template1" +// tenant_id = "5fb5fed8520000452a9e8911" + +// } +// resource "mso_schema_template_anp" "anp12" { +// schema_id=mso_schema.schema12.id +// template= "Template1" +// name = "anp123" +// display_name="%s" +// } +// `, name) +// } + +// func TestAccMSOSchemaTemplateAnp_ImportBasic(t *testing.T) { +// var s SchemaTemplateAnpTest +// resource.Test(t, resource.TestCase{ +// PreCheck: func() { testAccPreCheck(t) }, +// Providers: testAccProviders, +// CheckDestroy: testAccCheckMsoSchemaTemplateAnpDestroy, +// Steps: []resource.TestStep{ +// { + +// Check: resource.ComposeTestCheckFunc( +// testSchemaTemplateAnpConfig("anp123", &s), +// ), +// }, +// // { +// // Config: testSchemaTemplateAnpConfig("anp123"), +// // ResourceName: "mso_schema_template_anp.anp1", +// // ImportState: true, +// // ImportStateVerify: true, +// // }, +// }, +// }) +// } + +// func TestAccMSOSchemaTemplateAnp_Disappears(t *testing.T) { +// var s SchemaTemplateAnpTest + +// resource.Test(t, resource.TestCase{ +// PreCheck: func() { testAccPreCheck(t) }, +// Providers: testAccProviders, +// CheckDestroy: testAccCheckMsoSchemaTemplateAnpDestroy, +// Steps: []resource.TestStep{ +// { +// Config: testAccCheckMsoSchemaTemplateAnpConfig_basic("test1"), +// Check: resource.ComposeTestCheckFunc( +// testAccCheckMsoSchemaTemplateAnpExists("mso_schema.schema1", "mso_schema_template_anp.anp1", &s), +// testAccCheckMsoSchemaTemplateAnpAttributes("test1", &s), +// ), +// }, +// { +// Config: testAccCheckMsoSchemaTemplateAnpConfig_basic("test2"), +// Check: resource.ComposeTestCheckFunc( +// testAccCheckMsoSchemaTemplateAnpExists("mso_schema.schema1", "mso_schema_template_anp.anp1", &s), +// testAccCheckMsoSchemaTemplateAnpAttributes("test2", &s), +// ), +// }, +// }, +// }) +// } + +func TestAccMSOSchemaTemplateAnp_Update(t *testing.T) { var s SchemaTemplateAnpTest resource.Test(t, resource.TestCase{ @@ -54,24 +174,158 @@ func TestAccMsoSchemaTemplateAnp_Update(t *testing.T) { }) } +func TestAccMSOSchemaTemplateAnp_Update2(t *testing.T) { + var s SchemaTemplateAnpTest + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckMsoSchemaTemplateAnpDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCheckMsoSchemaTemplateAnpConfig_basic2("test1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckMsoSchemaTemplateAnpExists("mso_schema.schema1", "mso_schema_template_anp.anp1", &s), + testAccCheckMsoSchemaTemplateAnpAttributes("test1", &s), + ), + }, + { + Config: testAccCheckMsoSchemaTemplateAnpConfig_basic2("test2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckMsoSchemaTemplateAnpExists("mso_schema.schema1", "mso_schema_template_anp.anp1", &s), + testAccCheckMsoSchemaTemplateAnpAttributes("test2", &s), + ), + }, + }, + }) +} + +// func TestAccMSOSchemaTemplateAnp_Update2(t *testing.T) { +// var s SchemaTemplateAnpTest + +// resource.Test(t, resource.TestCase{ +// PreCheck: func() { testAccPreCheck(t) }, +// Providers: testAccProviders, +// CheckDestroy: testAccCheckMsoSchemaTemplateAnpDestroy, +// Steps: []resource.TestStep{ +// { +// Config: testAccCheckMsoSchemaTemplateAnpConfig_basic("test1"), +// Check: resource.ComposeTestCheckFunc( +// testAccCheckMsoSchemaTemplateAnpExists("mso_schema.schema1", "mso_schema_template_anp.anp1", &s), +// testAccCheckMsoSchemaTemplateAnpAttributes("test1", &s), +// ), +// }, +// { +// Config: testAccCheckMsoSchemaTemplateAnpConfig_basic("test2"), +// Check: resource.ComposeTestCheckFunc( +// testAccCheckMsoSchemaTemplateAnpExists("mso_schema.schema1", "mso_schema_template_anp.anp1", &s), +// testAccCheckMsoSchemaTemplateAnpAttributes("test2", &s), +// ), +// }, +// }, +// }) +// } + func testAccCheckMsoSchemaTemplateAnpConfig_basic(name string) string { return fmt.Sprintf(` resource "mso_schema" "schema1" { - name = "Shah200" - template_name = "template99" - tenant_id = "5ea7e44b2c00007ebb0a2781" + name = "Schema2" + template_name = "Template1" + tenant_id = "5fb5fed8520000452a9e8911" } resource "mso_schema_template_anp" "anp1" { - schema_id="${mso_schema.schema1.id}" - template= "template99" + schema_id=mso_schema.schema1.id + template= "Template1" name = "anp123" display_name="%s" } `, name) } +func testAccCheckMsoSchemaTemplateAnpConfig_basic2(name string) string { + return fmt.Sprintf(` + + resource "mso_schema" "schema1" { + name = "Schema2" + template_name = "Template1" + tenant_id = "5fb5fed8520000452a9e8911" + + } + resource "mso_schema_template_anp" "anp1" { + schema_id=mso_schema.schema1.id + template= "Template2" + name = "anp123" + display_name="%s" + } + `, name) +} + +func testAccCheckMsoSchemaTemplateAnpConfig_basic3(name string) string { + return fmt.Sprintf(` + + resource "mso_schema" "schema1" { + name = "Schema2" + template_name = "Template1" + tenant_id = "5fb5fed8520000452a9e8911" + + } + resource "mso_schema_template_anp" "anp1" { + schema_id=mso_schema.schema1.id + template= "Template2" + name = "anp123" + display_name="%s" + } + `, name) +} + +// func testSchemaTemplateAnpConfig(name string, stv *SchemaTemplateAnpTest) resource.TestCheckFunc { +// client := testAccProvider.Meta().(*client.Client) +// cont, err := client.GetViaURL(fmt.Sprintf("api/v1/schemas/%s", "60c1d2255100002f1b4a34ce")) +// if err != nil { +// return nil +// } +// // d := SchemaTemplateAnpTest{} +// // d.SchemaId := "60c1d2255100002f1b4a34ce" +// count, err := cont.ArrayCount("templates") +// if err != nil { +// return nil +// } + +// for i := 0; i < count; i++ { + +// tempCont, err := cont.ArrayElement(i, "templates") +// if err != nil { +// return nil +// } +// currentTemplateName := models.StripQuotes(tempCont.S("name").String()) + +// if currentTemplateName == "Template1" { +// anpCount, err := tempCont.ArrayCount("anps") + +// if err != nil { +// return nil +// } +// for j := 0; j < anpCount; j++ { +// anpCont, err := tempCont.ArrayElement(j, "anps") + +// if err != nil { +// return nil +// } +// currentAnpName := models.StripQuotes(anpCont.S("name").String()) +// if currentAnpName == name { +// if anpCont.Exists("displayName") { +// return nil +// } +// } +// } +// } +// } + +// return nil +// } + func testAccCheckMsoSchemaTemplateAnpExists(schemaName string, schemaTemplateAnpName string, stv *SchemaTemplateAnpTest) resource.TestCheckFunc { return func(s *terraform.State) error { rs1, err1 := s.RootModule().Resources[schemaName] @@ -93,6 +347,7 @@ func testAccCheckMsoSchemaTemplateAnpExists(schemaName string, schemaTemplateAnp client := testAccProvider.Meta().(*client.Client) con, err := client.GetViaURL("api/v1/schemas/" + rs1.Primary.ID) + log.Print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") if err != nil { return err @@ -131,12 +386,79 @@ func testAccCheckMsoSchemaTemplateAnpExists(schemaName string, schemaTemplateAnp } stvc := &stvt - + log.Printf(fmt.Sprint(stvt.DisplayName)) *stv = *stvc return nil } } +// func testAccCheckMsoSchemaTemplateAnpExists(schemaName string, schemaTemplateAnpName string, stv *SchemaTemplateAnpTest) resource.TestCheckFunc { +// return func(s *terraform.State) error { +// rs1, err1 := s.RootModule().Resources[schemaName] +// rs2, err2 := s.RootModule().Resources[schemaTemplateAnpName] + +// if !err1 { +// return fmt.Errorf("Schema %s not found", schemaName) +// } +// if !err2 { +// return fmt.Errorf("Schema Template Anp record %s not found", schemaTemplateAnpName) +// } + +// if rs1.Primary.ID == "" { +// return fmt.Errorf("No Schema id was set") +// } +// if rs2.Primary.ID == "" { +// return fmt.Errorf("No Schema Template Anp id was set") +// } + +// client := testAccProvider.Meta().(*client.Client) +// con, err := client.GetViaURL("api/v1/schemas/" + rs1.Primary.ID) + +// if err != nil { +// return err +// } + +// stvt := SchemaTemplateAnpTest{} +// stvt.SchemaId = rs1.Primary.ID + +// count, err := con.ArrayCount("templates") +// if err != nil { +// return err +// } + +// for i := 0; i < count; i++ { +// tempCont, err := con.ArrayElement(i, "templates") +// stvt.Template = models.StripQuotes(tempCont.S("name").String()) +// anpCount, err := tempCont.ArrayCount("anps") +// if err != nil { +// return fmt.Errorf("No Anp found") +// } +// for j := 0; j < anpCount; j++ { +// anpCont, err := tempCont.ArrayElement(j, "anps") +// if err != nil { +// return err +// } +// if anpCont.Exists("name") { +// stvt.Name = models.StripQuotes(anpCont.S("name").String()) + +// } + +// if anpCont.Exists("displayName") { +// stvt.DisplayName = models.StripQuotes(anpCont.S("displayName").String()) +// } + +// } +// } + +// stvc := &stvt +// log.Printf("^^^^^^^^^^^^^^^^^^^") +// log.Printf(fmt.Sprintf(stvt.Name)) + +// *stv = *stvc +// return nil +// } +// } + func testAccCheckMsoSchemaTemplateAnpDestroy(s *terraform.State) error { client := testAccProvider.Meta().(*client.Client) From 84e56933992000d64258e04a5be30eb07ca7603b Mon Sep 17 00:00:00 2001 From: ssrish Date: Tue, 13 Jul 2021 07:30:23 -0700 Subject: [PATCH 2/4] add few features to test file --- mso/resource_mso_schema_template_anp_test.go | 558 +++++++++++-------- 1 file changed, 317 insertions(+), 241 deletions(-) diff --git a/mso/resource_mso_schema_template_anp_test.go b/mso/resource_mso_schema_template_anp_test.go index fafeac2b..82aeec42 100644 --- a/mso/resource_mso_schema_template_anp_test.go +++ b/mso/resource_mso_schema_template_anp_test.go @@ -3,6 +3,7 @@ package mso import ( "fmt" "log" + "regexp" "testing" "github.com/ciscoecosystem/mso-go-client/client" @@ -11,7 +12,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccMSOSchemaTemplateAnp_Basic(t *testing.T) { +func TestAccMSOSchemaTemplateAnp_Create(t *testing.T) { var s SchemaTemplateAnpTest resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -19,7 +20,7 @@ func TestAccMSOSchemaTemplateAnp_Basic(t *testing.T) { CheckDestroy: testAccCheckMsoSchemaTemplateAnpDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckMsoSchemaTemplateAnpConfig_basic("test1"), + Config: testAccCheckMsoSchemaTemplateAnpConfig_Create("test1"), Check: resource.ComposeTestCheckFunc( testAccCheckMsoSchemaTemplateAnpExists("mso_schema.schema1", "mso_schema_template_anp.anp1", &s), testAccCheckMsoSchemaTemplateAnpAttributes("test1", &s), @@ -35,15 +36,15 @@ func TestAccMSOSchemaTemplateAnp_Basic(t *testing.T) { }) } -func TestAccMSOSchemaTemplateAnp_Basic2(t *testing.T) { +func TestAccMSOSchemaTemplateAnp_CreateError(t *testing.T) { var s SchemaTemplateAnpTest resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckMsoSchemaTemplateAnpDestroy, + //PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + //CheckDestroy: testAccCheckMsoSchemaTemplateAnpDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckMsoSchemaTemplateAnpConfig_basic2("test1"), + Config: testAccCheckMsoSchemaTemplateAnpConfig_CreateError("test1"), Check: resource.ComposeTestCheckFunc( testAccCheckMsoSchemaTemplateAnpExists("mso_schema.schema1", "mso_schema_template_anp.anp1", &s), testAccCheckMsoSchemaTemplateAnpAttributes("test1", &s), @@ -59,6 +60,276 @@ func TestAccMSOSchemaTemplateAnp_Basic2(t *testing.T) { }) } +func TestAccMSOSchemaTemplateAnp_Name(t *testing.T) { + resource.Test(t, resource.TestCase{ + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testViewConfigNameError("test"), + ExpectError: regexp.MustCompile("errors during apply: \"Resource Not Found: template with name Template5 not found in List(Template1)\"" + "{}"), + }, + }, + }) +} + +func testViewConfigNameError(name string) string { + return fmt.Sprintf(` + + resource "mso_schema" "schema1" { + name = "Schema2" + template_name = "Template1" + tenant_id = "5fb5fed8520000452a9e8911" + + } + resource "mso_schema_template_anp" "anp1" { + schema_id=mso_schema.schema1.id + template= "Template5" + name = "anp123" + display_name="%s" + } + `, name) +} + +func TestAccMSOSchemaTemplateAnp_Update(t *testing.T) { + var s SchemaTemplateAnpTest + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckMsoSchemaTemplateAnpDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCheckMsoSchemaTemplateAnpConfig_CreateError("test1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckMsoSchemaTemplateAnpExists("mso_schema.schema1", "mso_schema_template_anp.anp1", &s), + testAccCheckMsoSchemaTemplateAnpAttributes("test1", &s), + ), + }, + { + Config: testAccCheckMsoSchemaTemplateAnpConfig_CreateError("test2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckMsoSchemaTemplateAnpExists("mso_schema.schema1", "mso_schema_template_anp.anp1", &s), + testAccCheckMsoSchemaTemplateAnpAttributes("test2", &s), + ), + }, + }, + }) +} + +func TestAccMSOSchemaTemplateAnp_UpdateError(t *testing.T) { + var s SchemaTemplateAnpTest + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckMsoSchemaTemplateAnpDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCheckMsoSchemaTemplateAnpConfig_UpdateError("test1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckMsoSchemaTemplateAnpExists("mso_schema.schema1", "mso_schema_template_anp.anp1", &s), + testAccCheckMsoSchemaTemplateAnpAttributes("test1", &s), + ), + }, + }, + }) +} + +func testAccCheckMsoSchemaTemplateAnpConfig_Create(name string) string { + return fmt.Sprintf(` + + resource "mso_schema" "schema1" { + name = "Schema2" + template_name = "Template1" + tenant_id = "5fb5fed8520000452a9e8911" + + } + resource "mso_schema_template_anp" "anp1" { + schema_id=mso_schema.schema1.id + template= "Template1" + name = "anp123" + display_name="%s" + } + `, name) +} + +func testAccCheckMsoSchemaTemplateAnpConfig_CreateError(name string) string { + return fmt.Sprintf(` + + resource "mso_schema" "schema1" { + name = "Schema2" + template_name = "Template1" + tenant_id = "5fb5fed8520000452a9e8911" + + } + + resource "mso_schema_template_anp" "anp1" { + schema_id=mso_schema.schema1.id + template= "Template1" + name = "anp123" + display_name="%s" + } + `, name) +} + +func testAccCheckMsoSchemaTemplateAnpConfig_UpdateError(name string) string { + return fmt.Sprintf(` + + resource "mso_schema" "schema1" { + name = "Schema2" + template_name = "Template1" + tenant_id = "5fb5fed8520000452a9e8911" + + } + resource "mso_schema_template_anp" "anp1" { + schema_id=mso_schema.schema1.id + template= "Template1" + name = "anp123" + display_name="test1" + } + resource "mso_schema_template_anp" "anp2" { + schema_id=mso_schema.schema1.id + template= "Template1" + name = "anp123" + display_name="%s" + } + `, name) +} + +func testAccCheckMsoSchemaTemplateAnpExists(schemaName string, schemaTemplateAnpName string, stv *SchemaTemplateAnpTest) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs1, err1 := s.RootModule().Resources[schemaName] + rs2, err2 := s.RootModule().Resources[schemaTemplateAnpName] + + if !err1 { + return fmt.Errorf("Schema %s not found", schemaName) + } + if !err2 { + return fmt.Errorf("Schema Template Anp record %s not found", schemaTemplateAnpName) + } + + if rs1.Primary.ID == "" { + return fmt.Errorf("No Schema id was set") + } + if rs2.Primary.ID == "" { + return fmt.Errorf("No Schema Template Anp id was set") + } + + client := testAccProvider.Meta().(*client.Client) + con, err := client.GetViaURL("api/v1/schemas/" + rs1.Primary.ID) + log.Print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") + + if err != nil { + return err + } + + stvt := SchemaTemplateAnpTest{} + stvt.SchemaId = rs1.Primary.ID + + count, err := con.ArrayCount("templates") + if err != nil { + return err + } + + for i := 0; i < count; i++ { + tempCont, err := con.ArrayElement(i, "templates") + stvt.Template = models.StripQuotes(tempCont.S("name").String()) + anpCount, err := tempCont.ArrayCount("anps") + if err != nil { + return fmt.Errorf("No Anp found") + } + for j := 0; j < anpCount; j++ { + anpCont, err := tempCont.ArrayElement(j, "anps") + if err != nil { + return err + } + if anpCont.Exists("name") { + stvt.Name = models.StripQuotes(anpCont.S("name").String()) + + } + + if anpCont.Exists("displayName") { + stvt.DisplayName = models.StripQuotes(anpCont.S("displayName").String()) + } + + } + } + + stvc := &stvt + log.Printf(fmt.Sprint(stvt.DisplayName)) + *stv = *stvc + return nil + } +} + +func testAccCheckMsoSchemaTemplateAnpDestroy(s *terraform.State) error { + client := testAccProvider.Meta().(*client.Client) + + rs1, err1 := s.RootModule().Resources["mso_schema.schema1"] + + if !err1 { + return fmt.Errorf("Schema %s not found", "mso_schema.schema1") + } + + schemaid := rs1.Primary.ID + for _, rs := range s.RootModule().Resources { + + if rs.Type == "mso_schema_template_anp" { + con, err := client.GetViaURL(fmt.Sprintf("api/v1/schemas/%s", schemaid)) + if err != nil { + return nil + } else { + count, err := con.ArrayCount("templates") + if err != nil { + return fmt.Errorf("No Template found") + } + for i := 0; i < count; i++ { + tempCont, err := con.ArrayElement(i, "templates") + if err != nil { + return fmt.Errorf("No template exists") + } + anpCount, err := tempCont.ArrayCount("anps") + if err != nil { + return fmt.Errorf("No Anp found") + } + for j := 0; j < anpCount; j++ { + anpCont, err := tempCont.ArrayElement(j, "anps") + if err != nil { + return err + } + name := models.StripQuotes(anpCont.S("name").String()) + + if rs.Primary.ID == name { + return fmt.Errorf("Schema Template Anp record still exists") + + } + + } + } + } + } + } + return nil +} + +func testAccCheckMsoSchemaTemplateAnpAttributes(name string, stv *SchemaTemplateAnpTest) resource.TestCheckFunc { + return func(s *terraform.State) error { + if name != stv.DisplayName { + return fmt.Errorf("Bad Schema Template Anp Name %s", stv.DisplayName) + } + return nil + } +} + +type SchemaTemplateAnpTest struct { + Id string `json:",omitempty"` + SchemaId string `json:",omitempty"` + Template string `json:",omitempty"` + Name string `json:",omitempty"` + DisplayName string `json:",omitempty"` +} + +//*************************************EXPERIMENT******************* // func TestAccMSOSchemaTemplateAnp_ImportBasic(t *testing.T) { // var s SchemaTemplateAnpTest // resource.Test(t, resource.TestCase{ @@ -148,57 +419,31 @@ func TestAccMSOSchemaTemplateAnp_Basic2(t *testing.T) { // }) // } -func TestAccMSOSchemaTemplateAnp_Update(t *testing.T) { - var s SchemaTemplateAnpTest - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckMsoSchemaTemplateAnpDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckMsoSchemaTemplateAnpConfig_basic("test1"), - Check: resource.ComposeTestCheckFunc( - testAccCheckMsoSchemaTemplateAnpExists("mso_schema.schema1", "mso_schema_template_anp.anp1", &s), - testAccCheckMsoSchemaTemplateAnpAttributes("test1", &s), - ), - }, - { - Config: testAccCheckMsoSchemaTemplateAnpConfig_basic("test2"), - Check: resource.ComposeTestCheckFunc( - testAccCheckMsoSchemaTemplateAnpExists("mso_schema.schema1", "mso_schema_template_anp.anp1", &s), - testAccCheckMsoSchemaTemplateAnpAttributes("test2", &s), - ), - }, - }, - }) -} - -func TestAccMSOSchemaTemplateAnp_Update2(t *testing.T) { - var s SchemaTemplateAnpTest +// func TestAccMSOSchemaTemplateAnp_UpdateError(t *testing.T) { +// var s SchemaTemplateAnpTest - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckMsoSchemaTemplateAnpDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckMsoSchemaTemplateAnpConfig_basic2("test1"), - Check: resource.ComposeTestCheckFunc( - testAccCheckMsoSchemaTemplateAnpExists("mso_schema.schema1", "mso_schema_template_anp.anp1", &s), - testAccCheckMsoSchemaTemplateAnpAttributes("test1", &s), - ), - }, - { - Config: testAccCheckMsoSchemaTemplateAnpConfig_basic2("test2"), - Check: resource.ComposeTestCheckFunc( - testAccCheckMsoSchemaTemplateAnpExists("mso_schema.schema1", "mso_schema_template_anp.anp1", &s), - testAccCheckMsoSchemaTemplateAnpAttributes("test2", &s), - ), - }, - }, - }) -} +// resource.Test(t, resource.TestCase{ +// PreCheck: func() { testAccPreCheck(t) }, +// Providers: testAccProviders, +// CheckDestroy: testAccCheckMsoSchemaTemplateAnpDestroy, +// Steps: []resource.TestStep{ +// { +// Config: testAccCheckMsoSchemaTemplateAnpConfig_Create("test1"), +// Check: resource.ComposeTestCheckFunc( +// testAccCheckMsoSchemaTemplateAnpExists("mso_schema.schema1", "mso_schema_template_anp.anp1", &s), +// testAccCheckMsoSchemaTemplateAnpAttributes("test1", &s), +// ), +// }, +// { +// Config: testAccCheckMsoSchemaTemplateAnpConfig_UpdateError("test2qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq"), +// Check: resource.ComposeTestCheckFunc( +// testAccCheckMsoSchemaTemplateAnpExists("mso_schema.schema1", "mso_schema_template_anp.anp1", &s), +// testAccCheckMsoSchemaTemplateAnpAttributes("test2qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", &s), +// ), +// }, +// }, +// }) +// } // func TestAccMSOSchemaTemplateAnp_Update2(t *testing.T) { // var s SchemaTemplateAnpTest @@ -226,59 +471,23 @@ func TestAccMSOSchemaTemplateAnp_Update2(t *testing.T) { // }) // } -func testAccCheckMsoSchemaTemplateAnpConfig_basic(name string) string { - return fmt.Sprintf(` - - resource "mso_schema" "schema1" { - name = "Schema2" - template_name = "Template1" - tenant_id = "5fb5fed8520000452a9e8911" - - } - resource "mso_schema_template_anp" "anp1" { - schema_id=mso_schema.schema1.id - template= "Template1" - name = "anp123" - display_name="%s" - } - `, name) -} - -func testAccCheckMsoSchemaTemplateAnpConfig_basic2(name string) string { - return fmt.Sprintf(` - - resource "mso_schema" "schema1" { - name = "Schema2" - template_name = "Template1" - tenant_id = "5fb5fed8520000452a9e8911" - - } - resource "mso_schema_template_anp" "anp1" { - schema_id=mso_schema.schema1.id - template= "Template2" - name = "anp123" - display_name="%s" - } - `, name) -} +// func testAccCheckMsoSchemaTemplateAnpConfig_UpdateError(name string) string { +// return fmt.Sprintf(` -func testAccCheckMsoSchemaTemplateAnpConfig_basic3(name string) string { - return fmt.Sprintf(` +// resource "mso_schema" "schema1" { +// name = "Schema2" +// template_name = "Template1" +// tenant_id = "5fb5fed8520000452a9e8911" - resource "mso_schema" "schema1" { - name = "Schema2" - template_name = "Template1" - tenant_id = "5fb5fed8520000452a9e8911" - - } - resource "mso_schema_template_anp" "anp1" { - schema_id=mso_schema.schema1.id - template= "Template2" - name = "anp123" - display_name="%s" - } - `, name) -} +// } +// resource "mso_schema_template_anp" "anp1" { +// schema_id="qqqqqq" +// template= "Template1" +// name = "anp123" +// display_name="%s" +// } +// `, name) +// } // func testSchemaTemplateAnpConfig(name string, stv *SchemaTemplateAnpTest) resource.TestCheckFunc { // client := testAccProvider.Meta().(*client.Client) @@ -326,72 +535,6 @@ func testAccCheckMsoSchemaTemplateAnpConfig_basic3(name string) string { // return nil // } -func testAccCheckMsoSchemaTemplateAnpExists(schemaName string, schemaTemplateAnpName string, stv *SchemaTemplateAnpTest) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs1, err1 := s.RootModule().Resources[schemaName] - rs2, err2 := s.RootModule().Resources[schemaTemplateAnpName] - - if !err1 { - return fmt.Errorf("Schema %s not found", schemaName) - } - if !err2 { - return fmt.Errorf("Schema Template Anp record %s not found", schemaTemplateAnpName) - } - - if rs1.Primary.ID == "" { - return fmt.Errorf("No Schema id was set") - } - if rs2.Primary.ID == "" { - return fmt.Errorf("No Schema Template Anp id was set") - } - - client := testAccProvider.Meta().(*client.Client) - con, err := client.GetViaURL("api/v1/schemas/" + rs1.Primary.ID) - log.Print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") - - if err != nil { - return err - } - - stvt := SchemaTemplateAnpTest{} - stvt.SchemaId = rs1.Primary.ID - - count, err := con.ArrayCount("templates") - if err != nil { - return err - } - - for i := 0; i < count; i++ { - tempCont, err := con.ArrayElement(i, "templates") - stvt.Template = models.StripQuotes(tempCont.S("name").String()) - anpCount, err := tempCont.ArrayCount("anps") - if err != nil { - return fmt.Errorf("No Anp found") - } - for j := 0; j < anpCount; j++ { - anpCont, err := tempCont.ArrayElement(j, "anps") - if err != nil { - return err - } - if anpCont.Exists("name") { - stvt.Name = models.StripQuotes(anpCont.S("name").String()) - - } - - if anpCont.Exists("displayName") { - stvt.DisplayName = models.StripQuotes(anpCont.S("displayName").String()) - } - - } - } - - stvc := &stvt - log.Printf(fmt.Sprint(stvt.DisplayName)) - *stv = *stvc - return nil - } -} - // func testAccCheckMsoSchemaTemplateAnpExists(schemaName string, schemaTemplateAnpName string, stv *SchemaTemplateAnpTest) resource.TestCheckFunc { // return func(s *terraform.State) error { // rs1, err1 := s.RootModule().Resources[schemaName] @@ -458,70 +601,3 @@ func testAccCheckMsoSchemaTemplateAnpExists(schemaName string, schemaTemplateAnp // return nil // } // } - -func testAccCheckMsoSchemaTemplateAnpDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*client.Client) - - rs1, err1 := s.RootModule().Resources["mso_schema.schema1"] - - if !err1 { - return fmt.Errorf("Schema %s not found", "mso_schema.schema1") - } - - schemaid := rs1.Primary.ID - for _, rs := range s.RootModule().Resources { - - if rs.Type == "mso_schema_template_anp" { - con, err := client.GetViaURL(fmt.Sprintf("api/v1/schemas/%s", schemaid)) - if err != nil { - return nil - } else { - count, err := con.ArrayCount("templates") - if err != nil { - return fmt.Errorf("No Template found") - } - for i := 0; i < count; i++ { - tempCont, err := con.ArrayElement(i, "templates") - if err != nil { - return fmt.Errorf("No template exists") - } - anpCount, err := tempCont.ArrayCount("anps") - if err != nil { - return fmt.Errorf("No Anp found") - } - for j := 0; j < anpCount; j++ { - anpCont, err := tempCont.ArrayElement(j, "anps") - if err != nil { - return err - } - name := models.StripQuotes(anpCont.S("name").String()) - - if rs.Primary.ID == name { - return fmt.Errorf("Schema Template Anp record still exists") - - } - - } - } - } - } - } - return nil -} - -func testAccCheckMsoSchemaTemplateAnpAttributes(name string, stv *SchemaTemplateAnpTest) resource.TestCheckFunc { - return func(s *terraform.State) error { - if name != stv.DisplayName { - return fmt.Errorf("Bad Schema Template Anp Name %s", stv.DisplayName) - } - return nil - } -} - -type SchemaTemplateAnpTest struct { - Id string `json:",omitempty"` - SchemaId string `json:",omitempty"` - Template string `json:",omitempty"` - Name string `json:",omitempty"` - DisplayName string `json:",omitempty"` -} From 7a7c7b03968f7ac0e172d0911d72e738a57f88b4 Mon Sep 17 00:00:00 2001 From: ssrish Date: Mon, 19 Jul 2021 17:20:10 -0700 Subject: [PATCH 3/4] increase test coverage for few resources beyond 85 --- ...e_mso_schema_site_anp_epg_selector_test.go | 173 +++++++++-- mso/resource_mso_schema_template.go | 6 +- mso/resource_mso_schema_template_anp_test.go | 280 +----------------- mso/resource_mso_schema_template_bd_subnet.go | 9 +- ...urce_mso_schema_template_bd_subnet_test.go | 83 ++++-- ...source_mso_schema_template_filter_entry.go | 4 +- ...e_mso_schema_template_filter_entry_test.go | 92 +++++- mso/resource_mso_schema_template_l3out.go | 2 +- ...resource_mso_schema_template_l3out_test.go | 82 +++-- mso/resource_mso_schema_template_test.go | 35 ++- mso/resource_mso_schema_template_vrf.go | 2 +- mso/resource_mso_schema_template_vrf_test.go | 33 ++- mso/resource_mso_schema_test.go | 11 +- mso/resource_mso_template_bd.go | 8 +- mso/resource_mso_template_bd_test.go | 74 ++++- ...schema_template_filter_entry.html.markdown | 2 +- 16 files changed, 480 insertions(+), 416 deletions(-) diff --git a/mso/resource_mso_schema_site_anp_epg_selector_test.go b/mso/resource_mso_schema_site_anp_epg_selector_test.go index 5c2b075f..9c126433 100644 --- a/mso/resource_mso_schema_site_anp_epg_selector_test.go +++ b/mso/resource_mso_schema_site_anp_epg_selector_test.go @@ -11,6 +11,16 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) +// func TestAccMSOSchemaSiteAnpEpgSelector_Initial(t *testing.T) { +// resource.Test(t, resource.TestCase{ +// Providers: testAccProviders, +// Steps: []resource.TestStep{ +// { +// Config: testAccCheckMSOSiteAnpEpgSelectorConfig_initial("ANP"), +// }, +// }, +// }) +// } func TestAccMSOSchemaSiteAnpEpgSelector_Basic(t *testing.T) { var ss SiteAnpEpgSelectorTest resource.Test(t, resource.TestCase{ @@ -21,10 +31,16 @@ func TestAccMSOSchemaSiteAnpEpgSelector_Basic(t *testing.T) { { Config: testAccCheckMSOSiteAnpEpgSelectorConfig_basic("one"), Check: resource.ComposeTestCheckFunc( - testAccCheckMSOSchemaSiteAnpEpgSelectorExists("mso_schema_site_anp_epg_selector.selector1", &ss), + testAccCheckMSOSchemaSiteAnpEpgSelectorExists("mso_schema.schema1", "mso_schema_site_anp_epg_selector.selector1", &ss), testAccCheckMSOSchemaSiteAnpEpgSelectorAttributes("one", &ss), ), }, + + { + ResourceName: "mso_schema_site_anp_epg_selector.selector1", + ImportState: true, + ImportStateVerify: true, + }, }, }) } @@ -40,14 +56,14 @@ func TestAccMSOSchemaSiteAnpEpgSelector_Update(t *testing.T) { { Config: testAccCheckMSOSiteAnpEpgSelectorConfig_basic("one"), Check: resource.ComposeTestCheckFunc( - testAccCheckMSOSchemaSiteAnpEpgSelectorExists("mso_schema_site_anp_epg_selector.selector1", &ss), + testAccCheckMSOSchemaSiteAnpEpgSelectorExists("mso_schema.schema1", "mso_schema_site_anp_epg_selector.selector1", &ss), testAccCheckMSOSchemaSiteAnpEpgSelectorAttributes("one", &ss), ), }, { Config: testAccCheckMSOSiteAnpEpgSelectorConfig_basic("two"), Check: resource.ComposeTestCheckFunc( - testAccCheckMSOSchemaSiteAnpEpgSelectorExists("mso_schema_site_anp_epg_selector.selector1", &ss), + testAccCheckMSOSchemaSiteAnpEpgSelectorExists("mso_schema.schema1", "mso_schema_site_anp_epg_selector.selector1", &ss), testAccCheckMSOSchemaSiteAnpEpgSelectorAttributes("two", &ss), ), }, @@ -57,35 +73,150 @@ func TestAccMSOSchemaSiteAnpEpgSelector_Update(t *testing.T) { func testAccCheckMSOSiteAnpEpgSelectorConfig_basic(key string) string { return fmt.Sprintf(` + resource "mso_schema" "schema1" { + name = "Schema2" + template_name = "Template1" + tenant_id = "5fb5fed8520000452a9e8911" + + } + + resource "mso_schema_template_vrf" "vrf1" { + schema_id = mso_schema.schema1.id + template = mso_schema.schema1.template_name + name = "VRF" + display_name = "vz1" + layer3_multicast= false + vzany = false + } + + resource "mso_rest" "azure_site" { + path = "api/v1/schemas/${mso_schema.schema1.id}" + method = "PATCH" + + payload = < ```bash -terraform import mso_schema_template_filter_entry.filter_entry {schema_id}/template/{template_name}/filter/{name} +terraform import mso_schema_template_filter_entry.filter_entry {schema_id}/template/{template_name}/filter/{filter_name}/filter_entry/{name} ``` \ No newline at end of file From e3a367e309b04eaf7084df86e55cf196952d4026 Mon Sep 17 00:00:00 2001 From: ssrish Date: Tue, 27 Jul 2021 09:53:29 -0700 Subject: [PATCH 4/4] modification to mso_rest, site selector and its test file --- mso/resource_mso_rest.go | 45 ++- ...source_mso_schema_site_anp_epg_selector.go | 37 ++- ...e_mso_schema_site_anp_epg_selector_test.go | 291 +++++++++--------- mso/resource_mso_schema_template_vrf.go | 2 +- mso/resource_mso_template_bd_test.go | 2 +- 5 files changed, 199 insertions(+), 178 deletions(-) diff --git a/mso/resource_mso_rest.go b/mso/resource_mso_rest.go index 323b6b63..ca37792a 100644 --- a/mso/resource_mso_rest.go +++ b/mso/resource_mso_rest.go @@ -37,6 +37,17 @@ func resourceMSORest() *schema.Resource { Type: schema.TypeString, Required: true, }, + + "ignore_on_destroy": &schema.Schema{ + Type: schema.TypeBool, + Required: true, + }, + + "schema_id": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, }), } } @@ -93,22 +104,26 @@ func resourceMSORestUpdate(d *schema.ResourceData, m interface{}) error { } func resourceMSORestDelete(d *schema.ResourceData, m interface{}) error { - var method, path, payload string - path = d.Get("path").(string) - payload = d.Get("payload").(string) - if tempVar, ok := d.GetOk("method"); ok { - method = tempVar.(string) - } else { - method = "DELETE" - } - if !contains(HTTP_METHODS, method) { - return fmt.Errorf("Invalid method %s passed", method) - } - msoClient := m.(*client.Client) - _, err := MakeRestRequest(msoClient, path, method, payload) + var ignore_on_destroy = d.Get("ignore_on_destroy").(bool) + if ignore_on_destroy == false { + var method, path, payload string + path = d.Get("path").(string) + payload = d.Get("payload").(string) + if tempVar, ok := d.GetOk("method"); ok { + method = tempVar.(string) + } else { + method = "DELETE" + } + if !contains(HTTP_METHODS, method) { + return fmt.Errorf("Invalid method %s passed", method) + } - if err != nil { - return err + msoClient := m.(*client.Client) + _, err := MakeRestRequest(msoClient, path, method, payload) + + if err != nil { + return err + } } d.SetId("") return nil diff --git a/mso/resource_mso_schema_site_anp_epg_selector.go b/mso/resource_mso_schema_site_anp_epg_selector.go index e4b1eca8..5d1288df 100644 --- a/mso/resource_mso_schema_site_anp_epg_selector.go +++ b/mso/resource_mso_schema_site_anp_epg_selector.go @@ -104,18 +104,29 @@ func resourceMSOSchemaSiteAnpEpgSelector() *schema.Resource { } } +var importReadSchemaID, importReadSiteID, importReadTemplate, importReadANP, importReadEPG string + func resourceSchemaSiteApnEpgSelectorImport(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) { log.Printf("[DEBUG] %s: Beginning Import", d.Id()) found := false msoClient := m.(*client.Client) - get_attribute := strings.Split(d.Id(), "/") - schemaID := get_attribute[0] - siteID := get_attribute[2] - template := get_attribute[4] - anpName := get_attribute[6] - epgName := get_attribute[8] - name := get_attribute[10] - + var schemaID, siteID, template, anpName, epgName, name string + if !strings.Contains(d.Id(), "/") { + name = d.Id() + schemaID = importReadSchemaID + siteID = importReadSiteID + template = importReadTemplate + anpName = importReadANP + epgName = importReadEPG + } else { + get_attribute := strings.Split(d.Id(), "/") + schemaID = get_attribute[0] + siteID = get_attribute[2] + template = get_attribute[4] + anpName = get_attribute[6] + epgName = get_attribute[8] + name = get_attribute[10] + } cont, err := msoClient.GetViaURL(fmt.Sprintf("api/v1/schemas/%s", schemaID)) if err != nil { return nil, err @@ -180,7 +191,7 @@ func resourceSchemaSiteApnEpgSelectorImport(d *schema.ResourceData, m interface{ currentName := models.StripQuotes(selectorCont.S("name").String()) if currentName == name { found = true - d.SetId(name) + d.SetId(currentName) d.Set("name", currentName) exps := selectorCont.S("expressions").Data().([]interface{}) @@ -357,14 +368,17 @@ func resourceSchemaSiteApnEpgSelectorUpdate(d *schema.ResourceData, m interface{ func resourceSchemaSiteApnEpgSelectorRead(d *schema.ResourceData, m interface{}) error { found := false msoClient := m.(*client.Client) - dn := d.Id() schemaID := d.Get("schema_id").(string) siteID := d.Get("site_id").(string) template := d.Get("template_name").(string) anpName := d.Get("anp_name").(string) epgName := d.Get("epg_name").(string) - + importReadSchemaID = schemaID + importReadSiteID = siteID + importReadTemplate = template + importReadANP = anpName + importReadEPG = epgName cont, err := msoClient.GetViaURL(fmt.Sprintf("api/v1/schemas/%s", schemaID)) if err != nil { return err @@ -429,7 +443,6 @@ func resourceSchemaSiteApnEpgSelectorRead(d *schema.ResourceData, m interface{}) currentName := models.StripQuotes(selectorCont.S("name").String()) if currentName == dn { found = true - d.SetId(dn) d.Set("name", currentName) exps := selectorCont.S("expressions").Data().([]interface{}) diff --git a/mso/resource_mso_schema_site_anp_epg_selector_test.go b/mso/resource_mso_schema_site_anp_epg_selector_test.go index 9c126433..4a10dbfd 100644 --- a/mso/resource_mso_schema_site_anp_epg_selector_test.go +++ b/mso/resource_mso_schema_site_anp_epg_selector_test.go @@ -11,16 +11,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -// func TestAccMSOSchemaSiteAnpEpgSelector_Initial(t *testing.T) { -// resource.Test(t, resource.TestCase{ -// Providers: testAccProviders, -// Steps: []resource.TestStep{ -// { -// Config: testAccCheckMSOSiteAnpEpgSelectorConfig_initial("ANP"), -// }, -// }, -// }) -// } func TestAccMSOSchemaSiteAnpEpgSelector_Basic(t *testing.T) { var ss SiteAnpEpgSelectorTest resource.Test(t, resource.TestCase{ @@ -29,10 +19,10 @@ func TestAccMSOSchemaSiteAnpEpgSelector_Basic(t *testing.T) { CheckDestroy: testAccCheckMSOSchemaSiteAnpEpgSelectorDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckMSOSiteAnpEpgSelectorConfig_basic("one"), + Config: testAccCheckMSOSiteAnpEpgSelectorConfig_basic("in"), Check: resource.ComposeTestCheckFunc( testAccCheckMSOSchemaSiteAnpEpgSelectorExists("mso_schema.schema1", "mso_schema_site_anp_epg_selector.selector1", &ss), - testAccCheckMSOSchemaSiteAnpEpgSelectorAttributes("one", &ss), + testAccCheckMSOSchemaSiteAnpEpgSelectorAttributes("in", &ss), ), }, @@ -54,108 +44,114 @@ func TestAccMSOSchemaSiteAnpEpgSelector_Update(t *testing.T) { CheckDestroy: testAccCheckMSOSchemaSiteAnpEpgSelectorDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckMSOSiteAnpEpgSelectorConfig_basic("one"), + Config: testAccCheckMSOSiteAnpEpgSelectorConfig_basic("in"), Check: resource.ComposeTestCheckFunc( testAccCheckMSOSchemaSiteAnpEpgSelectorExists("mso_schema.schema1", "mso_schema_site_anp_epg_selector.selector1", &ss), - testAccCheckMSOSchemaSiteAnpEpgSelectorAttributes("one", &ss), + testAccCheckMSOSchemaSiteAnpEpgSelectorAttributes("in", &ss), ), }, { - Config: testAccCheckMSOSiteAnpEpgSelectorConfig_basic("two"), + Config: testAccCheckMSOSiteAnpEpgSelectorConfig_basic("equals"), Check: resource.ComposeTestCheckFunc( testAccCheckMSOSchemaSiteAnpEpgSelectorExists("mso_schema.schema1", "mso_schema_site_anp_epg_selector.selector1", &ss), - testAccCheckMSOSchemaSiteAnpEpgSelectorAttributes("two", &ss), + testAccCheckMSOSchemaSiteAnpEpgSelectorAttributes("equals", &ss), ), }, }, }) } -func testAccCheckMSOSiteAnpEpgSelectorConfig_basic(key string) string { +func testAccCheckMSOSiteAnpEpgSelectorConfig_basic(operator string) string { return fmt.Sprintf(` resource "mso_schema" "schema1" { name = "Schema2" template_name = "Template1" tenant_id = "5fb5fed8520000452a9e8911" - - } - - resource "mso_schema_template_vrf" "vrf1" { - schema_id = mso_schema.schema1.id - template = mso_schema.schema1.template_name - name = "VRF" - display_name = "vz1" - layer3_multicast= false - vzany = false - } - - resource "mso_rest" "azure_site" { - path = "api/v1/schemas/${mso_schema.schema1.id}" - method = "PATCH" + } - payload = <