diff --git a/docs/functions/is_http_2xx_status_code.md b/docs/functions/is_http_2xx_status_code.md index 80e24ae..749c936 100644 --- a/docs/functions/is_http_2xx_status_code.md +++ b/docs/functions/is_http_2xx_status_code.md @@ -1,6 +1,6 @@ --- # 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 @@ -8,7 +8,7 @@ description: |- # function: is_http_2xx_status_code -Checks whether the HTTP status code is a valid 2xx status code + diff --git a/docs/functions/isnull.md b/docs/functions/is_null.md similarity index 54% rename from docs/functions/isnull.md rename to docs/functions/is_null.md index 9a9aca3..f5a1696 100644 --- a/docs/functions/isnull.md +++ b/docs/functions/is_null.md @@ -1,14 +1,14 @@ --- # 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 @@ -16,11 +16,11 @@ Checks that the input is null ```text -isnull(input object) bool +is_null(object object) bool ``` ## Arguments -1. `input` (Object, Nullable) The input to check +1. `object` (Object, Nullable) The object to check diff --git a/docs/functions/notnull.md b/docs/functions/not_null.md similarity index 53% rename from docs/functions/notnull.md rename to docs/functions/not_null.md index 4ae9f75..2398bcb 100644 --- a/docs/functions/notnull.md +++ b/docs/functions/not_null.md @@ -1,14 +1,14 @@ --- # 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 @@ -16,11 +16,11 @@ Checks that the input is not null ```text -notnull(input object) bool +not_null(object object) bool ``` ## Arguments -1. `input` (Object, Nullable) The input to check +1. `object` (Object, Nullable) The object to check diff --git a/docs/functions/within_range.md b/docs/functions/within_range.md index b36b921..92ee572 100644 --- a/docs/functions/within_range.md +++ b/docs/functions/within_range.md @@ -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 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 diff --git a/internal/provider/is_http_2xx_status_code_function.go b/internal/provider/is_http_2xx_status_code_function.go index 4816ee8..5ed1083 100644 --- a/internal/provider/is_http_2xx_status_code_function.go +++ b/internal/provider/is_http_2xx_status_code_function.go @@ -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 } diff --git a/internal/provider/isnull_function.go b/internal/provider/is_null_function.go similarity index 85% rename from internal/provider/isnull_function.go rename to internal/provider/is_null_function.go index 395a940..e9ecb44 100644 --- a/internal/provider/isnull_function.go +++ b/internal/provider/is_null_function.go @@ -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 } diff --git a/internal/provider/isnull_function_test.go b/internal/provider/is_null_function_test.go similarity index 92% rename from internal/provider/isnull_function_test.go rename to internal/provider/is_null_function_test.go index 384d10c..6da95e9 100644 --- a/internal/provider/isnull_function_test.go +++ b/internal/provider/is_null_function_test.go @@ -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( diff --git a/internal/provider/notnull_function.go b/internal/provider/not_null_function.go similarity index 84% rename from internal/provider/notnull_function.go rename to internal/provider/not_null_function.go index 1616638..785ee57 100644 --- a/internal/provider/notnull_function.go +++ b/internal/provider/not_null_function.go @@ -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 } diff --git a/internal/provider/notnull_function_test.go b/internal/provider/not_null_function_test.go similarity index 92% rename from internal/provider/notnull_function_test.go rename to internal/provider/not_null_function_test.go index e36a92c..f703748 100644 --- a/internal/provider/notnull_function_test.go +++ b/internal/provider/not_null_function_test.go @@ -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( diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 4c3a355..60818d2 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -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 { diff --git a/internal/provider/within_range_function.go b/internal/provider/within_range_function.go index 4b0d797..1f3442f 100644 --- a/internal/provider/within_range_function.go +++ b/internal/provider/within_range_function.go @@ -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 +} diff --git a/main.go b/main.go index a5a8122..050b28c 100644 --- a/main.go +++ b/main.go @@ -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, }