forked from Chaotic-Logic/terraform-provider-discord
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #129 from Cyb3r-Jak3/discordgo-rewrite
Discordgo rewrite
- Loading branch information
Showing
46 changed files
with
1,631 additions
and
892 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,7 @@ terraform.tfstate | |
terraform.tfstate.backup | ||
|
||
.terraform/ | ||
|
||
.idea/ | ||
|
||
.env |
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,42 @@ | ||
package discord | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"testing" | ||
) | ||
|
||
func TestAccDatasourceDiscordColor(t *testing.T) { | ||
name := "data.discord_color.example" | ||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProviderFactories: providerFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDatasourceDiscordColorRGB, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr( | ||
name, "dec", "203569"), | ||
), | ||
}, | ||
{ | ||
Config: testAccDatasourceDiscordColorHex, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr( | ||
name, "dec", "203569"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccDatasourceDiscordColorHex = ` | ||
data "discord_color" "example" { | ||
hex = "#031b31" | ||
} | ||
` | ||
|
||
const testAccDatasourceDiscordColorRGB = ` | ||
data "discord_color" "example" { | ||
rgb = "rgb(3, 27, 49)" | ||
} | ||
` |
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,29 @@ | ||
package discord | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"testing" | ||
) | ||
|
||
func TestAccDatasourceDiscordLocalImage(t *testing.T) { | ||
name := "data.discord_local_image.example" | ||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProviderFactories: providerFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDatasourceDiscordLocalImage, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(name, "file", "provider.go"), | ||
resource.TestCheckResourceAttrSet(name, "data_uri"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccDatasourceDiscordLocalImage = ` | ||
data "discord_local_image" "example" { | ||
file = "provider.go" | ||
} | ||
` |
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,64 @@ | ||
package discord | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestAccDatasourceDiscordMember(t *testing.T) { | ||
testServerID := os.Getenv("DISCORD_TEST_SERVER_ID") | ||
testUserID := os.Getenv("DISCORD_TEST_USER_ID") | ||
testUsername := os.Getenv("DISCORD_TEST_USERNAME") | ||
if testServerID == "" || testUserID == "" || testUsername == "" { | ||
t.Skip("DISCORD_TEST_SERVER_ID, DISCORD_TEST_USER_ID, and DISCORD_TEST_USERNAME envvars must be set for acceptance tests") | ||
} | ||
|
||
name := "data.discord_member.example" | ||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProviderFactories: providerFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDatasourceDiscordMemberUserID(testServerID, testUserID), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(name, "server_id", testServerID), | ||
resource.TestCheckResourceAttr(name, "user_id", testUserID), | ||
resource.TestCheckResourceAttrSet(name, "joined_at"), | ||
resource.TestCheckResourceAttrSet(name, "avatar"), | ||
resource.TestCheckResourceAttrSet(name, "roles.#"), | ||
resource.TestCheckResourceAttr(name, "in_server", "true"), | ||
), | ||
}, | ||
{ | ||
Config: testAccDatasourceDiscordMemberUsername(testServerID, testUsername), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(name, "server_id", testServerID), | ||
resource.TestCheckResourceAttr(name, "username", testUsername), | ||
resource.TestCheckResourceAttrSet(name, "joined_at"), | ||
resource.TestCheckResourceAttrSet(name, "avatar"), | ||
resource.TestCheckResourceAttrSet(name, "roles.#"), | ||
resource.TestCheckResourceAttr(name, "in_server", "true"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDatasourceDiscordMemberUserID(serverId string, userID string) string { | ||
return fmt.Sprintf(` | ||
data "discord_member" "example" { | ||
server_id = "%[1]s" | ||
user_id = "%[2]s" | ||
}`, serverId, userID) | ||
} | ||
|
||
func testAccDatasourceDiscordMemberUsername(serverId string, username string) string { | ||
return fmt.Sprintf(` | ||
data "discord_member" "example" { | ||
server_id = "%[1]s" | ||
username = "%[2]s" | ||
discriminator = "0" | ||
}`, serverId, username) | ||
} |
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,49 @@ | ||
package discord | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"testing" | ||
) | ||
|
||
func TestAccDatasourceDiscordPermission(t *testing.T) { | ||
name := "data.discord_permission.example" | ||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProviderFactories: providerFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDatasourceDiscordPermissionSimple, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(name, "administrator", "allow"), | ||
resource.TestCheckResourceAttr(name, "allow_bits", "8"), | ||
), | ||
}, | ||
{ | ||
Config: testAccDatasourceDiscordPermissionComplex, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(name, "send_messages", "allow"), | ||
resource.TestCheckResourceAttr(name, "embed_links", "allow"), | ||
resource.TestCheckResourceAttr(name, "allow_bits", "18432"), | ||
resource.TestCheckResourceAttr(name, "speak", "deny"), | ||
resource.TestCheckResourceAttr(name, "change_nickname", "deny"), | ||
resource.TestCheckResourceAttr(name, "deny_bits", "69206016"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccDatasourceDiscordPermissionSimple = ` | ||
data "discord_permission" "example" { | ||
administrator = "allow" | ||
} | ||
` | ||
|
||
const testAccDatasourceDiscordPermissionComplex = ` | ||
data "discord_permission" "example" { | ||
send_messages = "allow" | ||
embed_links = "allow" | ||
speak = "deny" | ||
change_nickname = "deny" | ||
} | ||
` |
Oops, something went wrong.