-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: acceptance test | resource | agents
- Loading branch information
1 parent
af5f89c
commit a48cc4e
Showing
7 changed files
with
184 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package resource_test | ||
|
||
import ( | ||
"os" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/config" | ||
"github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/provider" | ||
"github.com/aruba-uxi/terraform-provider-hpeuxi/test/live/util" | ||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
func TestAgentResource(t *testing.T) { | ||
const ( | ||
agentName = "tf_provider_acceptance_test_agent_resource" | ||
agentNameUpdated = agentName + "_updated" | ||
) | ||
|
||
// we provision an agent here so that we have something to delete later on | ||
agentUid, err := util.ProvisionAgent{ | ||
CustomerUid: config.CustomerUid, | ||
ProvisionToken: os.Getenv("UXI_PROVISION_TOKEN"), | ||
DeviceSerial: config.AgentCreateSerial, | ||
DeviceGatewayHost: config.DeviceGatewayHost, | ||
}.Provision() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
resource.Test(t, resource.TestCase{ | ||
ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
// Creating an agent is not allowed | ||
{ | ||
Config: provider.ProviderConfig + ` | ||
resource "uxi_agent" "my_agent" { | ||
name = "` + agentName + `" | ||
}`, | ||
|
||
ExpectError: regexp.MustCompile( | ||
`creating an agent is not supported; agents can only be imported`, | ||
), | ||
}, | ||
// Importing an agent | ||
{ | ||
Config: provider.ProviderConfig + ` | ||
resource "uxi_agent" "my_agent" { | ||
name = "` + agentName + `" | ||
notes = "" | ||
pcap_mode = "light" | ||
} | ||
import { | ||
to = uxi_agent.my_agent | ||
id = "` + agentUid + `" | ||
}`, | ||
|
||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("uxi_agent.my_agent", "name", agentName), | ||
resource.TestCheckResourceAttr("uxi_agent.my_agent", "notes", ""), | ||
resource.TestCheckResourceAttr("uxi_agent.my_agent", "pcap_mode", "light"), | ||
resource.TestCheckResourceAttr("uxi_agent.my_agent", "id", agentUid), | ||
), | ||
}, | ||
// ImportState testing | ||
{ | ||
ResourceName: "uxi_agent.my_agent", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
// Update testing | ||
{ | ||
Config: provider.ProviderConfig + ` | ||
resource "uxi_agent" "my_agent" { | ||
name = "` + agentNameUpdated + `" | ||
notes = "notes" | ||
pcap_mode = "off" | ||
}`, | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("uxi_agent.my_agent", "id", agentUid), | ||
resource.TestCheckResourceAttr("uxi_agent.my_agent", "name", agentNameUpdated), | ||
resource.TestCheckResourceAttr("uxi_agent.my_agent", "notes", "notes"), | ||
resource.TestCheckResourceAttr("uxi_agent.my_agent", "pcap_mode", "off"), | ||
), | ||
}, | ||
// Delete testing happen automatically | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters