-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9c052dd
commit 9e639f5
Showing
4 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Return the rounding of of 1.2 | ||
data "stdlib_round" "down" { | ||
param = 1.2 | ||
} | ||
# => 1 | ||
|
||
# Return the rounding of 1.8 | ||
data "stdlib_round" "up" { | ||
param = 1.8 | ||
} | ||
# => 2 | ||
|
||
# Return the rounding of 1.5 | ||
data "stdlib_round" "half" { | ||
param = 1.5 | ||
} | ||
# => 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package numberfunc_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
|
||
"github.com/mschuchard/terraform-provider-stdlib/stdlib" | ||
) | ||
|
||
func TestAccRound(test *testing.T) { | ||
// invoke test | ||
resource.ParallelTest(test, resource.TestCase{ | ||
ProtoV6ProviderFactories: provider.TestAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
// test 1.2 round down | ||
{ | ||
Config: `data "stdlib_round" "test" { param = 1.2 }`, | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
// verify input param is stored correctly | ||
resource.TestCheckResourceAttr("data.stdlib_round.test", "param", "1.2"), | ||
// verify rounding result is stored correctly | ||
resource.TestCheckResourceAttr("data.stdlib_round.test", "result", "1"), | ||
// verify id stored correctly | ||
resource.TestCheckResourceAttr("data.stdlib_round.test", "id", "1.2"), | ||
), | ||
}, | ||
// test 1.8 round up | ||
{ | ||
Config: `data "stdlib_round" "test" { param = 1.8 }`, | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
// verify input param is stored correctly | ||
resource.TestCheckResourceAttr("data.stdlib_round.test", "param", "1.8"), | ||
// verify rounding result is stored correctly | ||
resource.TestCheckResourceAttr("data.stdlib_round.test", "result", "2"), | ||
// verify id stored correctly | ||
resource.TestCheckResourceAttr("data.stdlib_round.test", "id", "1.8"), | ||
), | ||
}, | ||
// test 1.5 round up | ||
{ | ||
Config: `data "stdlib_round" "test" { param = 1.5 }`, | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
// verify input param is stored correctly | ||
resource.TestCheckResourceAttr("data.stdlib_round.test", "param", "1.5"), | ||
// verify rounding result is stored correctly | ||
resource.TestCheckResourceAttr("data.stdlib_round.test", "result", "2"), | ||
// verify id stored correctly | ||
resource.TestCheckResourceAttr("data.stdlib_round.test", "id", "1.5"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters