Skip to content

Commit

Permalink
style: change naming convention for functions to use underscores
Browse files Browse the repository at this point in the history
bschaatsbergen committed Mar 15, 2024

Verified

This commit was signed with the committer’s verified signature.
haythemsellami Haythem Sellami
1 parent 6661ca3 commit 0826aa0
Showing 12 changed files with 38 additions and 73 deletions.
4 changes: 2 additions & 2 deletions docs/functions/is_http_2xx_status_code.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "is_http_2xx_status_code function - terraform-provider-assert"
page_title: "is_http_2xx_status_code function - assert"
subcategory: ""
description: |-
Checks whether the HTTP status code is a valid 2xx status code
---

# function: is_http_2xx_status_code

Checks whether the HTTP status code is a valid 2xx status code




12 changes: 6 additions & 6 deletions docs/functions/isnull.md → docs/functions/is_null.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "isnull function - terraform-provider-assert"
page_title: "is_null function - assert"
subcategory: ""
description: |-
Is null function
Checks whether a given object is null
---

# function: isnull
# function: is_null


Checks that the input is null



## Signature

<!-- signature generated by tfplugindocs -->
```text
isnull(input object) bool
is_null(object object) bool
```

## Arguments

<!-- arguments generated by tfplugindocs -->
1. `input` (Object, Nullable) The input to check
1. `object` (Object, Nullable) The object to check

12 changes: 6 additions & 6 deletions docs/functions/notnull.md → docs/functions/not_null.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "notnull function - terraform-provider-assert"
page_title: "not_null function - assert"
subcategory: ""
description: |-
Not null function
Checks whether a given object is not null
---

# function: notnull
# function: not_null


Checks that the input is not null



## Signature

<!-- signature generated by tfplugindocs -->
```text
notnull(input object) bool
not_null(object object) bool
```

## Arguments

<!-- arguments generated by tfplugindocs -->
1. `input` (Object, Nullable) The input to check
1. `object` (Object, Nullable) The object to check

8 changes: 4 additions & 4 deletions docs/functions/within_range.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "within_range function - terraform-provider-assert"
page_title: "within_range function - assert"
subcategory: ""
description: |-
Within range function
Checks whether a number is within a given range
---

# function: within_range

Checks whether the input is within the range




@@ -24,5 +24,5 @@ within_range(begin number, end number, number number) bool
<!-- arguments generated by tfplugindocs -->
1. `begin` (Number) The beginning of the range
1. `end` (Number) The end of the range
1. `number` (Number) The number to check if it is within the range
1. `number` (Number) The number to check

