Skip to content

Commit

Permalink
trying to get tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei-Predoiu committed Sep 26, 2022
1 parent 5e882eb commit feea178
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 41 deletions.
6 changes: 0 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ jobs:
name: Run go test
command: |
go test
- run:
name: Run terraTest
command: |
go test
cd test
go test -v -run TestTerraformAzureApplication -timeout 30m
workflows:
terraTest:
Expand Down
10 changes: 7 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,29 @@ require github.com/hashicorp/terraform-plugin-sdk/v2 v2.22.0
require (
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect
github.com/hashicorp/go-hclog v1.2.1 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.4.4 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/hc-install v0.4.0 // indirect
github.com/hashicorp/hcl/v2 v2.14.0 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/terraform-exec v0.17.3 // indirect
github.com/hashicorp/terraform-json v0.14.0 // indirect
github.com/hashicorp/terraform-plugin-go v0.14.0 // indirect
github.com/hashicorp/terraform-plugin-log v0.7.0 // indirect
github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c // indirect
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect
github.com/hashicorp/yamux v0.0.0-20210316155119-a95892c5f864 // indirect
github.com/kr/pretty v0.2.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
Expand All @@ -38,12 +42,12 @@ require (
github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect
github.com/vmihailenco/tagparser v0.1.1 // indirect
github.com/zclconf/go-cty v1.11.0 // indirect
golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167 // indirect
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20210518161634-ec7691c0a37d // indirect
google.golang.org/grpc v1.48.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)
82 changes: 82 additions & 0 deletions go.sum

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions internal/datasource/data_source_database_row.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TableRowRead(_ context.Context, data *schema.ResourceData, m interface{}) d
// Warning or errors can be collected in a slice type
var diags diag.Diagnostics
if data.Id() != "" {
tableID, sysID, err = ExtractIDs(data)
tableID, sysID, err = ExtractIDs(data.Id())
if err != nil {
return append(diags, diag.FromErr(err)...)
}
Expand Down Expand Up @@ -74,10 +74,10 @@ func TableRowRead(_ context.Context, data *schema.ResourceData, m interface{}) d
return diags
}

func ExtractIDs(data *schema.ResourceData) (tableID, sysID string, err error) {
ids := strings.Split(data.Id(), `/`)
func ExtractIDs(ID string) (tableID, sysID string, err error) {
ids := strings.Split(ID, `/`)
if len(ids) != 2 {
return "", "", errors.New(fmt.Sprintf("Faulty id!%s", data.Id()))
return "", "", errors.New(fmt.Sprintf("Faulty id!%s", ID))
}
return ids[0], ids[1], nil
}
Expand Down
27 changes: 0 additions & 27 deletions internal/provider/provider_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/resource/resource_database_row.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func tableRowUpdate(_ context.Context, d *schema.ResourceData, m interface{}) di
return diags
}

tableID, sysID, err := datasource.ExtractIDs(d)
tableID, sysID, err := datasource.ExtractIDs(d.Id())
if err != nil {
return append(diags, diag.FromErr(err)...)
}
Expand Down
40 changes: 40 additions & 0 deletions provider_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"github.com/BESTSELLER/terraform-provider-servicenow-data/internal/provider"
"os"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

var testAccProviders map[string]*schema.Provider
var testAccProvider *schema.Provider

func init() {
testAccProvider = provider.ServiceNowDataProvider()
testAccProviders = map[string]*schema.Provider{
"sericenow-data": testAccProvider,
}
}

func TestProvider(t *testing.T) {
if err := Provider().InternalValidate(); err != nil {
t.Fatalf("err: %s", err)
}
}

func TestProvider_impl(t *testing.T) {
var _ *schema.Provider = Provider()
}
func testAccPreCheck(t *testing.T) {
if err := os.Getenv("SN_API_URL"); err == "" {
t.Fatal("SN_API_URL must be set for acceptance tests")
}
if err := os.Getenv("SN_API_USER"); err == "" {
t.Fatal("SN_API_USER must be set for acceptance tests")
}
if err := os.Getenv("SN_API_PASS"); err == "" {
t.Fatal("SN_API_PASS must be set for acceptance tests")
}
}
81 changes: 81 additions & 0 deletions resource_database_row_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package main

import (
"fmt"
"github.com/BESTSELLER/terraform-provider-servicenow-data/internal/client"
"github.com/BESTSELLER/terraform-provider-servicenow-data/internal/datasource"
resource2 "github.com/BESTSELLER/terraform-provider-servicenow-data/internal/resource"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func TestAccRowBasic(t *testing.T) {
tableId := "x_beas_team_engi_0_lasse"
team := "engineering-services"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckRowDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckRowBasic(tableId, team),
Check: resource.ComposeTestCheckFunc(
testAccCheckRowExists("servicenow-data_table_row.eng-services-test"),
),
},
},
})
}

func testAccCheckRowDestroy(s *terraform.State) error {
c := testAccProvider.Meta().(*client.Client)

for _, rs := range s.RootModule().Resources {
if rs.Type != resource2.TableRowResourceName {
continue
}

tableID, rowID, err := datasource.ExtractIDs(rs.Primary.ID)

if err != nil {
return err
}

err = c.DeleteTableRow(tableID, rowID)
if err != nil {
return err
}
}

return nil
}

func testAccCheckRowBasic(tableId, team string) string {
return fmt.Sprintf(`
resource "servicenow-data_table_row" "eng-services-test" {
table_id = "%s"
row_data = {
"team": "%s",
}
}
`, tableId, team)
}

func testAccCheckRowExists(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]

if !ok {
return fmt.Errorf("Not found: %s", n)
}

if rs.Primary.ID == "" {
return fmt.Errorf("No OrderID set")
}

return nil
}
}
8 changes: 8 additions & 0 deletions terraform-registry-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"version": 1,
"metadata": {
"protocol_versions": [
"5.0"
]
}
}

0 comments on commit feea178

Please sign in to comment.