Skip to content

Commit b669edb

Browse files
authored
Merge pull request #33 from fnaoto/2022-12-08
Add initConfig.
2 parents 79d7ed8 + 9140ee2 commit b669edb

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ build:
1111
install: build
1212
mkdir -p $(PROVIDER_DIR)
1313
mv ${BINARY} $(PROVIDER_DIR)
14-
cp .terraformrc ~
1514

1615
test:
1716
go test -v $(TESTARGS) -cover -timeout=120s -parallel=4 ./...
1817

1918
testacc: install
19+
cp .terraformrc ~
2020
TF_ACC=1 go test -v $(TESTARGS) -cover -timeout 120m ./...
21+
rm ~/.terraformrc
2122

2223
docs:
2324
go generate ./...

deploygate/provider.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,22 @@ func Provider() *schema.Provider {
3838

3939
func providerConfigure(p *schema.Provider) schema.ConfigureContextFunc {
4040
return func(_ context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
41-
config := &Config{
42-
clientConfig: go_deploygate.ClientConfig{
43-
ApiKey: d.Get("api_key").(string),
44-
},
45-
}
41+
config, err := initConfig(d)
42+
return config, diag.FromErr(err)
43+
}
44+
}
4645

47-
err := config.initClient()
48-
if err != nil {
49-
return nil, diag.FromErr(err)
50-
}
46+
func initConfig(d *schema.ResourceData) (*Config, error) {
47+
config := &Config{
48+
clientConfig: go_deploygate.ClientConfig{
49+
ApiKey: d.Get("api_key").(string),
50+
},
51+
}
5152

52-
return config, nil
53+
err := config.initClient()
54+
if err != nil {
55+
return nil, err
5356
}
57+
58+
return config, nil
5459
}

deploygate/provider_test.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

1111
"github.com/dnaeon/go-vcr/cassette"
1212
"github.com/dnaeon/go-vcr/recorder"
13-
go_deploygate "github.com/fnaoto/go_deploygate"
1413
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1514
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1615
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -63,13 +62,8 @@ func initProvider(t *testing.T) map[string]*schema.Provider {
6362

6463
func providerConfigureVCR(p *schema.Provider, t *testing.T) schema.ConfigureContextFunc {
6564
return func(_ context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
66-
config := &Config{
67-
clientConfig: go_deploygate.ClientConfig{
68-
ApiKey: d.Get("api_key").(string),
69-
},
70-
}
65+
config, err := initConfig(d)
7166

72-
err := config.initClient()
7367
if err != nil {
7468
return nil, diag.FromErr(err)
7569
}

0 commit comments

Comments
 (0)