5 changes: 1 addition & 4 deletions internal/provider/is_http_2xx_status_code_function.go
Original file line number Diff line number Diff line change
@@ -26,8 +26,7 @@ func (r IsHTTP2XXStatusCodeFunction) Metadata(_ context.Context, req function.Me

func (r IsHTTP2XXStatusCodeFunction) Definition(_ context.Context, _ function.DefinitionRequest, resp *function.DefinitionResponse) {
resp.Definition = function.Definition{
Summary: "Checks whether the HTTP status code is a valid 2xx status code",
MarkdownDescription: "Checks whether the HTTP status code is a valid 2xx status code",
Summary: "Checks whether the HTTP status code is a valid 2xx status code",
Parameters: []function.Parameter{
function.Int64Parameter{
AllowNullValue: false,
@@ -42,9 +41,7 @@ func (r IsHTTP2XXStatusCodeFunction) Definition(_ context.Context, _ function.De

func (r IsHTTP2XXStatusCodeFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) {
var statusCode int

resp.Error = function.ConcatFuncErrors(req.Arguments.Get(ctx, &statusCode))

if resp.Error != nil {
return
}
Original file line number Diff line number Diff line change
@@ -21,19 +21,18 @@ func NewIsNullFunction() function.Function {
type IsNullFunction struct{}

func (r IsNullFunction) Metadata(_ context.Context, req function.MetadataRequest, resp *function.MetadataResponse) {
resp.Name = "isnull"
resp.Name = "is_null"
}

func (r IsNullFunction) Definition(_ context.Context, _ function.DefinitionRequest, resp *function.DefinitionResponse) {
resp.Definition = function.Definition{
Summary: "Is null function",
MarkdownDescription: "Checks that the input is null",
Summary: "Checks whether a given object is null",
Parameters: []function.Parameter{
function.ObjectParameter{
AllowNullValue: true,
AllowUnknownValues: true,
Description: "The input to check",
Name: "input",
Description: "The object to check",
Name: "object",
},
},
Return: function.BoolReturn{},
@@ -42,9 +41,7 @@ func (r IsNullFunction) Definition(_ context.Context, _ function.DefinitionReque

func (r IsNullFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) {
var data types.Object

resp.Error = function.ConcatFuncErrors(req.Arguments.Get(ctx, &data))

if resp.Error != nil {
return
}
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ func TestIsNullFunction_basic(t *testing.T) {
person = null
}
output "test" {
value = provider::assert::isnull(local.person)
value = provider::assert::is_null(local.person)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
@@ -51,7 +51,7 @@ func TestIsNullFunction_notNull(t *testing.T) {
}
}
output "test" {
value = provider::assert::isnull(local.person)
value = provider::assert::is_null(local.person)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
Original file line number Diff line number Diff line change
@@ -21,19 +21,18 @@ func NewNotNullFunction() function.Function {
type NotNullFunction struct{}

func (r NotNullFunction) Metadata(_ context.Context, req function.MetadataRequest, resp *function.MetadataResponse) {
resp.Name = "notnull"
resp.Name = "not_null"
}

func (r NotNullFunction) Definition(_ context.Context, _ function.DefinitionRequest, resp *function.DefinitionResponse) {
resp.Definition = function.Definition{
Summary: "Not null function",
MarkdownDescription: "Checks that the input is not null",
Summary: "Checks whether a given object is not null",
Parameters: []function.Parameter{
function.ObjectParameter{
AllowNullValue: true,
AllowUnknownValues: true,
Description: "The input to check",
Name: "input",
Description: "The object to check",
Name: "object",
},
},
Return: function.BoolReturn{},
@@ -42,9 +41,7 @@ func (r NotNullFunction) Definition(_ context.Context, _ function.DefinitionRequ

func (r NotNullFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) {
var data types.Object

resp.Error = function.ConcatFuncErrors(req.Arguments.Get(ctx, &data))

if resp.Error != nil {
return
}
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ func TestNotNullFunction_basic(t *testing.T) {
}
}
output "test" {
value = provider::assert::notnull(local.person)
value = provider::assert::not_null(local.person)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
@@ -51,7 +51,7 @@ func TestNotNullFunction_null(t *testing.T) {
person = null
}
output "test" {
value = provider::assert::notnull(local.person)
value = provider::assert::not_null(local.person)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
17 changes: 0 additions & 17 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ package provider

import (
"context"
"net/http"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/function"
@@ -26,10 +25,6 @@ type AssertProvider struct {
version string
}

// AssertProviderModel describes the provider data model.
type AssertProviderModel struct {
}

func (p *AssertProvider) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) {
resp.TypeName = "assert"
resp.Version = p.version
@@ -42,18 +37,6 @@ func (p *AssertProvider) Schema(ctx context.Context, req provider.SchemaRequest,
}

func (p *AssertProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {
var data AssertProviderModel

resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)

if resp.Diagnostics.HasError() {
return
}

// Example client configuration for data sources and resources
client := http.DefaultClient
resp.DataSourceData = client
resp.ResourceData = client
}

func (p *AssertProvider) Resources(ctx context.Context) []func() resource.Resource {
20 changes: 7 additions & 13 deletions internal/provider/within_range_function.go
Original file line number Diff line number Diff line change
@@ -25,8 +25,7 @@ func (r WithinRangeFunction) Metadata(_ context.Context, req function.MetadataRe

func (r WithinRangeFunction) Definition(_ context.Context, _ function.DefinitionRequest, resp *function.DefinitionResponse) {
resp.Definition = function.Definition{
Summary: "Within range function",
MarkdownDescription: "Checks whether the input is within the range",
Summary: "Checks whether a number is within a given range",
Parameters: []function.Parameter{
function.NumberParameter{
AllowNullValue: false,
@@ -43,7 +42,7 @@ func (r WithinRangeFunction) Definition(_ context.Context, _ function.Definition
function.NumberParameter{
AllowNullValue: false,
AllowUnknownValues: false,
Description: "The number to check if it is within the range",
Description: "The number to check",
Name: "number",
},
},
@@ -52,19 +51,14 @@ func (r WithinRangeFunction) Definition(_ context.Context, _ function.Definition
}

func (r WithinRangeFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) {
var begin int
var end int
var number int

var begin, end, number int
resp.Error = function.ConcatFuncErrors(req.Arguments.Get(ctx, &begin, &end, &number))

if resp.Error != nil {
return
}

isInRange := func(number, start, end int) bool {
return number >= start && number <= end
}

resp.Error = function.ConcatFuncErrors(resp.Result.Set(ctx, isInRange(number, begin, end)))
}

func isInRange(number, start, end int) bool {
return number >= start && number <= end
}
3 changes: 0 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
@@ -38,9 +38,6 @@ func main() {
flag.Parse()

opts := providerserver.ServeOpts{
// TODO: Update this string with the published name of your provider.
// Also update the tfplugindocs generate command to either remove the
// -provider-name flag or set its value to the updated provider name.
Address: "registry.terraform.io/bschaatsbergen/assert",
Debug: debug,
}

0 comments on commit 0826aa0

Please sign in to comment.