How to use patch method of main Package

Best Rod code snippet using main.patch

resource_aws_ssm_patch_baseline_test.go

Source:resource_aws_ssm_patch_baseline_test.go Github

copy

Full Screen

...11)12func TestAccAWSSSMPatchBaseline_basic(t *testing.T) {13 var before, after ssm.PatchBaselineIdentity14 name := acctest.RandString(10)15 resourceName := "aws_ssm_patch_baseline.test"16 resource.ParallelTest(t, resource.TestCase{17 PreCheck: func() { testAccPreCheck(t) },18 ErrorCheck: testAccErrorCheck(t, ssm.EndpointsID),19 Providers: testAccProviders,20 CheckDestroy: testAccCheckAWSSSMPatchBaselineDestroy,21 Steps: []resource.TestStep{22 {23 Config: testAccAWSSSMPatchBaselineBasicConfig(name),24 Check: resource.ComposeTestCheckFunc(25 testAccCheckAWSSSMPatchBaselineExists(resourceName, &before),26 testAccMatchResourceAttrRegionalARN(resourceName, "arn", "ssm", regexp.MustCompile(`patchbaseline/pb-.+`)),27 resource.TestCheckResourceAttr(resourceName, "approved_patches.#", "1"),28 resource.TestCheckTypeSetElemAttr(resourceName, "approved_patches.*", "KB123456"),29 resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("patch-baseline-%s", name)),30 resource.TestCheckResourceAttr(resourceName, "approved_patches_compliance_level", ssm.PatchComplianceLevelCritical),31 resource.TestCheckResourceAttr(resourceName, "description", "Baseline containing all updates approved for production systems"),32 resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),33 resource.TestCheckResourceAttr(resourceName, "approved_patches_enable_non_security", "false"),34 ),35 },36 {37 ResourceName: resourceName,38 ImportState: true,39 ImportStateVerify: true,40 },41 {42 Config: testAccAWSSSMPatchBaselineBasicConfigUpdated(name),43 Check: resource.ComposeTestCheckFunc(44 testAccCheckAWSSSMPatchBaselineExists(resourceName, &after),45 testAccMatchResourceAttrRegionalARN(resourceName, "arn", "ssm", regexp.MustCompile(`patchbaseline/pb-.+`)),46 resource.TestCheckResourceAttr(resourceName, "approved_patches.#", "2"),47 resource.TestCheckTypeSetElemAttr(resourceName, "approved_patches.*", "KB123456"),48 resource.TestCheckTypeSetElemAttr(resourceName, "approved_patches.*", "KB456789"),49 resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("updated-patch-baseline-%s", name)),50 resource.TestCheckResourceAttr(resourceName, "approved_patches_compliance_level", ssm.PatchComplianceLevelHigh),51 resource.TestCheckResourceAttr(resourceName, "description", "Baseline containing all updates approved for production systems - August 2017"),52 resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),53 func(*terraform.State) error {54 if aws.StringValue(before.BaselineId) != aws.StringValue(after.BaselineId) {55 t.Fatal("Baseline IDs changed unexpectedly")56 }57 return nil58 },59 ),60 },61 },62 })63}64func TestAccAWSSSMPatchBaseline_tags(t *testing.T) {65 var patch ssm.PatchBaselineIdentity66 name := acctest.RandString(10)67 resourceName := "aws_ssm_patch_baseline.test"68 resource.ParallelTest(t, resource.TestCase{69 PreCheck: func() { testAccPreCheck(t) },70 ErrorCheck: testAccErrorCheck(t, ssm.EndpointsID),71 Providers: testAccProviders,72 CheckDestroy: testAccCheckAWSSSMPatchBaselineDestroy,73 Steps: []resource.TestStep{74 {75 Config: testAccAWSSSMPatchBaselineBasicConfigTags1(name, "key1", "value1"),76 Check: resource.ComposeTestCheckFunc(77 testAccCheckAWSSSMPatchBaselineExists(resourceName, &patch),78 resource.TestCheckResourceAttr(resourceName, "tags.%", "1"),79 resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"),80 ),81 },82 {83 ResourceName: resourceName,84 ImportState: true,85 ImportStateVerify: true,86 },87 {88 Config: testAccAWSSSMPatchBaselineBasicConfigTags2(name, "key1", "value1updated", "key2", "value2"),89 Check: resource.ComposeTestCheckFunc(90 testAccCheckAWSSSMPatchBaselineExists(resourceName, &patch),91 resource.TestCheckResourceAttr(resourceName, "tags.%", "2"),92 resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1updated"),93 resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"),94 ),95 },96 {97 Config: testAccAWSSSMPatchBaselineBasicConfigTags1(name, "key2", "value2"),98 Check: resource.ComposeTestCheckFunc(99 testAccCheckAWSSSMPatchBaselineExists(resourceName, &patch),100 resource.TestCheckResourceAttr(resourceName, "tags.%", "1"),101 resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"),102 ),103 },104 },105 })106}107func TestAccAWSSSMPatchBaseline_disappears(t *testing.T) {108 var identity ssm.PatchBaselineIdentity109 name := acctest.RandString(10)110 resourceName := "aws_ssm_patch_baseline.test"111 resource.ParallelTest(t, resource.TestCase{112 PreCheck: func() { testAccPreCheck(t) },113 ErrorCheck: testAccErrorCheck(t, ssm.EndpointsID),114 Providers: testAccProviders,115 CheckDestroy: testAccCheckAWSSSMPatchBaselineDestroy,116 Steps: []resource.TestStep{117 {118 Config: testAccAWSSSMPatchBaselineBasicConfig(name),119 Check: resource.ComposeTestCheckFunc(120 testAccCheckAWSSSMPatchBaselineExists(resourceName, &identity),121 testAccCheckResourceDisappears(testAccProvider, resourceAwsSsmPatchBaseline(), resourceName),122 ),123 ExpectNonEmptyPlan: true,124 },125 },126 })127}128func TestAccAWSSSMPatchBaseline_OperatingSystem(t *testing.T) {129 var before, after ssm.PatchBaselineIdentity130 name := acctest.RandString(10)131 resourceName := "aws_ssm_patch_baseline.test"132 resource.ParallelTest(t, resource.TestCase{133 PreCheck: func() { testAccPreCheck(t) },134 ErrorCheck: testAccErrorCheck(t, ssm.EndpointsID),135 Providers: testAccProviders,136 CheckDestroy: testAccCheckAWSSSMPatchBaselineDestroy,137 Steps: []resource.TestStep{138 {139 Config: testAccAWSSSMPatchBaselineConfigWithOperatingSystem(name),140 Check: resource.ComposeTestCheckFunc(141 testAccCheckAWSSSMPatchBaselineExists(resourceName, &before),142 resource.TestCheckResourceAttr(resourceName, "approval_rule.#", "1"),143 resource.TestCheckResourceAttr(resourceName, "approval_rule.0.approve_after_days", "7"),144 resource.TestCheckResourceAttr(resourceName, "approval_rule.0.patch_filter.#", "2"),145 resource.TestCheckResourceAttr(resourceName, "approval_rule.0.compliance_level", ssm.PatchComplianceLevelCritical),146 resource.TestCheckResourceAttr(resourceName, "approval_rule.0.enable_non_security", "true"),147 resource.TestCheckResourceAttr(resourceName, "operating_system", "AMAZON_LINUX"),148 ),149 },150 {151 ResourceName: resourceName,152 ImportState: true,153 ImportStateVerify: true,154 },155 {156 Config: testAccAWSSSMPatchBaselineConfigWithOperatingSystemUpdated(name),157 Check: resource.ComposeTestCheckFunc(158 testAccCheckAWSSSMPatchBaselineExists(resourceName, &after),159 resource.TestCheckResourceAttr(resourceName, "approval_rule.#", "1"),160 resource.TestCheckResourceAttr(resourceName, "approval_rule.0.approve_after_days", "7"),161 resource.TestCheckResourceAttr(resourceName, "approval_rule.0.patch_filter.#", "2"),162 resource.TestCheckResourceAttr(resourceName, "approval_rule.0.compliance_level", ssm.PatchComplianceLevelInformational),163 resource.TestCheckResourceAttr(resourceName, "operating_system", ssm.OperatingSystemWindows),164 testAccCheckAwsSsmPatchBaselineRecreated(t, &before, &after),165 ),166 },167 },168 })169}170func TestAccAWSSSMPatchBaseline_ApproveUntilDateParam(t *testing.T) {171 var before, after ssm.PatchBaselineIdentity172 name := acctest.RandString(10)173 resourceName := "aws_ssm_patch_baseline.test"174 resource.ParallelTest(t, resource.TestCase{175 PreCheck: func() { testAccPreCheck(t) },176 ErrorCheck: testAccErrorCheck(t, ssm.EndpointsID),177 Providers: testAccProviders,178 CheckDestroy: testAccCheckAWSSSMPatchBaselineDestroy,179 Steps: []resource.TestStep{180 {181 Config: testAccAWSSSMPatchBaselineConfigWithApproveUntilDate(name),182 Check: resource.ComposeTestCheckFunc(183 testAccCheckAWSSSMPatchBaselineExists(resourceName, &before),184 resource.TestCheckResourceAttr(resourceName, "approval_rule.#", "1"),185 resource.TestCheckResourceAttr(resourceName, "approval_rule.0.approve_until_date", "2020-01-01"),186 resource.TestCheckResourceAttr(resourceName, "approval_rule.0.patch_filter.#", "2"),187 resource.TestCheckResourceAttr(resourceName, "approval_rule.0.compliance_level", ssm.PatchComplianceLevelCritical),188 resource.TestCheckResourceAttr(resourceName, "approval_rule.0.enable_non_security", "true"),189 resource.TestCheckResourceAttr(resourceName, "operating_system", "AMAZON_LINUX"),190 ),191 },192 {193 ResourceName: resourceName,194 ImportState: true,195 ImportStateVerify: true,196 },197 {198 Config: testAccAWSSSMPatchBaselineConfigWithApproveUntilDateUpdated(name),199 Check: resource.ComposeTestCheckFunc(200 testAccCheckAWSSSMPatchBaselineExists(resourceName, &after),201 resource.TestCheckResourceAttr(resourceName, "approval_rule.#", "1"),202 resource.TestCheckResourceAttr(resourceName, "approval_rule.0.approve_until_date", "2020-02-02"),203 resource.TestCheckResourceAttr(resourceName, "approval_rule.0.patch_filter.#", "2"),204 resource.TestCheckResourceAttr(resourceName, "approval_rule.0.compliance_level", ssm.PatchComplianceLevelCritical),205 resource.TestCheckResourceAttr(resourceName, "operating_system", "AMAZON_LINUX"),206 func(*terraform.State) error {207 if aws.StringValue(before.BaselineId) != aws.StringValue(after.BaselineId) {208 t.Fatal("Baseline IDs changed unexpectedly")209 }210 return nil211 },212 ),213 },214 },215 })216}217func TestAccAWSSSMPatchBaseline_Sources(t *testing.T) {218 var before, after ssm.PatchBaselineIdentity219 name := acctest.RandString(10)220 resourceName := "aws_ssm_patch_baseline.test"221 resource.ParallelTest(t, resource.TestCase{222 PreCheck: func() { testAccPreCheck(t) },223 ErrorCheck: testAccErrorCheck(t, ssm.EndpointsID),224 Providers: testAccProviders,225 CheckDestroy: testAccCheckAWSSSMPatchBaselineDestroy,226 Steps: []resource.TestStep{227 {228 Config: testAccAWSSSMPatchBaselineConfigWithSource(name),229 Check: resource.ComposeTestCheckFunc(230 testAccCheckAWSSSMPatchBaselineExists(resourceName, &before),231 resource.TestCheckResourceAttr(resourceName, "source.#", "1"),232 resource.TestCheckResourceAttr(resourceName, "source.0.name", "My-AL2017.09"),233 resource.TestCheckResourceAttr(resourceName, "source.0.configuration", "[amzn-main] \nname=amzn-main-Base\nmirrorlist=http://repo./$awsregion./$awsdomain//$releasever/main/mirror.list //nmirrorlist_expire=300//nmetadata_expire=300 \npriority=10 \nfailovermethod=priority \nfastestmirror_enabled=0 \ngpgcheck=1 \ngpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-amazon-ga \nenabled=1 \nretries=3 \ntimeout=5\nreport_instanceid=yes"),234 resource.TestCheckResourceAttr(resourceName, "source.0.products.#", "1"),235 resource.TestCheckResourceAttr(resourceName, "source.0.products.0", "AmazonLinux2017.09"),236 ),237 },238 {239 ResourceName: resourceName,240 ImportState: true,241 ImportStateVerify: true,242 },243 {244 Config: testAccAWSSSMPatchBaselineConfigWithSourceUpdated(name),245 Check: resource.ComposeTestCheckFunc(246 testAccCheckAWSSSMPatchBaselineExists(resourceName, &after),247 resource.TestCheckResourceAttr(resourceName, "source.#", "2"),248 resource.TestCheckResourceAttr(resourceName, "source.0.name", "My-AL2017.09"),249 resource.TestCheckResourceAttr(resourceName, "source.0.configuration", "[amzn-main] \nname=amzn-main-Base\nmirrorlist=http://repo./$awsregion./$awsdomain//$releasever/main/mirror.list //nmirrorlist_expire=300//nmetadata_expire=300 \npriority=10 \nfailovermethod=priority \nfastestmirror_enabled=0 \ngpgcheck=1 \ngpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-amazon-ga \nenabled=1 \nretries=3 \ntimeout=5\nreport_instanceid=yes"),250 resource.TestCheckResourceAttr(resourceName, "source.0.products.#", "1"),251 resource.TestCheckResourceAttr(resourceName, "source.0.products.0", "AmazonLinux2017.09"),252 resource.TestCheckResourceAttr(resourceName, "source.1.name", "My-AL2018.03"),253 resource.TestCheckResourceAttr(resourceName, "source.1.configuration", "[amzn-main] \nname=amzn-main-Base\nmirrorlist=http://repo./$awsregion./$awsdomain//$releasever/main/mirror.list //nmirrorlist_expire=300//nmetadata_expire=300 \npriority=10 \nfailovermethod=priority \nfastestmirror_enabled=0 \ngpgcheck=1 \ngpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-amazon-ga \nenabled=1 \nretries=3 \ntimeout=5\nreport_instanceid=yes"),254 resource.TestCheckResourceAttr(resourceName, "source.1.products.#", "1"),255 resource.TestCheckResourceAttr(resourceName, "source.1.products.0", "AmazonLinux2018.03"),256 func(*terraform.State) error {257 if aws.StringValue(before.BaselineId) != aws.StringValue(after.BaselineId) {258 t.Fatal("Baseline IDs changed unexpectedly")259 }260 return nil261 },262 ),263 },264 },265 })266}267func TestAccAWSSSMPatchBaseline_ApprovedPatchesNonSec(t *testing.T) {268 var ssmPatch ssm.PatchBaselineIdentity269 name := acctest.RandString(10)270 resourceName := "aws_ssm_patch_baseline.test"271 resource.ParallelTest(t, resource.TestCase{272 PreCheck: func() { testAccPreCheck(t) },273 ErrorCheck: testAccErrorCheck(t, ssm.EndpointsID),274 Providers: testAccProviders,275 CheckDestroy: testAccCheckAWSSSMPatchBaselineDestroy,276 Steps: []resource.TestStep{277 {278 Config: testAccAWSSSMPatchBaselineBasicConfigApprovedPatchesNonSec(name),279 Check: resource.ComposeTestCheckFunc(280 testAccCheckAWSSSMPatchBaselineExists(resourceName, &ssmPatch),281 resource.TestCheckResourceAttr(resourceName, "approved_patches_enable_non_security", "true"),282 ),283 },284 {285 ResourceName: resourceName,286 ImportState: true,287 ImportStateVerify: true,288 },289 },290 })291}292func TestAccAWSSSMPatchBaseline_RejectPatchesAction(t *testing.T) {293 var ssmPatch ssm.PatchBaselineIdentity294 name := acctest.RandString(10)295 resourceName := "aws_ssm_patch_baseline.test"296 resource.ParallelTest(t, resource.TestCase{297 PreCheck: func() { testAccPreCheck(t) },298 ErrorCheck: testAccErrorCheck(t, ssm.EndpointsID),299 Providers: testAccProviders,300 CheckDestroy: testAccCheckAWSSSMPatchBaselineDestroy,301 Steps: []resource.TestStep{302 {303 Config: testAccAWSSSMPatchBaselineBasicConfigRejectPatchesAction(name),304 Check: resource.ComposeTestCheckFunc(305 testAccCheckAWSSSMPatchBaselineExists(resourceName, &ssmPatch),306 resource.TestCheckResourceAttr(resourceName, "rejected_patches_action", "ALLOW_AS_DEPENDENCY"),307 ),308 },309 {310 ResourceName: resourceName,311 ImportState: true,312 ImportStateVerify: true,313 },314 },315 })316}317func testAccCheckAwsSsmPatchBaselineRecreated(t *testing.T,318 before, after *ssm.PatchBaselineIdentity) resource.TestCheckFunc {319 return func(s *terraform.State) error {320 if *before.BaselineId == *after.BaselineId {321 t.Fatalf("Expected change of SSM Patch Baseline IDs, but both were %v", *before.BaselineId)322 }323 return nil324 }325}326func testAccCheckAWSSSMPatchBaselineExists(n string, patch *ssm.PatchBaselineIdentity) resource.TestCheckFunc {327 return func(s *terraform.State) error {328 rs, ok := s.RootModule().Resources[n]329 if !ok {330 return fmt.Errorf("Not found: %s", n)331 }332 if rs.Primary.ID == "" {333 return fmt.Errorf("No SSM Patch Baseline ID is set")334 }335 conn := testAccProvider.Meta().(*AWSClient).ssmconn336 resp, err := conn.DescribePatchBaselines(&ssm.DescribePatchBaselinesInput{337 Filters: []*ssm.PatchOrchestratorFilter{338 {339 Key: aws.String("NAME_PREFIX"),340 Values: []*string{aws.String(rs.Primary.Attributes["name"])},341 },342 },343 })344 for _, i := range resp.BaselineIdentities {345 if *i.BaselineId == rs.Primary.ID {346 *patch = *i347 return nil348 }349 }350 if err != nil {351 return err352 }353 return fmt.Errorf("No AWS SSM Patch Baseline found")354 }355}356func testAccCheckAWSSSMPatchBaselineDestroy(s *terraform.State) error {357 conn := testAccProvider.Meta().(*AWSClient).ssmconn358 for _, rs := range s.RootModule().Resources {359 if rs.Type != "aws_ssm_patch_baseline" {360 continue361 }362 out, err := conn.DescribePatchBaselines(&ssm.DescribePatchBaselinesInput{363 Filters: []*ssm.PatchOrchestratorFilter{364 {365 Key: aws.String("NAME_PREFIX"),366 Values: []*string{aws.String(rs.Primary.Attributes["name"])},367 },368 },369 })370 if err != nil {371 return err372 }373 if len(out.BaselineIdentities) > 0 {374 return fmt.Errorf("Expected AWS SSM Patch Baseline to be gone, but was still found")375 }376 return nil377 }378 return nil379}380func testAccAWSSSMPatchBaselineBasicConfig(rName string) string {381 return fmt.Sprintf(`382resource "aws_ssm_patch_baseline" "test" {383 name = "patch-baseline-%s"384 description = "Baseline containing all updates approved for production systems"385 approved_patches = ["KB123456"]386 approved_patches_compliance_level = "CRITICAL"387}388`, rName)389}390func testAccAWSSSMPatchBaselineBasicConfigTags1(rName, tagKey1, tagValue1 string) string {391 return fmt.Sprintf(`392resource "aws_ssm_patch_baseline" "test" {393 name = %[1]q394 description = "Baseline containing all updates approved for production systems"395 approved_patches = ["KB123456"]396 approved_patches_compliance_level = "CRITICAL"397 tags = {398 %[2]q = %[3]q399 }400}401`, rName, tagKey1, tagValue1)402}403func testAccAWSSSMPatchBaselineBasicConfigTags2(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string {404 return fmt.Sprintf(`405resource "aws_ssm_patch_baseline" "test" {406 name = %[1]q407 description = "Baseline containing all updates approved for production systems"408 approved_patches = ["KB123456"]409 approved_patches_compliance_level = "CRITICAL"410 tags = {411 %[2]q = %[3]q412 %[4]q = %[5]q413 }414}415`, rName, tagKey1, tagValue1, tagKey2, tagValue2)416}417func testAccAWSSSMPatchBaselineBasicConfigUpdated(rName string) string {418 return fmt.Sprintf(`419resource "aws_ssm_patch_baseline" "test" {420 name = "updated-patch-baseline-%s"421 description = "Baseline containing all updates approved for production systems - August 2017"422 approved_patches = ["KB123456", "KB456789"]423 approved_patches_compliance_level = "HIGH"424}425`, rName)426}427func testAccAWSSSMPatchBaselineConfigWithOperatingSystem(rName string) string {428 return fmt.Sprintf(`429resource "aws_ssm_patch_baseline" "test" {430 name = "patch-baseline-%s"431 operating_system = "AMAZON_LINUX"432 description = "Baseline containing all updates approved for production systems"433 tags = {434 Name = "My Patch Baseline"435 }436 approval_rule {437 approve_after_days = 7438 enable_non_security = true439 compliance_level = "CRITICAL"440 patch_filter {441 key = "PRODUCT"442 values = ["AmazonLinux2016.03", "AmazonLinux2016.09", "AmazonLinux2017.03", "AmazonLinux2017.09"]443 }444 patch_filter {445 key = "SEVERITY"446 values = ["Critical", "Important"]447 }448 }449}450`, rName)451}452func testAccAWSSSMPatchBaselineConfigWithOperatingSystemUpdated(rName string) string {453 return fmt.Sprintf(`454resource "aws_ssm_patch_baseline" "test" {455 name = "patch-baseline-%s"456 operating_system = "WINDOWS"457 description = "Baseline containing all updates approved for production systems"458 tags = {459 Name = "My Patch Baseline"460 }461 approval_rule {462 approve_after_days = 7463 compliance_level = "INFORMATIONAL"464 patch_filter {465 key = "PRODUCT"466 values = ["WindowsServer2012R2"]467 }468 patch_filter {469 key = "MSRC_SEVERITY"470 values = ["Critical", "Important"]471 }472 }473}474`, rName)475}476func testAccAWSSSMPatchBaselineConfigWithApproveUntilDate(rName string) string {477 return fmt.Sprintf(`478resource "aws_ssm_patch_baseline" "test" {479 name = %[1]q480 operating_system = "AMAZON_LINUX"481 description = "Baseline containing all updates approved for production systems"482 tags = {483 Name = "My Patch Baseline"484 }485 approval_rule {486 approve_until_date = "2020-01-01"487 enable_non_security = true488 compliance_level = "CRITICAL"489 patch_filter {490 key = "PRODUCT"491 values = ["AmazonLinux2016.03", "AmazonLinux2016.09", "AmazonLinux2017.03", "AmazonLinux2017.09"]492 }493 patch_filter {494 key = "SEVERITY"495 values = ["Critical", "Important"]496 }497 }498}499`, rName)500}501func testAccAWSSSMPatchBaselineConfigWithApproveUntilDateUpdated(rName string) string {502 return fmt.Sprintf(`503resource "aws_ssm_patch_baseline" "test" {504 name = %[1]q505 operating_system = "AMAZON_LINUX"506 description = "Baseline containing all updates approved for production systems"507 tags = {508 Name = "My Patch Baseline"509 }510 approval_rule {511 approve_until_date = "2020-02-02"512 enable_non_security = true513 compliance_level = "CRITICAL"514 patch_filter {515 key = "PRODUCT"516 values = ["AmazonLinux2016.03", "AmazonLinux2016.09", "AmazonLinux2017.03", "AmazonLinux2017.09"]517 }518 patch_filter {519 key = "SEVERITY"520 values = ["Critical", "Important"]521 }522 }523}524`, rName)525}526func testAccAWSSSMPatchBaselineConfigWithSource(rName string) string {527 return fmt.Sprintf(`528resource "aws_ssm_patch_baseline" "test" {529 name = %[1]q530 description = "Baseline containing all updates approved for production systems"531 approved_patches_compliance_level = "CRITICAL"532 approved_patches = ["test123"]533 operating_system = "AMAZON_LINUX"534 source {535 name = "My-AL2017.09"536 configuration = "[amzn-main] \nname=amzn-main-Base\nmirrorlist=http://repo./$awsregion./$awsdomain//$releasever/main/mirror.list //nmirrorlist_expire=300//nmetadata_expire=300 \npriority=10 \nfailovermethod=priority \nfastestmirror_enabled=0 \ngpgcheck=1 \ngpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-amazon-ga \nenabled=1 \nretries=3 \ntimeout=5\nreport_instanceid=yes"537 products = ["AmazonLinux2017.09"]538 }539}540`, rName)541}542func testAccAWSSSMPatchBaselineConfigWithSourceUpdated(rName string) string {543 return fmt.Sprintf(`544resource "aws_ssm_patch_baseline" "test" {545 name = %[1]q546 description = "Baseline containing all updates approved for production systems"547 approved_patches_compliance_level = "CRITICAL"548 approved_patches = ["test123"]549 operating_system = "AMAZON_LINUX"550 source {551 name = "My-AL2017.09"552 configuration = "[amzn-main] \nname=amzn-main-Base\nmirrorlist=http://repo./$awsregion./$awsdomain//$releasever/main/mirror.list //nmirrorlist_expire=300//nmetadata_expire=300 \npriority=10 \nfailovermethod=priority \nfastestmirror_enabled=0 \ngpgcheck=1 \ngpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-amazon-ga \nenabled=1 \nretries=3 \ntimeout=5\nreport_instanceid=yes"553 products = ["AmazonLinux2017.09"]554 }555 source {556 name = "My-AL2018.03"557 configuration = "[amzn-main] \nname=amzn-main-Base\nmirrorlist=http://repo./$awsregion./$awsdomain//$releasever/main/mirror.list //nmirrorlist_expire=300//nmetadata_expire=300 \npriority=10 \nfailovermethod=priority \nfastestmirror_enabled=0 \ngpgcheck=1 \ngpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-amazon-ga \nenabled=1 \nretries=3 \ntimeout=5\nreport_instanceid=yes"558 products = ["AmazonLinux2018.03"]559 }560}561`, rName)562}563func testAccAWSSSMPatchBaselineBasicConfigApprovedPatchesNonSec(rName string) string {564 return fmt.Sprintf(`565resource "aws_ssm_patch_baseline" "test" {566 name = %q567 operating_system = "AMAZON_LINUX"568 description = "Baseline containing all updates approved for production systems"569 approved_patches = ["KB123456"]570 approved_patches_compliance_level = "CRITICAL"571 approved_patches_enable_non_security = true572}573`, rName)574}575func testAccAWSSSMPatchBaselineBasicConfigRejectPatchesAction(rName string) string {576 return fmt.Sprintf(`577resource "aws_ssm_patch_baseline" "test" {578 name = "patch-baseline-%s"579 description = "Baseline containing all updates approved for production systems"580 approved_patches = ["KB123456"]581 approved_patches_compliance_level = "CRITICAL"582 rejected_patches_action = "ALLOW_AS_DEPENDENCY"583}584`, rName)585}...

Full Screen

Full Screen

package_test.go

Source:package_test.go Github

copy

Full Screen

...35 pkg, err := NewGoPackage(pkgDir)36 if err != nil {37 t.Fatal(err)38 }39 patchTargets := []string{40 pkgName + "/main",41 pkgName + "/DoStuff",42 pkgName + "/A.DoStuff",43 }44 targetList, err := pkg.Find(patchTargets...)45 if err != nil {46 t.Fatal(err)47 }48 if len(targetList) != len(patchTargets) {49 t.Fatalf("expected to get back %d targets; got %d", len(patchTargets), len(targetList))50 }51}52func TestFindMissingTarget(t *testing.T) {53 wsDir, pkgDir, pkgName := mockPackage(t)54 defer os.RemoveAll(wsDir)55 pkg, err := NewGoPackage(pkgDir)56 if err != nil {57 t.Fatal(err)58 }59 invalidTarget := pkgName + "/missing.target"60 expError := fmt.Sprintf("GoPackage.Find: no match for profile target %q", invalidTarget)61 _, err = pkg.Find(invalidTarget)62 if err == nil || err.Error() != expError {63 t.Fatalf("expected to get error %q; got: %v", expError, err)64 }65}66func TestPatchPackageExcludingDeps(t *testing.T) {67 wsDir, pkgDir, pkgName := mockPackage(t)68 defer os.RemoveAll(wsDir)69 pkg, err := NewGoPackage(pkgDir)70 if err != nil {71 t.Fatal(err)72 }73 targetList, err := pkg.Find(pkgName + "/main")74 if err != nil {75 t.Fatal(err)76 }77 if len(targetList) != 1 {78 t.Fatal("error looking up patch target for main()")79 }80 vendorPkgRegex := []string{}81 dummyPatchCmd := PatchCmd{82 Targets: targetList,83 PatchFn: func(_ *CallGraphNode, _ *ast.BlockStmt) (modifiedAST bool, extraImports []string) {84 return true, nil85 },86 }87 updatedFiles, patchCount, err := pkg.Patch(vendorPkgRegex, dummyPatchCmd)88 if err != nil {89 t.Fatal(err)90 }91 expUpdatedFiles := 192 if updatedFiles != expUpdatedFiles {93 t.Fatalf("expected Patch() to update %d files; got %d", expUpdatedFiles, updatedFiles)94 }95 // pkg.Patch will modify main and the 2 call targets in its callgraph96 expPatchCount := 397 if patchCount != expPatchCount {98 t.Fatalf("expected Patch() to apply %d patches; got %d", expPatchCount, patchCount)99 }100}101func TestPatchPackageIncludingGodeps(t *testing.T) {102 wsDir, pkgDir, pkgName := mockPackageWithVendoredDeps(t, true)103 defer os.RemoveAll(wsDir)104 pkg, err := NewGoPackage(pkgDir)105 if err != nil {106 t.Fatal(err)107 }108 targetList, err := pkg.Find(pkgName + "/main")109 if err != nil {110 t.Fatal(err)111 }112 if len(targetList) != 1 {113 t.Fatal("error looking up patch target for main()")114 }115 vendorPkgRegex := []string{"other/pkg"}116 dummyPatchCmd := PatchCmd{117 Targets: targetList,118 PatchFn: func(_ *CallGraphNode, _ *ast.BlockStmt) (modifiedAST bool, extraImports []string) {119 return true, nil120 },121 }122 updatedFiles, patchCount, err := pkg.Patch(vendorPkgRegex, dummyPatchCmd)123 if err != nil {124 t.Fatal(err)125 }126 expUpdatedFiles := 2127 if updatedFiles != expUpdatedFiles {128 t.Fatalf("expected Patch() to update %d files; got %d", expUpdatedFiles, updatedFiles)129 }130 // pkg.Patch will modify main and the 2 call targets in its callgraph + 1 function in the vendored package131 expPatchCount := 4132 if patchCount != expPatchCount {133 t.Fatalf("expected Patch() to apply %d patches; got %d", expPatchCount, patchCount)134 }135}136func TestPatchPackageIncludingVendorDeps(t *testing.T) {137 wsDir, pkgDir, pkgName := mockPackageWithVendoredDeps(t, false)138 defer os.RemoveAll(wsDir)139 pkg, err := NewGoPackage(pkgDir)140 if err != nil {141 t.Fatal(err)142 }143 targetList, err := pkg.Find(pkgName + "/main")144 if err != nil {145 t.Fatal(err)146 }147 if len(targetList) != 1 {148 t.Fatal("error looking up patch target for main()")149 }150 vendorPkgRegex := []string{"other/pkg"}151 dummyPatchCmd := PatchCmd{152 Targets: targetList,153 PatchFn: func(_ *CallGraphNode, _ *ast.BlockStmt) (modifiedAST bool, extraImports []string) {154 return true, nil155 },156 }157 updatedFiles, patchCount, err := pkg.Patch(vendorPkgRegex, dummyPatchCmd)158 if err != nil {159 t.Fatal(err)160 }161 expUpdatedFiles := 2162 if updatedFiles != expUpdatedFiles {163 t.Fatalf("expected Patch() to update %d files; got %d", expUpdatedFiles, updatedFiles)164 }165 // pkg.Patch will modify main and the 2 call targets in its callgraph + 1 function in the vendored package166 expPatchCount := 4167 if patchCount != expPatchCount {168 t.Fatalf("expected Patch() to apply %d patches; got %d", expPatchCount, patchCount)169 }170}171func TestPatchPackageWithInvalidVendorRegex(t *testing.T) {172 wsDir, pkgDir, pkgName := mockPackageWithVendoredDeps(t, true)173 defer os.RemoveAll(wsDir)174 pkg, err := NewGoPackage(pkgDir)175 if err != nil {176 t.Fatal(err)177 }178 targetList, err := pkg.Find(pkgName + "/main")179 if err != nil {180 t.Fatal(err)181 }182 if len(targetList) != 1 {183 t.Fatal("error looking up patch target for main()")184 }185 vendorPkgRegex := []string{"other/pkg *****"}186 dummyPatchCmd := PatchCmd{187 Targets: targetList,188 PatchFn: func(_ *CallGraphNode, _ *ast.BlockStmt) (modifiedAST bool, extraImports []string) {189 return true, nil190 },191 }192 _, _, err = pkg.Patch(vendorPkgRegex, dummyPatchCmd)193 if err == nil || !strings.Contains(err.Error(), "could not compile regex") {194 t.Fatalf("expected to get a regex compilation error; got %v", err)195 }196}...

Full Screen

Full Screen

main_test.go

Source:main_test.go Github

copy

Full Screen

...9 "errors"10 "github.com/intel/edge-conductor/cmd/ep/app"11 "github.com/intel/edge-conductor/pkg/eputils"12 "testing"13 "github.com/undefinedlabs/go-mpatch"14)15var (16 errHash = errors.New("checkhash.error")17)18func patcheputilscheckhash(t *testing.T, ok bool) {19 var patch *mpatch.Patch20 var patchErr error21 patch, patchErr = mpatch.PatchMethod(eputils.CheckHash, func(workspace string) error {22 unpatch(t, patch)23 if ok {24 return nil25 } else {26 return errHash27 }28 })29 if patchErr != nil {30 t.Errorf("patch error: %v", patchErr)31 }32}33func patchappexecute(t *testing.T) *mpatch.Patch {34 var patch *mpatch.Patch35 var patchErr error36 patch, patchErr = mpatch.PatchMethod(app.Execute, func() {})37 if patchErr != nil {38 t.Errorf("patch error: %v", patchErr)39 }40 return patch41}42func unpatch(t *testing.T, m *mpatch.Patch) {43 err := m.Unpatch()44 if err != nil {45 t.Fatal(err)46 }47}48func Test_main(t *testing.T) {49 var handler *mpatch.Patch50 var cases = []struct {51 name string52 expectError error53 beforetest func()54 teardown func()55 }{56 {57 name: "Hash is valid in main function",58 expectError: nil,59 beforetest: func() {60 patcheputilscheckhash(t, true)61 handler = patchappexecute(t)62 },63 teardown: func() {64 unpatch(t, handler)65 },66 },67 {68 name: "Hash is not valid in main function",69 expectError: errHash,70 beforetest: func() {71 patcheputilscheckhash(t, false)72 handler = patchappexecute(t)73 },74 teardown: func() {75 unpatch(t, handler)76 },77 },78 }79 for _, tc := range cases {80 t.Run(tc.name, func(t *testing.T) {81 for _, tc := range cases {82 if tc.beforetest != nil {83 tc.beforetest()84 }85 main()86 if tc.teardown != nil {87 tc.teardown()88 }89 }...

Full Screen

Full Screen

patch

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello, world.")4}5import "fmt"6func main() {7 fmt.Println("Hello, world.")8}9import "fmt"10func main() {11 fmt.Println("Hello, world.")12}13import "fmt"14func main() {15 fmt.Println("Hello, world.")16}17import "fmt"18func main() {19 fmt.Println("Hello, world.")20}21import "fmt"22func main() {23 fmt.Println("Hello, world.")24}25import "fmt"26func main() {27 fmt.Println("Hello, world.")28}29import "fmt"30func main() {31 fmt.Println("Hello, world.")32}33import "fmt"34func main() {35 fmt.Println("Hello, world.")36}37import "fmt"38func main() {39 fmt.Println("Hello, world.")40}41import "fmt"42func main() {43 fmt.Println("Hello, world.")44}45import "fmt"46func main() {47 fmt.Println("Hello, world.")48}49import "fmt"50func main() {51 fmt.Println("Hello, world.")52}53import "fmt"54func main() {55 fmt.Println("Hello,

Full Screen

Full Screen

patch

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World")4}5import (6func main() {7 fmt.Println("Hello World")8}9import (10func main() {11 fmt.Println("Hello World")12}13import (14func main() {15 fmt.Println("Hello World")16}17import (18func main() {19 fmt.Println("Hello World")20}21import (22func main() {23 fmt.Println("Hello World")24}25import (26func main() {27 fmt.Println("Hello World")28}29import (30func main() {31 fmt.Println("Hello World")32}33import (34func main() {35 fmt.Println("Hello World")36}37import (38func main() {39 fmt.Println("Hello World")40}41import (42func main() {43 fmt.Println("Hello World")44}45import (46func main() {47 fmt.Println("Hello World")48}49import (50func main() {51 fmt.Println("Hello World")52}53import (54func main() {55 fmt.Println("Hello

Full Screen

Full Screen

patch

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main(){3fmt.Println("This is path 2")4}5import "fmt"6func main(){7fmt.Println("This is path 3")8}9import "fmt"10func main(){11fmt.Println("This is path 4")12}13import "fmt"14func main(){15fmt.Println("This is path 5")16}17import "fmt"18func main(){19fmt.Println("This is path 6")20}21import "fmt"22func main(){23fmt.Println("This is path 7")24}25import "fmt"26func main(){27fmt.Println("This is path 8")28}29import "fmt"30func main(){31fmt.Println("This is path 9")32}33import "fmt"34func main(){35fmt.Println("This is path 10")36}37import "fmt"38func main(){39fmt.Println("This is path 11")40}41import "fmt"42func main(){43fmt.Println("This is path 12")44}45import "fmt"46func main(){47fmt.Println("This is path 13")48}49import "fmt"50func main(){51fmt.Println("This is path 14")52}53import "fmt"54func main(){55fmt.Println("This is path

Full Screen

Full Screen

patch

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("URL:>", url)4 var jsonStr = []byte(`{"title":"Buy cheese and bread for breakfast."}`)5 req, err := http.NewRequest("PATCH", url, bytes.NewBuffer(jsonStr))6 req.Header.Set("Content-Type", "application/json")7 client := &http.Client{}8 resp, err := client.Do(req)9 if err != nil {10 panic(err)11 }12 defer resp.Body.Close()13 fmt.Println("response Status:", resp.Status)14 fmt.Println("response Headers:", resp.Header)15 body, _ := ioutil.ReadAll(resp.Body)16 fmt.Println("response Body:", string(body))17}18import (19func main() {20 fmt.Println("URL:>", url)21 req, err := http.NewRequest("DELETE", url, nil)22 client := &http.Client{}23 resp, err := client.Do(req)24 if err != nil {25 panic(err)26 }27 defer resp.Body.Close()28 fmt.Println("response Status:", resp.Status)29 fmt.Println("response Headers:", resp.Header)30 body, _ := ioutil.ReadAll(resp.Body)31 fmt.Println("response Body:", string(body))32}33import (34func main() {35 fmt.Println("URL:>", url)36 var jsonStr = []byte(`{"title":"Buy cheese and bread for breakfast."}`)37 req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))38 req.Header.Set("Content-Type", "application/json")39 client := &http.Client{}40 resp, err := client.Do(req)41 if err != nil {42 panic(err)43 }44 defer resp.Body.Close()45 fmt.Println("response Status:", resp.Status)

Full Screen

Full Screen

patch

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(stringutil.Reverse("Hello, world!"))4}5import (6func main() {7 fmt.Println(stringutil.Reverse("Hello, world!"))8}9import (10func main() {11 fmt.Println(stringutil.Reverse("Hello, world!"))12}13import (14func main() {15 fmt.Println(stringutil.Reverse("Hello, world!"))16}17import (18func main() {19 fmt.Println(stringutil.Reverse("Hello, world!"))20}21import (22func main() {23 fmt.Println(stringutil.Reverse("Hello, world!"))24}25import (26func main() {27 fmt.Println(stringutil.Reverse("Hello, world!"))28}29import (30func main() {31 fmt.Println(stringutil.Reverse("Hello, world!"))32}33import (34func main() {35 fmt.Println(stringutil.Reverse("Hello, world!"))36}37import (

Full Screen

Full Screen

patch

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Addition is", c)4 fmt.Println("Subtraction is", c)5 fmt.Println("Multiplication is", c)6 fmt.Println("Division is", c)7 fmt.Println("Modulus is", c)8 fmt.Println("Increment is", a)9 fmt.Println("Decrement is", a)10}11import (12func main() {13 if a == b {14 fmt.Println("a is equal to b")15 } else {16 fmt.Println("a is not equal to b")17 }18 if a < b {19 fmt.Println("a is less than b")20 } else {21 fmt.Println("a is not less than b")22 }23 if a > b {24 fmt.Println("a is greater than b")25 } else {26 fmt.Println("a is not greater than b")27 }28 if a <= b {29 fmt.Println("a is either less than or equal to b")30 } else {31 fmt.Println("a is neither less than nor equal to b")32 }33 if a >= b {34 fmt.Println("a is either greater than or equal to b")35 } else {36 fmt.Println("a is neither greater than nor equal to b")37 }38}39import (40func main() {41 if a && b {42 fmt.Println("Line 1 - condition is true")43 }44 if a || b {45 fmt.Println("Line 2 - condition is true")46 }47 if a && b {48 fmt.Println("Line 3 - condition is true")49 } else {50 fmt.Println("Line 3

Full Screen

Full Screen

patch

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 slice := []int{10, 20, 30, 40, 50}4 slice2 := []int{60, 70, 80}5 copy(slice[1:], slice2)6 fmt.Println(slice)7}8import (9func main() {10 slice := []int{10, 20, 30, 40, 50}11 slice2 := []int{60, 70, 80}12 copy(slice[1:], slice2)13 fmt.Println(slice)14}15import (16func main() {17 slice := []int{10, 20, 30, 40, 50}18 slice2 := []int{60, 70, 80}19 copy(slice[1:], slice2)20 fmt.Println(slice)21}

Full Screen

Full Screen

patch

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World")4 main.Patch()5}6import (7func Patch() {8 fmt.Println("Patch method")9}

Full Screen

Full Screen

patch

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello world")4 pack.Patch()5}6import "fmt"7func Patch() {8 fmt.Println("In patch")9}10/usr/local/go/src/main/pack (from $GOROOT)11/Users/username/go/src/main/pack (from $GOPATH)12import "fmt"13func main() {14 fmt.Println(a)15 fmt.Println(b)16 fmt.Println(c)17 fmt.Println(d)18}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful