Compare commits

...

2 Commits

Author SHA1 Message Date
6165e5ae19
use correct test function
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2022-07-09 23:15:25 +02:00
021db20aa1
hard wip
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2022-07-09 23:11:26 +02:00
4 changed files with 105 additions and 23 deletions

View File

@ -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_TEST_PASSWORD
- name: test
image: golang:1.18.3-alpine3.16
commands:
- "apk add --update --no-cache make build-base"
- "make test"
- "make testacc"
environment:
TF_ACC: 1
GITEA_BASE_URL: "http://localhost:3000"
GITEA_USERNAME: test
GITEA_PASSWORD:
from_secret: GITEA_TEST_PASSWORD
when:
event:
- push

View File

@ -11,7 +11,7 @@ test: fmt-check
xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4
testacc: fmt-check
TF_ACC=1 go test -v $(TEST) $(TESTARGS) -timeout 40m
go test -v $(TEST) $(TESTARGS) -timeout 40m
vet:
@echo "go vet ."

View File

@ -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" {
}
`)
}
}*/

View File

@ -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)
}