From c7a105076a57ca3dc8e7fc5ba8b6b3eb4a6bb5d5 Mon Sep 17 00:00:00 2001 From: Felix Date: Fri, 5 Jan 2024 22:42:51 +0300 Subject: [PATCH] test(user): Add tests --- routeros/resource_system_user_aaa_test.go | 51 ++++++++++++++++++ routeros/resource_system_user_group_test.go | 45 ++++++++++++++++ .../resource_system_user_settings_test.go | 54 +++++++++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 routeros/resource_system_user_aaa_test.go create mode 100644 routeros/resource_system_user_group_test.go create mode 100644 routeros/resource_system_user_settings_test.go diff --git a/routeros/resource_system_user_aaa_test.go b/routeros/resource_system_user_aaa_test.go new file mode 100644 index 00000000..44a2c97e --- /dev/null +++ b/routeros/resource_system_user_aaa_test.go @@ -0,0 +1,51 @@ +package routeros + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +const testUserAAA = "routeros_system_user_aaa.settings" + +func TestAccUserAAATest_basic(t *testing.T) { + t.Parallel() + for _, name := range testNames { + t.Run(name, func(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + testSetTransportEnv(t, name) + }, + ProviderFactories: testAccProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccUserAAAConfig("true"), + Check: resource.ComposeTestCheckFunc( + testResourcePrimaryInstanceId(testUserAAA), + resource.TestCheckResourceAttr(testUserAAA, "use_radius", "true"), + ), + }, + { + Config: testAccUserAAAConfig("false"), + Check: resource.ComposeTestCheckFunc( + testResourcePrimaryInstanceId(testUserAAA), + resource.TestCheckResourceAttr(testUserAAA, "use_radius", "false"), + ), + }, + }, + }) + + }) + } +} + +func testAccUserAAAConfig(param string) string { + return fmt.Sprintf(`%v + +resource "routeros_system_user_aaa" "settings" { + use_radius = %v +} +`, providerConfig, param) +} diff --git a/routeros/resource_system_user_group_test.go b/routeros/resource_system_user_group_test.go new file mode 100644 index 00000000..4fe9a020 --- /dev/null +++ b/routeros/resource_system_user_group_test.go @@ -0,0 +1,45 @@ +package routeros + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +const testUserGroupAddress = "routeros_system_user_group.test" + +func TestAccUserGroupTest_basic(t *testing.T) { + t.Parallel() + for _, name := range testNames { + t.Run(name, func(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + testSetTransportEnv(t, name) + }, + ProviderFactories: testAccProviderFactories, + CheckDestroy: testCheckResourceDestroy("/user/group", "routeros_system_user_group"), + Steps: []resource.TestStep{ + { + Config: testAccUserGroupConfig(), + Check: resource.ComposeTestCheckFunc( + testResourcePrimaryInstanceId(testUserGroupAddress), + resource.TestCheckResourceAttr(testUserGroupAddress, "name", "terraform"), + ), + }, + }, + }) + + }) + } +} + +func testAccUserGroupConfig() string { + return providerConfig + ` + +resource "routeros_system_user_group" "test" { + name = "terraform" + policy = ["api", "!ftp", "!local", "password", "policy", "read", "!reboot", "!rest-api", "!romon", "sensitive", "!sniff", "!ssh", "!telnet", "!test", "!web", "!winbox", "write"] +} +` +} diff --git a/routeros/resource_system_user_settings_test.go b/routeros/resource_system_user_settings_test.go new file mode 100644 index 00000000..3e2bbecc --- /dev/null +++ b/routeros/resource_system_user_settings_test.go @@ -0,0 +1,54 @@ +package routeros + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +const testUserSettings = "routeros_system_user_settings.test" + +func TestAccUserSettingsTest_basic(t *testing.T) { + t.Parallel() + for _, name := range testNames { + t.Run(name, func(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + testSetTransportEnv(t, name) + }, + ProviderFactories: testAccProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccUserSettingsConfig("2", "5"), + Check: resource.ComposeTestCheckFunc( + testResourcePrimaryInstanceId(testUserSettings), + resource.TestCheckResourceAttr(testUserSettings, "minimum_categories", "2"), + resource.TestCheckResourceAttr(testUserSettings, "minimum_password_length", "5"), + ), + }, + { + Config: testAccUserSettingsConfig("0", "0"), + Check: resource.ComposeTestCheckFunc( + testResourcePrimaryInstanceId(testUserSettings), + resource.TestCheckResourceAttr(testUserSettings, "minimum_categories", "0"), + resource.TestCheckResourceAttr(testUserSettings, "minimum_password_length", "0"), + ), + }, + }, + }) + + }) + } +} + +func testAccUserSettingsConfig(p1, p2 string) string { + return fmt.Sprintf(`%v + +resource "routeros_system_user_settings" "test" { + minimum_categories = %v + minimum_password_length = %v +} +`, providerConfig, p1, p2) +}