From 021db20aa1f47831b30779ddb6471e37ce4a0277 Mon Sep 17 00:00:00 2001 From: Tobias Trabelsi Date: Sat, 9 Jul 2022 23:11:26 +0200 Subject: [PATCH] hard wip --- .drone.yml | 26 +++++---- gitea/data_source_gitea_user_test.go | 12 +--- gitea/resource_gitea_user_test.go | 86 ++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 21 deletions(-) create mode 100644 gitea/resource_gitea_user_test.go diff --git a/.drone.yml b/.drone.yml index fb46e0a..ed18b47 100644 --- a/.drone.yml +++ b/.drone.yml @@ -15,23 +15,27 @@ steps: - push - pull_request - tag - - name: build - image: goreleaser/goreleaser + - name: backend + image: gitea/gitea:1.16.8 + detach: true commands: - - goreleaser build --snapshot - when: - event: - - push - - pull_request - resources: - limits: - cpu: 1000 - memory: 1024MiB + - su git + - gitea admin user create --username test --password $GITEA_PASSWORD --must-change-password false --admin --email test@mail.org + - /usr/bin/entrypoint /bin/s6-svscan /etc/s6 + environment: + GITEA_PASSWORD: + from_secret: GITEA_PASSWORD - name: test image: golang:1.18.3-alpine3.16 commands: - "apk add --update --no-cache make build-base" - "make test" + environment: + TF_ACC: 1 + GITEA_BASE_URL: "http://localhost:3000" + GITEA_USERNAME: test + GITEA_PASSWORD: + from_secret: GITEA_PASSWORD when: event: - push diff --git a/gitea/data_source_gitea_user_test.go b/gitea/data_source_gitea_user_test.go index 58731f5..aaa3487 100644 --- a/gitea/data_source_gitea_user_test.go +++ b/gitea/data_source_gitea_user_test.go @@ -1,14 +1,6 @@ package gitea -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" -) - -func TestAccDataSourceGiteaUser_basic(t *testing.T) { +/*func TestAccDataSourceGiteaUser_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -59,4 +51,4 @@ data "gitea_user" "foo" { data "gitea_user" "self" { } `) -} +}*/ diff --git a/gitea/resource_gitea_user_test.go b/gitea/resource_gitea_user_test.go new file mode 100644 index 0000000..156541c --- /dev/null +++ b/gitea/resource_gitea_user_test.go @@ -0,0 +1,86 @@ +package gitea + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" +) + +func TestAccResourceGiteaUser_basic(t *testing.T) { + name := fmt.Sprintf("user-%d", 1) + mail := fmt.Sprintf("%s@test.org", name) + fqrn := fmt.Sprintf("gitea_user.%s", name) + + userSimple := fmt.Sprintf(` + resource "gitea_user" "%s" { + username = "%s" + login_name = "%s" + email = "%s" + password = "Geheim1!" + + } + `, name, name, name, mail) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckExampleResourceDestroy, + Steps: []resource.TestStep{ + { + Config: userSimple, + ResourceName: fqrn, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(fqrn, "username", name), + ), + }, + }, + }) +} + +func testAccCheckExampleResourceDestroy(s *terraform.State) error { + // retrieve the connection established in Provider configuration + //conn := testAccProvider.Meta().(*ExampleClient) + + // loop through the resources in state, verifying each widget + // is destroyed + for _, rs := range s.RootModule().Resources { + if rs.Type != "example_widget" { + continue + } + + // Retrieve our widget by referencing it's state ID for API lookup + //request := &example.DescribeWidgets{ + // IDs: []string{rs.Primary.ID}, + //} + + //response, err := conn.DescribeWidgets(request) + //if err == nil { + // if len(response.Widgets) > 0 && *response.Widgets[0].ID == rs.Primary.ID { + // return fmt.Errorf("Widget (%s) still exists.", rs.Primary.ID) + // } + // return nil + //} + + // If the error is equivalent to 404 not found, the widget is destroyed. + // Otherwise return the error + //if !strings.Contains(err.Error(), "Widget not found") { + // return err + //} + } + + return nil +} + +func testAccResourceGiteaUserSimple(fqrn string, name string, mail string) string { + return fmt.Sprintf(` + resource "gitea_user" "%s" { + username = "%s" + login_name = "%s" + email = "%s" + password = "Geheim1!" + + } + `, fqrn, name, name, mail) +}