Skip to content

Commit

Permalink
adding fixes for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RavinderReddyF5 committed Aug 1, 2024
1 parent cf31cf3 commit 9a5e293
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 0 deletions.
31 changes: 31 additions & 0 deletions bigip/datasource_bigip_ltm_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,32 @@ func dataSourceBigipLtmMonitor() *schema.Resource {
Computed: true,
Description: "the database in which your user is created",
},

"base": {
Type: schema.TypeString,
Computed: true,
Description: "Specifies the location in the LDAP tree from which the monitor starts the health check",
},
"filter": {
Type: schema.TypeString,
Computed: true,
Description: "Specifies an LDAP key for which the monitor searches",
},
"mandatory_attributes": {
Type: schema.TypeString,
Computed: true,
Description: "Specifies whether the target must include attributes in its response to be considered up. The options are no (Specifies that the system performs only a one-level search (based on the Filter setting), and does not require that the target returns any attributes.) and yes (Specifies that the system performs a sub-tree search, and if the target returns no attributes, the target is considered down.)",
},
"chase_referrals": {
Type: schema.TypeString,
Computed: true,
Description: "Specifies whether the system will query the LDAP servers pointed to by any referrals in the query results.",
},
"security": {
Type: schema.TypeString,
Computed: true,
Description: "Specifies the secure communications protocol that the monitor uses to communicate with the target. The options are none (Specifies that the system does not use a security protocol for communications with the target.), ssl (Specifies that the system uses the SSL protocol for communications with the target.), and tls (Specifies that the system uses the TLS protocol for communications with the target.)",
},
},
}
}
Expand Down Expand Up @@ -141,6 +167,11 @@ func dataSourceBigipLtmMonitorRead(ctx context.Context, d *schema.ResourceData,
_ = d.Set("username", m.Username)
_ = d.Set("name", name)
_ = d.Set("database", m.Database)
_ = d.Set("base", m.Base)
_ = d.Set("filter", m.Filter)
_ = d.Set("mandatory_attributes", m.MandatoryAttributes)
_ = d.Set("chase_referrals", m.ChaseReferrals)
_ = d.Set("security", m.Security)
d.SetId(m.FullPath)
return nil
}
Expand Down
76 changes: 76 additions & 0 deletions bigip/resource_bigip_awaf_policy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
Original work from https://github.com/DealerDotCom/terraform-provider-bigip
Modifications Copyright 2019 F5 Networks Inc.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file,You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package bigip

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccBigipLtmWafPolicyTestCases(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAcctPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testMonitorsDestroyed,
Steps: []resource.TestStep{
{
Config: loadFixtureString("../examples/awaf/awaftest_issue822.tf"),
Check: resource.ComposeTestCheckFunc(
// testCheckMonitorExists("/Common/test_monitor_tc1"),
// testCheckMonitorExists("/Common/test_monitor_tc2"),
// testCheckMonitorExists("/Common/test_monitor_tc3"),
// testCheckMonitorExists("/Common/test_monitor_tc4"),
// testCheckMonitorExists("/Common/test_monitor_tc5"),
),
},
},
})
}

// func testCheckMonitorExists(name string) resource.TestCheckFunc {
// return func(s *terraform.State) error {
// client := testAccProvider.Meta().(*bigip.BigIP)

// monitors, err := client.Monitors()
// if err != nil {
// return err
// }

// for _, m := range monitors {
// if m.FullPath == name {
// return nil
// }
// }
// return fmt.Errorf("Monitor %s was not created ", name)
// }
// }

// func testMonitorsDestroyed(s *terraform.State) error {
// client := testAccProvider.Meta().(*bigip.BigIP)

// monitors, err := client.Monitors()
// if err != nil {
// return err
// }

// for _, rs := range s.RootModule().Resources {
// if rs.Type != "bigip_ltm_monitor" {
// continue
// }

// name := rs.Primary.ID
// for _, m := range monitors {
// if m.FullPath == name {
// return fmt.Errorf("Monitor %s not destroyed ", name)
// }
// }
// }
// return nil
// }
38 changes: 38 additions & 0 deletions bigip/resource_bigip_ltm_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,33 @@ func resourceBigipLtmMonitor() *schema.Resource {
Optional: true,
Description: "the ssl profile",
},

"base": {
Type: schema.TypeString,
Optional: true,
Description: "Specifies the location in the LDAP tree from which the monitor starts the health check",
},
"filter": {
Type: schema.TypeString,
Optional: true,
Description: "Specifies an LDAP key for which the monitor searches",
},
"mandatory_attributes": {
Type: schema.TypeString,
Optional: true,
Description: "Specifies whether the target must include attributes in its response to be considered up. The options are no (Specifies that the system performs only a one-level search (based on the Filter setting), and does not require that the target returns any attributes.) and yes (Specifies that the system performs a sub-tree search, and if the target returns no attributes, the target is considered down.)",
},
"chase_referrals": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Specifies whether the system will query the LDAP servers pointed to by any referrals in the query results.",
},
"security": {
Type: schema.TypeString,
Optional: true,
Description: "Specifies the secure communications protocol that the monitor uses to communicate with the target. The options are none (Specifies that the system does not use a security protocol for communications with the target.), ssl (Specifies that the system uses the SSL protocol for communications with the target.), and tls (Specifies that the system uses the TLS protocol for communications with the target.)",
},
},
}
}
Expand Down Expand Up @@ -287,6 +314,12 @@ func resourceBigipLtmMonitorRead(ctx context.Context, d *schema.ResourceData, me
_ = d.Set("password", m.Password)
_ = d.Set("name", name)
_ = d.Set("database", m.Database)

_ = d.Set("base", m.Base)
_ = d.Set("filter", m.Filter)
_ = d.Set("mandatory_attributes", m.MandatoryAttributes)
_ = d.Set("chase_referrals", m.ChaseReferrals)
_ = d.Set("security", m.Security)
return nil
}
}
Expand Down Expand Up @@ -382,5 +415,10 @@ func getLtmMonitorConfig(d *schema.ResourceData, config *bigip.Monitor) *bigip.M
config.Password = d.Get("password").(string)
config.UpInterval = d.Get("up_interval").(int)
config.SSLProfile = d.Get("ssl_profile").(string)
config.Base = d.Get("base").(string)
config.Filter = d.Get("filter").(string)
config.MandatoryAttributes = d.Get("mandatory_attributes").(string)
config.ChaseReferrals = d.Get("chase_referrals").(string)
config.Security = d.Get("security").(string)
return config
}
36 changes: 36 additions & 0 deletions bigip/resource_bigip_ltm_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var TestHttpsMonitorName = fmt.Sprintf("/%s/test-https-monitor", TestPartition)
var TestFtpMonitorName = fmt.Sprintf("/%s/test-ftp-monitor", TestPartition)
var TestUdpMonitorName = fmt.Sprintf("/%s/test-udp-monitor", TestPartition)
var TestPostgresqlMonitorName = fmt.Sprintf("/%s/test-postgresql-monitor", TestPartition)
var TestLDAPMonitorName = fmt.Sprintf("/%s/test-ldap-monitor", TestPartition)
var TestGatewayIcmpMonitorName = fmt.Sprintf("/%s/test-gateway", TestPartition)
var TestTcpHalfOpenMonitorName = fmt.Sprintf("/%s/test-tcp-half-open", TestPartition)

Expand Down Expand Up @@ -97,6 +98,17 @@ resource "bigip_ltm_monitor" "test-postgresql-monitor" {
}
`

var TestLDAPMonitorResource = `
resource "bigip_ltm_monitor" "test-ldap-monitor" {
name = "` + TestLDAPMonitorName + `"
parent = "/Common/ldap"
interval = 5
timeout = 16
base = "DC=company,DC=com"
filter = "(cn=username)"
security = "ssl"
}
`
var TestGatewayIcmpMonitorResource = `
resource "bigip_ltm_monitor" "test-gateway-icmp-monitor" {
name = "` + TestGatewayIcmpMonitorName + `"
Expand Down Expand Up @@ -292,6 +304,30 @@ func TestAccBigipLtmMonitor_UdpCreate(t *testing.T) {
},
})
}
func TestAccBigipLtmMonitor_LDAPCreate(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAcctPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testMonitorsDestroyed,
Steps: []resource.TestStep{
{
Config: TestLDAPMonitorResource,
Check: resource.ComposeTestCheckFunc(
testCheckMonitorExists(TestLDAPMonitorName),
resource.TestCheckResourceAttr("bigip_ltm_monitor.test-ldap-monitor", "parent", "/Common/ldap"),
resource.TestCheckResourceAttr("bigip_ltm_monitor.test-ldap-monitor", "timeout", "16"),
resource.TestCheckResourceAttr("bigip_ltm_monitor.test-ldap-monitor", "interval", "5"),
resource.TestCheckResourceAttr("bigip_ltm_monitor.test-ldap-monitor", "filter", "(cn=username)"),
resource.TestCheckResourceAttr("bigip_ltm_monitor.test-ldap-monitor", "security", "ssl"),
resource.TestCheckResourceAttr("bigip_ltm_monitor.test-ldap-monitor", "base", "DC=company,DC=com"),
),
},
},
})
}

func TestAccBigipLtmMonitor_PostgresqlCreate(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
Expand Down
12 changes: 12 additions & 0 deletions vendor/github.com/f5devcentral/go-bigip/ltm.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9a5e293

Please sign in to comment.