feat: move to forgejo sdk
This commit is contained in:
parent
d9bf396917
commit
9e053a1c5c
35 changed files with 316 additions and 714 deletions
62
forgejo/data_source_gitea_user_test.go
Normal file
62
forgejo/data_source_gitea_user_test.go
Normal file
|
@ -0,0 +1,62 @@
|
|||
package forgejo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
|
||||
)
|
||||
|
||||
func TestAccDataSourceGiteaUser_basic(t *testing.T) {
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
Steps: []resource.TestStep{
|
||||
// Get user using its username
|
||||
{
|
||||
Config: testAccDataGiteaUserConfigUsername(),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccDataSourceGiteaUser("data.forgejo_user.foo"),
|
||||
),
|
||||
},
|
||||
{
|
||||
Config: testAccDataGiteaUserConfigUsername(),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccDataSourceGiteaUser("data.forgejo_user.self"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testAccDataSourceGiteaUser(src string) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
|
||||
user := s.RootModule().Resources[src]
|
||||
userResource := user.Primary.Attributes
|
||||
|
||||
testAttributes := []string{
|
||||
"username",
|
||||
}
|
||||
|
||||
for _, attribute := range testAttributes {
|
||||
if userResource[attribute] != "test01" {
|
||||
return fmt.Errorf("Expected user's parameter `%s` to be: %s, but got: `%s`", attribute, userResource[attribute], "test01")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func testAccDataGiteaUserConfigUsername() string {
|
||||
return fmt.Sprintf(`
|
||||
data "forgejo_user" "foo" {
|
||||
username = "test01"
|
||||
}
|
||||
data "forgejo_user" "self" {
|
||||
}
|
||||
`)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue