Skip to content

Commit

Permalink
Bump api client and add tests (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdelucaa authored Jul 2, 2022
1 parent fde3e69 commit d3e96cf
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 21 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ go 1.16
require (
github.com/hashicorp/terraform-plugin-docs v0.11.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.17.0
github.com/philips-labs/go-unleash-api v1.0.0
github.com/philips-labs/go-unleash-api v1.0.1
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce h1:RPclfga2SEJmgMmz2k
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce/go.mod h1:uFMI8w+ref4v2r9jz+c9i1IfIttS/OkmLfrk1jne5hs=
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/philips-labs/go-unleash-api v1.0.0 h1:/E/27iY/USyZmKeG1W3PHg1VjA3Nw/63QOit2dmOFt8=
github.com/philips-labs/go-unleash-api v1.0.0/go.mod h1:7iJbdxlvMu9VlRLpitWFavCifH8IsfYPc7EkDY3PFv4=
github.com/philips-labs/go-unleash-api v1.0.1 h1:kJhwxtGebiDYXWysC5fit1Che8W3X5ri6gtvaWU/Pk4=
github.com/philips-labs/go-unleash-api v1.0.1/go.mod h1:7iJbdxlvMu9VlRLpitWFavCifH8IsfYPc7EkDY3PFv4=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
53 changes: 53 additions & 0 deletions internal/provider/resource_feature_enabling_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package provider

import (
"fmt"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/philips-labs/terraform-provider-unleash/utils"
)

func TestAccResourceFeatureEnabling(t *testing.T) {
resource.UnitTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testAccResourceFeatureEnabling,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestMatchResourceAttr("unleash_feature_enabling.foo", "feature_name", regexp.MustCompile("^bar")),
resource.TestCheckResourceAttr("unleash_feature_enabling.foo", "project_id", "default"),
resource.TestCheckResourceAttr("unleash_feature_enabling.foo", "environment", "development"),
resource.TestCheckResourceAttr("unleash_feature_enabling.foo", "enabled", "true"),
),
},
},
})
}

