debt/tt/#6-add-tests
Tobias Trabelsi 2 years ago
parent 0208cbd960
commit 021db20aa1
No known key found for this signature in database
GPG Key ID: FF0C2839718CAF2E

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

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

@ -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)
}
Loading…
Cancel
Save