diff --git a/internal/provider/data_source_branch.go b/internal/provider/data_source_branch.go index 3551be6..3420c30 100644 --- a/internal/provider/data_source_branch.go +++ b/internal/provider/data_source_branch.go @@ -17,12 +17,12 @@ import ( "github.com/hashicorp/terraform-plugin-log/tflog" ) -type branchDataSource struct{} +type BranchDataSource struct{} var ( - _ datasource.DataSource = (*branchDataSource)(nil) - _ datasource.DataSourceWithGetSchema = (*branchDataSource)(nil) - _ datasource.DataSourceWithMetadata = (*branchDataSource)(nil) + _ datasource.DataSource = (*BranchDataSource)(nil) + _ datasource.DataSourceWithGetSchema = (*BranchDataSource)(nil) + _ datasource.DataSourceWithMetadata = (*BranchDataSource)(nil) ) type branchDataSourceModel struct { @@ -35,14 +35,14 @@ type branchDataSourceModel struct { } func NewBranchDataSource() datasource.DataSource { - return &branchDataSource{} + return &BranchDataSource{} } -func (d *branchDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { +func (d *BranchDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { resp.TypeName = req.ProviderTypeName + "_branch" } -func (d *branchDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { +func (d *BranchDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ Description: "Fetches information about a specific branch of a Git repository.", MarkdownDescription: "Fetches information about a specific branch of a Git repository.", @@ -93,7 +93,7 @@ func (d *branchDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diag }, nil } -func (d *branchDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { +func (d *BranchDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { tflog.Debug(ctx, "Read data source git_branch") var inputs branchDataSourceModel diff --git a/internal/provider/data_source_branch_test.go b/internal/provider/data_source_branch_test.go index 2d2d4ef..f59fbc1 100644 --- a/internal/provider/data_source_branch_test.go +++ b/internal/provider/data_source_branch_test.go @@ -6,15 +6,25 @@ package provider_test import ( + "context" "fmt" "github.com/go-git/go-git/v5/config" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/metio/terraform-provider-git/internal/provider" "github.com/metio/terraform-provider-git/internal/testutils" "os" "regexp" "testing" ) +func TestDataSourceGitBranch_GetSchema(t *testing.T) { + t.Parallel() + r := &provider.BranchDataSource{} + schema, _ := r.GetSchema(context.TODO()) + + testutils.VerifySchemaDescriptions(t, schema) +} + func TestDataSourceGitBranch(t *testing.T) { t.Parallel() directory, repository := testutils.CreateRepository(t) diff --git a/internal/provider/data_source_branches.go b/internal/provider/data_source_branches.go index f16e9b1..e763bdb 100644 --- a/internal/provider/data_source_branches.go +++ b/internal/provider/data_source_branches.go @@ -18,12 +18,12 @@ import ( "github.com/hashicorp/terraform-plugin-log/tflog" ) -type branchesDataSource struct{} +type BranchesDataSource struct{} var ( - _ datasource.DataSource = (*branchesDataSource)(nil) - _ datasource.DataSourceWithGetSchema = (*branchesDataSource)(nil) - _ datasource.DataSourceWithMetadata = (*branchesDataSource)(nil) + _ datasource.DataSource = (*BranchesDataSource)(nil) + _ datasource.DataSourceWithGetSchema = (*BranchesDataSource)(nil) + _ datasource.DataSourceWithMetadata = (*BranchesDataSource)(nil) ) type branchesDataSourceModel struct { @@ -33,14 +33,14 @@ type branchesDataSourceModel struct { } func NewBranchesDataSource() datasource.DataSource { - return &branchesDataSource{} + return &BranchesDataSource{} } -func (d *branchesDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { +func (d *BranchesDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { resp.TypeName = req.ProviderTypeName + "_branches" } -func (d *branchesDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { +func (d *BranchesDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ Description: "Fetches all branches of a Git repository.", MarkdownDescription: "Fetches all branches of a Git repository.", @@ -89,7 +89,7 @@ func (d *branchesDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Di }, nil } -func (d *branchesDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { +func (d *BranchesDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { tflog.Debug(ctx, "Read data source git_branches") var inputs branchesDataSourceModel diff --git a/internal/provider/data_source_branches_test.go b/internal/provider/data_source_branches_test.go index 88d0314..807ac2e 100644 --- a/internal/provider/data_source_branches_test.go +++ b/internal/provider/data_source_branches_test.go @@ -6,14 +6,24 @@ package provider_test import ( + "context" "fmt" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/metio/terraform-provider-git/internal/provider" "github.com/metio/terraform-provider-git/internal/testutils" "os" "regexp" "testing" ) +func TestDataSourceGitBranches_GetSchema(t *testing.T) { + t.Parallel() + r := &provider.BranchesDataSource{} + schema, _ := r.GetSchema(context.TODO()) + + testutils.VerifySchemaDescriptions(t, schema) +} + func TestDataSourceGitBranches(t *testing.T) { t.Parallel() directory, repository := testutils.CreateRepository(t) diff --git a/internal/provider/data_source_commit.go b/internal/provider/data_source_commit.go index 45087a1..5160a88 100644 --- a/internal/provider/data_source_commit.go +++ b/internal/provider/data_source_commit.go @@ -15,12 +15,12 @@ import ( "github.com/hashicorp/terraform-plugin-log/tflog" ) -type commitDataSource struct{} +type CommitDataSource struct{} var ( - _ datasource.DataSource = (*commitDataSource)(nil) - _ datasource.DataSourceWithGetSchema = (*commitDataSource)(nil) - _ datasource.DataSourceWithMetadata = (*commitDataSource)(nil) + _ datasource.DataSource = (*CommitDataSource)(nil) + _ datasource.DataSourceWithGetSchema = (*CommitDataSource)(nil) + _ datasource.DataSourceWithMetadata = (*CommitDataSource)(nil) ) type commitDataSourceModel struct { @@ -37,14 +37,14 @@ type commitDataSourceModel struct { } func NewCommitDataSource() datasource.DataSource { - return &commitDataSource{} + return &CommitDataSource{} } -func (d *commitDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { +func (d *CommitDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { resp.TypeName = req.ProviderTypeName + "_commit" } -func (d *commitDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { +func (d *CommitDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ Description: "Fetches information about a single commit.", MarkdownDescription: "Fetches information about a single commit.", @@ -159,7 +159,7 @@ func (d *commitDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diag }, nil } -func (d *commitDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { +func (d *CommitDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { tflog.Debug(ctx, "Read data source git_commit") var inputs commitDataSourceModel diff --git a/internal/provider/data_source_commit_test.go b/internal/provider/data_source_commit_test.go index 3dd3376..378f706 100644 --- a/internal/provider/data_source_commit_test.go +++ b/internal/provider/data_source_commit_test.go @@ -6,14 +6,24 @@ package provider_test import ( + "context" "fmt" "github.com/go-git/go-git/v5" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/metio/terraform-provider-git/internal/provider" "github.com/metio/terraform-provider-git/internal/testutils" "os" "testing" ) +func TestDataSourceGitCommit_GetSchema(t *testing.T) { + t.Parallel() + r := &provider.CommitDataSource{} + schema, _ := r.GetSchema(context.TODO()) + + testutils.VerifySchemaDescriptions(t, schema) +} + func TestDataSourceGitCommit(t *testing.T) { t.Parallel() directory, repository := testutils.CreateRepository(t) diff --git a/internal/provider/data_source_config.go b/internal/provider/data_source_config.go index 56e11b9..dd19ee8 100644 --- a/internal/provider/data_source_config.go +++ b/internal/provider/data_source_config.go @@ -16,12 +16,12 @@ import ( "github.com/metio/terraform-provider-git/internal/modifiers" ) -type configDataSource struct{} +type ConfigDataSource struct{} var ( - _ datasource.DataSource = (*configDataSource)(nil) - _ datasource.DataSourceWithGetSchema = (*configDataSource)(nil) - _ datasource.DataSourceWithMetadata = (*configDataSource)(nil) + _ datasource.DataSource = (*ConfigDataSource)(nil) + _ datasource.DataSourceWithGetSchema = (*ConfigDataSource)(nil) + _ datasource.DataSourceWithMetadata = (*ConfigDataSource)(nil) ) type configDataSourceModel struct { @@ -37,14 +37,14 @@ type configDataSourceModel struct { } func NewConfigDataSource() datasource.DataSource { - return &configDataSource{} + return &ConfigDataSource{} } -func (d *configDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { +func (d *ConfigDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { resp.TypeName = req.ProviderTypeName + "_config" } -func (d *configDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { +func (d *ConfigDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ Description: "Reads the configuration of a Git repository.", MarkdownDescription: "Reads the configuration of a Git repository.", @@ -121,7 +121,7 @@ func (d *configDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diag }, nil } -func (d *configDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { +func (d *ConfigDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { tflog.Debug(ctx, "Read data source git_config") var inputs configDataSourceModel diff --git a/internal/provider/data_source_config_test.go b/internal/provider/data_source_config_test.go index 25bc70c..560ace7 100644 --- a/internal/provider/data_source_config_test.go +++ b/internal/provider/data_source_config_test.go @@ -6,14 +6,24 @@ package provider_test import ( + "context" "fmt" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/metio/terraform-provider-git/internal/provider" "github.com/metio/terraform-provider-git/internal/testutils" "os" "regexp" "testing" ) +func TestDataSourceGitConfig_GetSchema(t *testing.T) { + t.Parallel() + r := &provider.ConfigDataSource{} + schema, _ := r.GetSchema(context.TODO()) + + testutils.VerifySchemaDescriptions(t, schema) +} + func TestDataSourceGitConfig(t *testing.T) { t.Parallel() directory, repository := testutils.CreateRepository(t) diff --git a/internal/provider/data_source_log.go b/internal/provider/data_source_log.go index 169c104..f5df5b5 100644 --- a/internal/provider/data_source_log.go +++ b/internal/provider/data_source_log.go @@ -18,12 +18,12 @@ import ( "github.com/metio/terraform-provider-git/internal/modifiers" ) -type logDataSource struct{} +type LogDataSource struct{} var ( - _ datasource.DataSource = (*logDataSource)(nil) - _ datasource.DataSourceWithGetSchema = (*logDataSource)(nil) - _ datasource.DataSourceWithMetadata = (*logDataSource)(nil) + _ datasource.DataSource = (*LogDataSource)(nil) + _ datasource.DataSourceWithGetSchema = (*LogDataSource)(nil) + _ datasource.DataSourceWithMetadata = (*LogDataSource)(nil) ) type logDataSourceModel struct { @@ -41,14 +41,14 @@ type logDataSourceModel struct { } func NewLogDataSource() datasource.DataSource { - return &logDataSource{} + return &LogDataSource{} } -func (d *logDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { +func (d *LogDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { resp.TypeName = req.ProviderTypeName + "_log" } -func (d *logDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { +func (d *LogDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ Description: "Fetches the commit log of a Git repository similar to 'git log'.", MarkdownDescription: "Fetches the commit log of a Git repository similar to `git log`.", @@ -157,7 +157,7 @@ func (d *logDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnos }, nil } -func (d *logDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { +func (d *LogDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { tflog.Debug(ctx, "Read data source git_log") var inputs logDataSourceModel diff --git a/internal/provider/data_source_log_test.go b/internal/provider/data_source_log_test.go index d823fae..88e9e09 100644 --- a/internal/provider/data_source_log_test.go +++ b/internal/provider/data_source_log_test.go @@ -6,14 +6,24 @@ package provider_test import ( + "context" "fmt" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/metio/terraform-provider-git/internal/provider" "github.com/metio/terraform-provider-git/internal/testutils" "os" "regexp" "testing" ) +func TestDataSourceGitLog_GetSchema(t *testing.T) { + t.Parallel() + r := &provider.LogDataSource{} + schema, _ := r.GetSchema(context.TODO()) + + testutils.VerifySchemaDescriptions(t, schema) +} + func TestDataSourceGitLog(t *testing.T) { t.Parallel() directory, repository := testutils.CreateRepository(t) diff --git a/internal/provider/data_source_remote.go b/internal/provider/data_source_remote.go index 5fb86fd..948a887 100644 --- a/internal/provider/data_source_remote.go +++ b/internal/provider/data_source_remote.go @@ -15,12 +15,12 @@ import ( "github.com/hashicorp/terraform-plugin-log/tflog" ) -type remoteDataSource struct{} +type RemoteDataSource struct{} var ( - _ datasource.DataSource = (*remoteDataSource)(nil) - _ datasource.DataSourceWithGetSchema = (*remoteDataSource)(nil) - _ datasource.DataSourceWithMetadata = (*remoteDataSource)(nil) + _ datasource.DataSource = (*RemoteDataSource)(nil) + _ datasource.DataSourceWithGetSchema = (*RemoteDataSource)(nil) + _ datasource.DataSourceWithMetadata = (*RemoteDataSource)(nil) ) type remoteDataSourceModel struct { @@ -31,14 +31,14 @@ type remoteDataSourceModel struct { } func NewRemoteDataSource() datasource.DataSource { - return &remoteDataSource{} + return &RemoteDataSource{} } -func (d *remoteDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { +func (d *RemoteDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { resp.TypeName = req.ProviderTypeName + "_remote" } -func (d *remoteDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { +func (d *RemoteDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ Description: "Reads information about a specific remote of a Git repository.", MarkdownDescription: "Reads information about a specific remote of a Git repository.", @@ -79,7 +79,7 @@ func (d *remoteDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diag }, nil } -func (d *remoteDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { +func (d *RemoteDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { tflog.Debug(ctx, "Read data source git_remote") var inputs remoteDataSourceModel diff --git a/internal/provider/data_source_remote_test.go b/internal/provider/data_source_remote_test.go index 59e9772..f08f774 100644 --- a/internal/provider/data_source_remote_test.go +++ b/internal/provider/data_source_remote_test.go @@ -6,14 +6,24 @@ package provider_test import ( + "context" "fmt" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/metio/terraform-provider-git/internal/provider" "github.com/metio/terraform-provider-git/internal/testutils" "os" "regexp" "testing" ) +func TestDataSourceGitRemote_GetSchema(t *testing.T) { + t.Parallel() + r := &provider.RemoteDataSource{} + schema, _ := r.GetSchema(context.TODO()) + + testutils.VerifySchemaDescriptions(t, schema) +} + func TestDataSourceGitRemote(t *testing.T) { t.Parallel() directory, repository := testutils.CreateRepository(t) diff --git a/internal/provider/data_source_remotes.go b/internal/provider/data_source_remotes.go index 7b326a0..861bd43 100644 --- a/internal/provider/data_source_remotes.go +++ b/internal/provider/data_source_remotes.go @@ -16,12 +16,12 @@ import ( "github.com/hashicorp/terraform-plugin-log/tflog" ) -type remotesDataSource struct{} +type RemotesDataSource struct{} var ( - _ datasource.DataSource = (*remotesDataSource)(nil) - _ datasource.DataSourceWithGetSchema = (*remotesDataSource)(nil) - _ datasource.DataSourceWithMetadata = (*remotesDataSource)(nil) + _ datasource.DataSource = (*RemotesDataSource)(nil) + _ datasource.DataSourceWithGetSchema = (*RemotesDataSource)(nil) + _ datasource.DataSourceWithMetadata = (*RemotesDataSource)(nil) ) type remotesDataSourceModel struct { @@ -31,14 +31,14 @@ type remotesDataSourceModel struct { } func NewRemotesDataSource() datasource.DataSource { - return &remotesDataSource{} + return &RemotesDataSource{} } -func (d *remotesDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { +func (d *RemotesDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { resp.TypeName = req.ProviderTypeName + "_remotes" } -func (d *remotesDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { +func (d *RemotesDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ Description: "Reads all configured remotes of a Git repository.", MarkdownDescription: "Reads all configured remotes of a Git repository.", @@ -77,7 +77,7 @@ func (d *remotesDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Dia }, nil } -func (d *remotesDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { +func (d *RemotesDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { tflog.Debug(ctx, "Read data source git_remotes") var inputs remotesDataSourceModel diff --git a/internal/provider/data_source_remotes_test.go b/internal/provider/data_source_remotes_test.go index d3f059e..a4d95c8 100644 --- a/internal/provider/data_source_remotes_test.go +++ b/internal/provider/data_source_remotes_test.go @@ -6,14 +6,24 @@ package provider_test import ( + "context" "fmt" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/metio/terraform-provider-git/internal/provider" "github.com/metio/terraform-provider-git/internal/testutils" "os" "regexp" "testing" ) +func TestDataSourceGitRemotes_GetSchema(t *testing.T) { + t.Parallel() + r := &provider.RemotesDataSource{} + schema, _ := r.GetSchema(context.TODO()) + + testutils.VerifySchemaDescriptions(t, schema) +} + func TestDataSourceGitRemotes(t *testing.T) { t.Parallel() directory, repository := testutils.CreateRepository(t) diff --git a/internal/provider/data_source_repository.go b/internal/provider/data_source_repository.go index 4ef3702..9493bcf 100644 --- a/internal/provider/data_source_repository.go +++ b/internal/provider/data_source_repository.go @@ -16,12 +16,12 @@ import ( "github.com/hashicorp/terraform-plugin-log/tflog" ) -type repositoryDataSource struct{} +type RepositoryDataSource struct{} var ( - _ datasource.DataSource = (*repositoryDataSource)(nil) - _ datasource.DataSourceWithGetSchema = (*repositoryDataSource)(nil) - _ datasource.DataSourceWithMetadata = (*repositoryDataSource)(nil) + _ datasource.DataSource = (*RepositoryDataSource)(nil) + _ datasource.DataSourceWithGetSchema = (*RepositoryDataSource)(nil) + _ datasource.DataSourceWithMetadata = (*RepositoryDataSource)(nil) ) type repositoryDataSourceModel struct { @@ -32,14 +32,14 @@ type repositoryDataSourceModel struct { } func NewRepositoryDataSource() datasource.DataSource { - return &repositoryDataSource{} + return &RepositoryDataSource{} } -func (d *repositoryDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { +func (d *RepositoryDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { resp.TypeName = req.ProviderTypeName + "_repository" } -func (d *repositoryDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { +func (d *RepositoryDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ Description: "Reads information about a specific Git repository.", MarkdownDescription: "Reads information about a specific Git repository.", @@ -75,7 +75,7 @@ func (d *repositoryDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag. }, nil } -func (d *repositoryDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { +func (d *RepositoryDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { tflog.Debug(ctx, "Read data source git_repository") var inputs repositoryDataSourceModel diff --git a/internal/provider/data_source_repository_test.go b/internal/provider/data_source_repository_test.go index a6e1482..000a5ee 100644 --- a/internal/provider/data_source_repository_test.go +++ b/internal/provider/data_source_repository_test.go @@ -6,14 +6,24 @@ package provider_test import ( + "context" "fmt" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/metio/terraform-provider-git/internal/provider" "github.com/metio/terraform-provider-git/internal/testutils" "os" "regexp" "testing" ) +func TestDataSourceGitRepository_GetSchema(t *testing.T) { + t.Parallel() + r := &provider.RepositoryDataSource{} + schema, _ := r.GetSchema(context.TODO()) + + testutils.VerifySchemaDescriptions(t, schema) +} + func TestDataSourceGitRepository(t *testing.T) { t.Parallel() directory, repository := testutils.CreateRepository(t) diff --git a/internal/provider/data_source_status.go b/internal/provider/data_source_status.go index 4ea7d31..2c1fd35 100644 --- a/internal/provider/data_source_status.go +++ b/internal/provider/data_source_status.go @@ -16,12 +16,12 @@ import ( "github.com/hashicorp/terraform-plugin-log/tflog" ) -type statusDataSource struct{} +type StatusDataSource struct{} var ( - _ datasource.DataSource = (*statusDataSource)(nil) - _ datasource.DataSourceWithGetSchema = (*statusDataSource)(nil) - _ datasource.DataSourceWithMetadata = (*statusDataSource)(nil) + _ datasource.DataSource = (*StatusDataSource)(nil) + _ datasource.DataSourceWithGetSchema = (*StatusDataSource)(nil) + _ datasource.DataSourceWithMetadata = (*StatusDataSource)(nil) ) type statusDataSourceModel struct { @@ -33,14 +33,14 @@ type statusDataSourceModel struct { } func NewStatusDataSource() datasource.DataSource { - return &statusDataSource{} + return &StatusDataSource{} } -func (d *statusDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { +func (d *StatusDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { resp.TypeName = req.ProviderTypeName + "_status" } -func (d *statusDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { +func (d *StatusDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ Description: "Fetches the status of a single files in a Git repository.", MarkdownDescription: "Fetches the status of a single files in a Git repository.", @@ -85,7 +85,7 @@ func (d *statusDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diag }, nil } -func (d *statusDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { +func (d *StatusDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { tflog.Debug(ctx, "Read data source git_status") var inputs statusDataSourceModel diff --git a/internal/provider/data_source_status_test.go b/internal/provider/data_source_status_test.go index 203a544..3795c8b 100644 --- a/internal/provider/data_source_status_test.go +++ b/internal/provider/data_source_status_test.go @@ -6,13 +6,23 @@ package provider_test import ( + "context" "fmt" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/metio/terraform-provider-git/internal/provider" "github.com/metio/terraform-provider-git/internal/testutils" "os" "testing" ) +func TestDataSourceGitStatus_GetSchema(t *testing.T) { + t.Parallel() + r := &provider.StatusDataSource{} + schema, _ := r.GetSchema(context.TODO()) + + testutils.VerifySchemaDescriptions(t, schema) +} + func TestDataSourceGitStatus_StagedFile(t *testing.T) { t.Parallel() directory, repository := testutils.CreateRepository(t) diff --git a/internal/provider/data_source_statuses.go b/internal/provider/data_source_statuses.go index 1212d24..69bb847 100644 --- a/internal/provider/data_source_statuses.go +++ b/internal/provider/data_source_statuses.go @@ -16,12 +16,12 @@ import ( "github.com/hashicorp/terraform-plugin-log/tflog" ) -type statusesDataSource struct{} +type StatusesDataSource struct{} var ( - _ datasource.DataSource = (*statusesDataSource)(nil) - _ datasource.DataSourceWithGetSchema = (*statusesDataSource)(nil) - _ datasource.DataSourceWithMetadata = (*statusesDataSource)(nil) + _ datasource.DataSource = (*StatusesDataSource)(nil) + _ datasource.DataSourceWithGetSchema = (*StatusesDataSource)(nil) + _ datasource.DataSourceWithMetadata = (*StatusesDataSource)(nil) ) type statusesDataSourceModel struct { @@ -32,14 +32,14 @@ type statusesDataSourceModel struct { } func NewStatusesDataSource() datasource.DataSource { - return &statusesDataSource{} + return &StatusesDataSource{} } -func (d *statusesDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { +func (d *StatusesDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { resp.TypeName = req.ProviderTypeName + "_statuses" } -func (d *statusesDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { +func (d *StatusesDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ Description: "Fetches the status of all files in a Git repository.", MarkdownDescription: "Fetches the status of all files in a Git repository.", @@ -88,7 +88,7 @@ func (d *statusesDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Di }, nil } -func (d *statusesDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { +func (d *StatusesDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { tflog.Debug(ctx, "Read data source git_statuses") var inputs statusesDataSourceModel diff --git a/internal/provider/data_source_statuses_test.go b/internal/provider/data_source_statuses_test.go index 5a01ba1..df1ecb1 100644 --- a/internal/provider/data_source_statuses_test.go +++ b/internal/provider/data_source_statuses_test.go @@ -6,13 +6,23 @@ package provider_test import ( + "context" "fmt" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/metio/terraform-provider-git/internal/provider" "github.com/metio/terraform-provider-git/internal/testutils" "os" "testing" ) +func TestDataSourceGitStatuses_GetSchema(t *testing.T) { + t.Parallel() + r := &provider.StatusesDataSource{} + schema, _ := r.GetSchema(context.TODO()) + + testutils.VerifySchemaDescriptions(t, schema) +} + func TestDataSourceGitStatuses_Unclean(t *testing.T) { t.Parallel() directory, repository := testutils.CreateRepository(t) diff --git a/internal/provider/data_source_tag.go b/internal/provider/data_source_tag.go index 7f70385..900e96f 100644 --- a/internal/provider/data_source_tag.go +++ b/internal/provider/data_source_tag.go @@ -15,12 +15,12 @@ import ( "github.com/hashicorp/terraform-plugin-log/tflog" ) -type tagDataSource struct{} +type TagDataSource struct{} var ( - _ datasource.DataSource = (*tagDataSource)(nil) - _ datasource.DataSourceWithGetSchema = (*tagDataSource)(nil) - _ datasource.DataSourceWithMetadata = (*tagDataSource)(nil) + _ datasource.DataSource = (*TagDataSource)(nil) + _ datasource.DataSourceWithGetSchema = (*TagDataSource)(nil) + _ datasource.DataSourceWithMetadata = (*TagDataSource)(nil) ) type tagDataSourceModel struct { @@ -34,14 +34,14 @@ type tagDataSourceModel struct { } func NewTagDataSource() datasource.DataSource { - return &tagDataSource{} + return &TagDataSource{} } -func (d *tagDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { +func (d *TagDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { resp.TypeName = req.ProviderTypeName + "_tag" } -func (d *tagDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { +func (d *TagDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ Description: "Reads information about a specific tag of a Git repository.", MarkdownDescription: "Reads information about a specific tag of a Git repository.", @@ -98,7 +98,7 @@ func (d *tagDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnos }, nil } -func (d *tagDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { +func (d *TagDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { tflog.Debug(ctx, "Reading Git repository tag") var inputs tagDataSourceModel diff --git a/internal/provider/data_source_tag_test.go b/internal/provider/data_source_tag_test.go index a0da6b1..1a0849e 100644 --- a/internal/provider/data_source_tag_test.go +++ b/internal/provider/data_source_tag_test.go @@ -6,14 +6,24 @@ package provider_test import ( + "context" "fmt" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/metio/terraform-provider-git/internal/provider" "github.com/metio/terraform-provider-git/internal/testutils" "os" "regexp" "testing" ) +func TestDataSourceGitTag_GetSchema(t *testing.T) { + t.Parallel() + r := &provider.TagDataSource{} + schema, _ := r.GetSchema(context.TODO()) + + testutils.VerifySchemaDescriptions(t, schema) +} + func TestDataSourceGitTag(t *testing.T) { t.Parallel() directory, repository := testutils.CreateRepository(t) diff --git a/internal/provider/data_source_tags.go b/internal/provider/data_source_tags.go index 5cc972e..c449441 100644 --- a/internal/provider/data_source_tags.go +++ b/internal/provider/data_source_tags.go @@ -18,12 +18,12 @@ import ( "github.com/metio/terraform-provider-git/internal/modifiers" ) -type tagsDataSource struct{} +type TagsDataSource struct{} var ( - _ datasource.DataSource = (*tagsDataSource)(nil) - _ datasource.DataSourceWithGetSchema = (*tagsDataSource)(nil) - _ datasource.DataSourceWithMetadata = (*tagsDataSource)(nil) + _ datasource.DataSource = (*TagsDataSource)(nil) + _ datasource.DataSourceWithGetSchema = (*TagsDataSource)(nil) + _ datasource.DataSourceWithMetadata = (*TagsDataSource)(nil) ) type tagsDataSourceModel struct { @@ -35,14 +35,14 @@ type tagsDataSourceModel struct { } func NewTagsDataSource() datasource.DataSource { - return &tagsDataSource{} + return &TagsDataSource{} } -func (d *tagsDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { +func (d *TagsDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { resp.TypeName = req.ProviderTypeName + "_tags" } -func (d *tagsDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { +func (d *TagsDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ Description: "Reads information about all tags of a Git repository.", MarkdownDescription: "Reads information about all tags of a Git repository.", @@ -111,7 +111,7 @@ func (d *tagsDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagno }, nil } -func (d *tagsDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { +func (d *TagsDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { tflog.Debug(ctx, "Read data source git_tags") var inputs tagsDataSourceModel diff --git a/internal/provider/data_source_tags_test.go b/internal/provider/data_source_tags_test.go index 99aea02..49cba36 100644 --- a/internal/provider/data_source_tags_test.go +++ b/internal/provider/data_source_tags_test.go @@ -6,14 +6,24 @@ package provider_test import ( + "context" "fmt" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/metio/terraform-provider-git/internal/provider" "github.com/metio/terraform-provider-git/internal/testutils" "os" "regexp" "testing" ) +func TestDataSourceGitTags_GetSchema(t *testing.T) { + t.Parallel() + r := &provider.TagsDataSource{} + schema, _ := r.GetSchema(context.TODO()) + + testutils.VerifySchemaDescriptions(t, schema) +} + func TestDataSourceGitTags(t *testing.T) { t.Parallel() directory, repository := testutils.CreateRepository(t) diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 382e544..b5f09e6 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -14,35 +14,35 @@ import ( "github.com/hashicorp/terraform-plugin-framework/tfsdk" ) -type gitProvider struct{} +type GitProvider struct{} var ( - _ provider.Provider = (*gitProvider)(nil) - _ provider.ProviderWithMetadata = (*gitProvider)(nil) - _ provider.ProviderWithDataSources = (*gitProvider)(nil) - _ provider.ProviderWithResources = (*gitProvider)(nil) + _ provider.Provider = (*GitProvider)(nil) + _ provider.ProviderWithMetadata = (*GitProvider)(nil) + _ provider.ProviderWithDataSources = (*GitProvider)(nil) + _ provider.ProviderWithResources = (*GitProvider)(nil) ) func New() provider.Provider { - return &gitProvider{} + return &GitProvider{} } -func (p *gitProvider) Metadata(_ context.Context, _ provider.MetadataRequest, resp *provider.MetadataResponse) { +func (p *GitProvider) Metadata(_ context.Context, _ provider.MetadataRequest, resp *provider.MetadataResponse) { resp.TypeName = "git" } -func (p *gitProvider) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { +func (p *GitProvider) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ Description: "Provider for local Git operations. Requires Terraform 1.0 or later.", MarkdownDescription: "Provider for local [Git](https://git-scm.com/) operations. Requires Terraform 1.0 or later.", }, nil } -func (p *gitProvider) Configure(_ context.Context, _ provider.ConfigureRequest, _ *provider.ConfigureResponse) { +func (p *GitProvider) Configure(_ context.Context, _ provider.ConfigureRequest, _ *provider.ConfigureResponse) { // NO-OP: provider requires no configuration } -func (p *gitProvider) DataSources(_ context.Context) []func() datasource.DataSource { +func (p *GitProvider) DataSources(_ context.Context) []func() datasource.DataSource { return []func() datasource.DataSource{ NewBranchDataSource, NewBranchesDataSource, @@ -59,7 +59,7 @@ func (p *gitProvider) DataSources(_ context.Context) []func() datasource.DataSou } } -func (p *gitProvider) Resources(_ context.Context) []func() resource.Resource { +func (p *GitProvider) Resources(_ context.Context) []func() resource.Resource { return []func() resource.Resource{ NewAddResource, NewCommitResource, diff --git a/internal/provider/provider_unit_test.go b/internal/provider/provider_test.go similarity index 55% rename from internal/provider/provider_unit_test.go rename to internal/provider/provider_test.go index 6e91f43..7d5ff48 100644 --- a/internal/provider/provider_unit_test.go +++ b/internal/provider/provider_test.go @@ -3,29 +3,32 @@ * SPDX-License-Identifier: 0BSD */ -package provider +package provider_test import ( "context" "github.com/hashicorp/terraform-plugin-framework/provider" + internal "github.com/metio/terraform-provider-git/internal/provider" + "github.com/metio/terraform-provider-git/internal/testutils" "github.com/stretchr/testify/assert" "testing" ) func TestGitProvider_Metadata(t *testing.T) { - p := &gitProvider{} + t.Parallel() + p := &internal.GitProvider{} request := provider.MetadataRequest{} response := &provider.MetadataResponse{} p.Metadata(context.TODO(), request, response) - assert.Equal(t, "git", response.TypeName) + assert.Equal(t, "git", response.TypeName, "TypeName") } func TestGitProvider_GetSchema(t *testing.T) { - p := &gitProvider{} + t.Parallel() + p := &internal.GitProvider{} schema, _ := p.GetSchema(context.TODO()) - assert.NotNil(t, schema.Description) - assert.NotNil(t, schema.MarkdownDescription) - assert.Nil(t, schema.Attributes) + testutils.VerifySchemaDescriptions(t, schema) + assert.Nil(t, schema.Attributes, "should require no configuration") } diff --git a/internal/provider/resource_add.go b/internal/provider/resource_add.go index d392d36..5615b23 100644 --- a/internal/provider/resource_add.go +++ b/internal/provider/resource_add.go @@ -19,13 +19,13 @@ import ( "time" ) -type addResource struct{} +type AddResource struct{} var ( - _ resource.Resource = (*addResource)(nil) - _ resource.ResourceWithMetadata = (*addResource)(nil) - _ resource.ResourceWithGetSchema = (*addResource)(nil) - _ resource.ResourceWithModifyPlan = (*addResource)(nil) + _ resource.Resource = (*AddResource)(nil) + _ resource.ResourceWithMetadata = (*AddResource)(nil) + _ resource.ResourceWithGetSchema = (*AddResource)(nil) + _ resource.ResourceWithModifyPlan = (*AddResource)(nil) ) type addResourceModel struct { @@ -35,14 +35,14 @@ type addResourceModel struct { } func NewAddResource() resource.Resource { - return &addResource{} + return &AddResource{} } -func (r *addResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { +func (r *AddResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { resp.TypeName = req.ProviderTypeName + "_add" } -func (r *addResource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { +func (r *AddResource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ Description: "Add file contents to the index similar to 'git add'.", MarkdownDescription: "Add file contents to the index similar to `git add`.", @@ -78,7 +78,7 @@ func (r *addResource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnosti }, nil } -func (r *addResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { +func (r *AddResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { tflog.Debug(ctx, "Create resource git_add") var inputs addResourceModel @@ -153,22 +153,22 @@ func (r *addResource) Create(ctx context.Context, req resource.CreateRequest, re } } -func (r *addResource) Read(ctx context.Context, _ resource.ReadRequest, _ *resource.ReadResponse) { +func (r *AddResource) Read(ctx context.Context, _ resource.ReadRequest, _ *resource.ReadResponse) { tflog.Debug(ctx, "Read resource git_add") // NO-OP: All data is already in Terraform state } -func (r *addResource) Update(ctx context.Context, _ resource.UpdateRequest, _ *resource.UpdateResponse) { +func (r *AddResource) Update(ctx context.Context, _ resource.UpdateRequest, _ *resource.UpdateResponse) { tflog.Debug(ctx, "Update resource git_add") // NO-OP: All attributes require replacement, thus delete/create will be called } -func (r *addResource) Delete(ctx context.Context, _ resource.DeleteRequest, _ *resource.DeleteResponse) { +func (r *AddResource) Delete(ctx context.Context, _ resource.DeleteRequest, _ *resource.DeleteResponse) { tflog.Debug(ctx, "Delete resource git_add") // NO-OP: Terraform removes the state automatically for us } -func (r *addResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { +func (r *AddResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { tflog.Debug(ctx, "ModifyPlan resource git_add") if req.State.Raw.IsNull() { diff --git a/internal/provider/resource_add_test.go b/internal/provider/resource_add_test.go index 8ec9be1..2fe4a79 100644 --- a/internal/provider/resource_add_test.go +++ b/internal/provider/resource_add_test.go @@ -6,14 +6,24 @@ package provider_test import ( + "context" "fmt" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/metio/terraform-provider-git/internal/provider" "github.com/metio/terraform-provider-git/internal/testutils" "os" "regexp" "testing" ) +func TestResourceGitAdd_GetSchema(t *testing.T) { + t.Parallel() + r := &provider.AddResource{} + schema, _ := r.GetSchema(context.TODO()) + + testutils.VerifySchemaDescriptions(t, schema) +} + func TestResourceGitAdd(t *testing.T) { t.Parallel() directory, repository := testutils.CreateRepository(t) diff --git a/internal/provider/resource_commit.go b/internal/provider/resource_commit.go index b34ce57..12e668c 100644 --- a/internal/provider/resource_commit.go +++ b/internal/provider/resource_commit.go @@ -16,12 +16,12 @@ import ( "github.com/metio/terraform-provider-git/internal/modifiers" ) -type commitResource struct{} +type CommitResource struct{} var ( - _ resource.Resource = (*commitResource)(nil) - _ resource.ResourceWithMetadata = (*commitResource)(nil) - _ resource.ResourceWithGetSchema = (*commitResource)(nil) + _ resource.Resource = (*CommitResource)(nil) + _ resource.ResourceWithMetadata = (*CommitResource)(nil) + _ resource.ResourceWithGetSchema = (*CommitResource)(nil) ) type commitResourceModel struct { @@ -35,14 +35,14 @@ type commitResourceModel struct { } func NewCommitResource() resource.Resource { - return &commitResource{} + return &CommitResource{} } -func (r *commitResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { +func (r *CommitResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { resp.TypeName = req.ProviderTypeName + "_commit" } -func (r *commitResource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { +func (r *CommitResource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ Description: "Record changes to the repository similar to 'git commit'", MarkdownDescription: "Record changes to the repository with `git commit`", @@ -142,7 +142,7 @@ func (r *commitResource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagno }, nil } -func (r *commitResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { +func (r *CommitResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { tflog.Debug(ctx, "Create resource git_commit") var inputs commitResourceModel @@ -214,17 +214,17 @@ func (r *commitResource) Create(ctx context.Context, req resource.CreateRequest, } } -func (r *commitResource) Read(ctx context.Context, _ resource.ReadRequest, _ *resource.ReadResponse) { +func (r *CommitResource) Read(ctx context.Context, _ resource.ReadRequest, _ *resource.ReadResponse) { tflog.Debug(ctx, "Read resource git_add") // NO-OP: All data is already in Terraform state } -func (r *commitResource) Update(ctx context.Context, _ resource.UpdateRequest, _ *resource.UpdateResponse) { +func (r *CommitResource) Update(ctx context.Context, _ resource.UpdateRequest, _ *resource.UpdateResponse) { tflog.Debug(ctx, "Update resource git_add") // NO-OP: All attributes require replacement, thus delete/create will be called } -func (r *commitResource) Delete(ctx context.Context, _ resource.DeleteRequest, _ *resource.DeleteResponse) { +func (r *CommitResource) Delete(ctx context.Context, _ resource.DeleteRequest, _ *resource.DeleteResponse) { tflog.Debug(ctx, "Delete resource git_add") // NO-OP: Terraform removes the state automatically for us } diff --git a/internal/provider/resource_commit_test.go b/internal/provider/resource_commit_test.go index 4bd9d3f..56f3d47 100644 --- a/internal/provider/resource_commit_test.go +++ b/internal/provider/resource_commit_test.go @@ -6,14 +6,24 @@ package provider_test import ( + "context" "fmt" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/metio/terraform-provider-git/internal/provider" "github.com/metio/terraform-provider-git/internal/testutils" "os" "regexp" "testing" ) +func TestResourceGitCommit_GetSchema(t *testing.T) { + t.Parallel() + r := &provider.CommitResource{} + schema, _ := r.GetSchema(context.TODO()) + + testutils.VerifySchemaDescriptions(t, schema) +} + func TestResourceGitCommit(t *testing.T) { t.Parallel() directory, repository := testutils.CreateRepository(t) diff --git a/internal/provider/resource_init.go b/internal/provider/resource_init.go index f09dc9b..3d4029c 100644 --- a/internal/provider/resource_init.go +++ b/internal/provider/resource_init.go @@ -20,13 +20,13 @@ import ( "os" ) -type initResource struct{} +type InitResource struct{} var ( - _ resource.Resource = (*initResource)(nil) - _ resource.ResourceWithMetadata = (*initResource)(nil) - _ resource.ResourceWithGetSchema = (*initResource)(nil) - _ resource.ResourceWithImportState = (*initResource)(nil) + _ resource.Resource = (*InitResource)(nil) + _ resource.ResourceWithMetadata = (*InitResource)(nil) + _ resource.ResourceWithGetSchema = (*InitResource)(nil) + _ resource.ResourceWithImportState = (*InitResource)(nil) ) type initResourceModel struct { @@ -36,14 +36,14 @@ type initResourceModel struct { } func NewInitResource() resource.Resource { - return &initResource{} + return &InitResource{} } -func (r *initResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { +func (r *InitResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { resp.TypeName = req.ProviderTypeName + "_init" } -func (r *initResource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { +func (r *InitResource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ Description: "Initializes a Git repository similar to 'git init'.", MarkdownDescription: "Initializes a Git repository similar to `git init`.", @@ -81,7 +81,7 @@ func (r *initResource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnost }, nil } -func (r *initResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { +func (r *InitResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { tflog.Debug(ctx, "Create resource git_init") var inputs initResourceModel @@ -126,7 +126,7 @@ func (r *initResource) Create(ctx context.Context, req resource.CreateRequest, r } } -func (r *initResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { +func (r *InitResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { tflog.Debug(ctx, "Read resource git_init") var state initResourceModel @@ -160,12 +160,12 @@ func (r *initResource) Read(ctx context.Context, req resource.ReadRequest, resp } } -func (r *initResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { +func (r *InitResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { tflog.Debug(ctx, "Update resource git_init") updatedUsingPlan(ctx, &req, resp, &initResourceModel{}) } -func (r *initResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { +func (r *InitResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { tflog.Debug(ctx, "Delete resource git_init") var state initResourceModel @@ -198,7 +198,7 @@ func (r *initResource) Delete(ctx context.Context, req resource.DeleteRequest, r } } -func (r *initResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { +func (r *InitResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "ImportState resource git_init") if req.ID == "" { diff --git a/internal/provider/resource_init_test.go b/internal/provider/resource_init_test.go index b84e6f1..280515b 100644 --- a/internal/provider/resource_init_test.go +++ b/internal/provider/resource_init_test.go @@ -6,14 +6,24 @@ package provider_test import ( + "context" "fmt" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/metio/terraform-provider-git/internal/provider" "github.com/metio/terraform-provider-git/internal/testutils" "os" "regexp" "testing" ) +func TestResourceGitInit_GetSchema(t *testing.T) { + t.Parallel() + r := &provider.InitResource{} + schema, _ := r.GetSchema(context.TODO()) + + testutils.VerifySchemaDescriptions(t, schema) +} + func TestResourceGitInit(t *testing.T) { t.Parallel() directory := testutils.TemporaryDirectory(t) diff --git a/internal/provider/resource_remote.go b/internal/provider/resource_remote.go index a73d641..c2ff8f4 100644 --- a/internal/provider/resource_remote.go +++ b/internal/provider/resource_remote.go @@ -18,13 +18,13 @@ import ( "strings" ) -type remoteResource struct{} +type RemoteResource struct{} var ( - _ resource.Resource = (*remoteResource)(nil) - _ resource.ResourceWithMetadata = (*remoteResource)(nil) - _ resource.ResourceWithGetSchema = (*remoteResource)(nil) - _ resource.ResourceWithImportState = (*remoteResource)(nil) + _ resource.Resource = (*RemoteResource)(nil) + _ resource.ResourceWithMetadata = (*RemoteResource)(nil) + _ resource.ResourceWithGetSchema = (*RemoteResource)(nil) + _ resource.ResourceWithImportState = (*RemoteResource)(nil) ) type remoteResourceModel struct { @@ -35,14 +35,14 @@ type remoteResourceModel struct { } func NewRemoteResource() resource.Resource { - return &remoteResource{} + return &RemoteResource{} } -func (r *remoteResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { +func (r *RemoteResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { resp.TypeName = req.ProviderTypeName + "_remote" } -func (r *remoteResource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { +func (r *RemoteResource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ Description: "Manages remotes in a Git repository similar to 'git remote'.", MarkdownDescription: "Manages remotes in a Git repository similar to `git remote`.", @@ -89,7 +89,7 @@ func (r *remoteResource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagno }, nil } -func (r *remoteResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { +func (r *RemoteResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { tflog.Debug(ctx, "Create resource git_remote") var inputs remoteResourceModel @@ -144,7 +144,7 @@ func (r *remoteResource) Create(ctx context.Context, req resource.CreateRequest, } } -func (r *remoteResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { +func (r *RemoteResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { tflog.Debug(ctx, "Read resource git_remote") var state remoteResourceModel @@ -182,7 +182,7 @@ func (r *remoteResource) Read(ctx context.Context, req resource.ReadRequest, res } } -func (r *remoteResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { +func (r *RemoteResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { tflog.Debug(ctx, "Update resource git_remote") var inputs remoteResourceModel @@ -253,7 +253,7 @@ func (r *remoteResource) Update(ctx context.Context, req resource.UpdateRequest, } } -func (r *remoteResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { +func (r *RemoteResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { tflog.Debug(ctx, "Delete resource git_remote") var state remoteResourceModel @@ -282,7 +282,7 @@ func (r *remoteResource) Delete(ctx context.Context, req resource.DeleteRequest, }) } -func (r *remoteResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { +func (r *RemoteResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "ImportState resource git_remote") id := req.ID diff --git a/internal/provider/resource_remote_test.go b/internal/provider/resource_remote_test.go index 2bdc901..daef729 100644 --- a/internal/provider/resource_remote_test.go +++ b/internal/provider/resource_remote_test.go @@ -6,14 +6,24 @@ package provider_test import ( + "context" "fmt" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/metio/terraform-provider-git/internal/provider" "github.com/metio/terraform-provider-git/internal/testutils" "os" "regexp" "testing" ) +func TestResourceGitRemote_GetSchema(t *testing.T) { + t.Parallel() + r := &provider.RemoteResource{} + schema, _ := r.GetSchema(context.TODO()) + + testutils.VerifySchemaDescriptions(t, schema) +} + func TestResourceGitRemote(t *testing.T) { t.Parallel() directory, _ := testutils.CreateRepository(t) diff --git a/internal/provider/resource_tag.go b/internal/provider/resource_tag.go index badddf2..7017130 100644 --- a/internal/provider/resource_tag.go +++ b/internal/provider/resource_tag.go @@ -18,12 +18,12 @@ import ( "strings" ) -type tagResource struct{} +type TagResource struct{} var ( - _ resource.Resource = (*tagResource)(nil) - _ resource.ResourceWithMetadata = (*tagResource)(nil) - _ resource.ResourceWithGetSchema = (*tagResource)(nil) + _ resource.Resource = (*TagResource)(nil) + _ resource.ResourceWithMetadata = (*TagResource)(nil) + _ resource.ResourceWithGetSchema = (*TagResource)(nil) ) type tagResourceModel struct { @@ -36,14 +36,14 @@ type tagResourceModel struct { } func NewTagResource() resource.Resource { - return &tagResource{} + return &TagResource{} } -func (r *tagResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { +func (r *TagResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { resp.TypeName = req.ProviderTypeName + "_tag" } -func (r *tagResource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { +func (r *TagResource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ Description: "Manage Git tags similar to 'git tag'.", MarkdownDescription: "Manage Git tags similar to `git tag`.", @@ -108,7 +108,7 @@ func (r *tagResource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnosti }, nil } -func (r *tagResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { +func (r *TagResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { tflog.Debug(ctx, "Create resource git_tag") var inputs tagResourceModel @@ -165,7 +165,7 @@ func (r *tagResource) Create(ctx context.Context, req resource.CreateRequest, re } } -func (r *tagResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { +func (r *TagResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { tflog.Debug(ctx, "Read resource git_tag") var state tagResourceModel @@ -214,12 +214,12 @@ func (r *tagResource) Read(ctx context.Context, req resource.ReadRequest, resp * } } -func (r *tagResource) Update(ctx context.Context, _ resource.UpdateRequest, _ *resource.UpdateResponse) { +func (r *TagResource) Update(ctx context.Context, _ resource.UpdateRequest, _ *resource.UpdateResponse) { tflog.Debug(ctx, "Update resource git_tag") // NO-OP: all attributes require replace, thus Delete and Create methods will be called } -func (r *tagResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { +func (r *TagResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { tflog.Debug(ctx, "Delete resource git_tag") var state tagResourceModel @@ -243,7 +243,7 @@ func (r *tagResource) Delete(ctx context.Context, req resource.DeleteRequest, re } } -func (r *tagResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { +func (r *TagResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "ImportState resource git_tag") id := req.ID diff --git a/internal/provider/resource_tag_test.go b/internal/provider/resource_tag_test.go index 4ba2a8e..5d42f83 100644 --- a/internal/provider/resource_tag_test.go +++ b/internal/provider/resource_tag_test.go @@ -6,14 +6,24 @@ package provider_test import ( + "context" "fmt" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/metio/terraform-provider-git/internal/provider" "github.com/metio/terraform-provider-git/internal/testutils" "os" "regexp" "testing" ) +func TestResourceGitTag_GetSchema(t *testing.T) { + t.Parallel() + r := &provider.TagResource{} + schema, _ := r.GetSchema(context.TODO()) + + testutils.VerifySchemaDescriptions(t, schema) +} + func TestResourceGitTag(t *testing.T) { t.Parallel() directory, repository := testutils.CreateRepository(t) diff --git a/internal/testutils/checkers.go b/internal/testutils/checkers.go index c68f344..2c2b983 100644 --- a/internal/testutils/checkers.go +++ b/internal/testutils/checkers.go @@ -9,8 +9,11 @@ package testutils import ( "fmt" + "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/stretchr/testify/assert" + "testing" ) func CheckExactLength(expectedLength int) func(input string) error { @@ -65,3 +68,20 @@ func CheckResourceAttrInstanceState(attributeName, attributeValue string) resour return nil } } + +func VerifySchemaDescriptions(t *testing.T, schema tfsdk.Schema) { + assert.NotEmpty(t, schema.Description, "schema.Description") + assert.NotEmpty(t, schema.MarkdownDescription, "schema.MarkdownDescription") + + for name, attribute := range schema.Attributes { + assert.NotEmpty(t, attribute.Description, fmt.Sprintf("%s.Description", name)) + assert.NotEmpty(t, attribute.MarkdownDescription, fmt.Sprintf("%s.MarkdownDescription", name)) + + if attribute.Attributes != nil { + for nn, nv := range attribute.Attributes.GetAttributes() { + assert.NotEmpty(t, nv.GetDescription(), fmt.Sprintf("%s.Description", nn)) + assert.NotEmpty(t, nv.GetMarkdownDescription(), fmt.Sprintf("%s.MarkdownDescription", nn)) + } + } + } +}