var testAccResourceFeatureEnabling = fmt.Sprintf(`
resource "unleash_feature" "foo" {
name = "bar%s"
project_id = "default"
type = "release"
}
resource "unleash_strategy_assignment" "foo" {
feature_name = unleash_feature.foo.name
project_id = "default"
environment = "development"
strategy_name = "userWithId"
parameters = {
userIds = "xyz,bar"
}
}
resource "unleash_feature_enabling" "foo" {
feature_name = unleash_feature.foo.name
project_id = "default"
environment = "development"
depends_on = [
unleash_strategy_assignment.foo
]
}
`, utils.RandomString(4))
20 changes: 10 additions & 10 deletions internal/provider/resource_feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ func TestAccResourceFeature(t *testing.T) {
Config: testAccResourceFeature,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestMatchResourceAttr("unleash_feature.foo", "name", regexp.MustCompile("^bar")),
resource.TestMatchResourceAttr("unleash_feature.foo", "project_id", regexp.MustCompile("^default$")),
resource.TestMatchResourceAttr("unleash_feature.foo", "type", regexp.MustCompile("^release$")),
resource.TestMatchResourceAttr("unleash_feature.foo", "variant.0.name", regexp.MustCompile("^Variant$")),
resource.TestMatchResourceAttr("unleash_feature.foo", "variant.0.payload.0.type", regexp.MustCompile("^string$")),
resource.TestMatchResourceAttr("unleash_feature.foo", "variant.0.payload.0.value", regexp.MustCompile("^foo$")),
resource.TestMatchResourceAttr("unleash_feature.foo", "variant.0.overrides.0.context_name", regexp.MustCompile("^appName$")),
resource.TestMatchResourceAttr("unleash_feature.foo", "variant.0.overrides.0.values.0", regexp.MustCompile("^bar$")),
resource.TestMatchResourceAttr("unleash_feature.foo", "variant.0.overrides.0.values.1", regexp.MustCompile("^xyz$")),
resource.TestMatchResourceAttr("unleash_feature.foo", "variant.0.overrides.1.context_name", regexp.MustCompile("^environment$")),
resource.TestMatchResourceAttr("unleash_feature.foo", "variant.0.overrides.1.values.0", regexp.MustCompile("^development$")),
resource.TestCheckResourceAttr("unleash_feature.foo", "project_id", "default"),
resource.TestCheckResourceAttr("unleash_feature.foo", "type", "release"),
resource.TestCheckResourceAttr("unleash_feature.foo", "variant.0.name", "Variant"),
resource.TestCheckResourceAttr("unleash_feature.foo", "variant.0.payload.0.type", "string"),
resource.TestCheckResourceAttr("unleash_feature.foo", "variant.0.payload.0.value", "foo"),
resource.TestCheckResourceAttr("unleash_feature.foo", "variant.0.overrides.0.context_name", "appName"),
resource.TestCheckResourceAttr("unleash_feature.foo", "variant.0.overrides.0.values.0", "bar"),
resource.TestCheckResourceAttr("unleash_feature.foo", "variant.0.overrides.0.values.1", "xyz"),
resource.TestCheckResourceAttr("unleash_feature.foo", "variant.0.overrides.1.context_name", "environment"),
resource.TestCheckResourceAttr("unleash_feature.foo", "variant.0.overrides.1.values.0", "development"),
),
},
},
Expand Down
16 changes: 8 additions & 8 deletions internal/provider/resource_strategy_assingment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ func TestAccResourceStrategyAssignment(t *testing.T) {
Config: testAccResourceStrategyAssignment,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestMatchResourceAttr("unleash_strategy_assignment.foo", "feature_name", regexp.MustCompile("^bar")),
resource.TestMatchResourceAttr("unleash_strategy_assignment.foo", "project_id", regexp.MustCompile("^default$")),
resource.TestMatchResourceAttr("unleash_strategy_assignment.foo", "environment", regexp.MustCompile("^development$")),
resource.TestMatchResourceAttr("unleash_strategy_assignment.foo", "strategy_name", regexp.MustCompile("^flexibleRollout$")),
resource.TestMatchResourceAttr("unleash_strategy_assignment.foo", "parameters.rollout", regexp.MustCompile("^68$")),
resource.TestMatchResourceAttr("unleash_strategy_assignment.foo", "parameters.stickiness", regexp.MustCompile("^random$")),
resource.TestMatchResourceAttr("unleash_strategy_assignment.foo", "parameters.groupId", regexp.MustCompile("^toggle$")),
resource.TestMatchResourceAttr("unleash_strategy_assignment.foo2", "strategy_name", regexp.MustCompile("^userWithId$")),
resource.TestMatchResourceAttr("unleash_strategy_assignment.foo2", "parameters.userIds", regexp.MustCompile("xyz,bar")),
resource.TestCheckResourceAttr("unleash_strategy_assignment.foo", "project_id", "default"),
resource.TestCheckResourceAttr("unleash_strategy_assignment.foo", "environment", "development"),
resource.TestCheckResourceAttr("unleash_strategy_assignment.foo", "strategy_name", "flexibleRollout"),
resource.TestCheckResourceAttr("unleash_strategy_assignment.foo", "parameters.rollout", "68"),
resource.TestCheckResourceAttr("unleash_strategy_assignment.foo", "parameters.stickiness", "random"),
resource.TestCheckResourceAttr("unleash_strategy_assignment.foo", "parameters.groupId", "toggle"),
resource.TestCheckResourceAttr("unleash_strategy_assignment.foo2", "strategy_name", "userWithId"),
resource.TestCheckResourceAttr("unleash_strategy_assignment.foo2", "parameters.userIds", "xyz,bar"),
),
},
},
Expand Down

0 comments on commit d3e96cf

Please sign in to comment.