forked from isometry/terraform-provider-github
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprovider_test.go
More file actions
227 lines (184 loc) · 5.07 KB
/
provider_test.go
File metadata and controls
227 lines (184 loc) · 5.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
package github
import (
"context"
"fmt"
"testing"
"github.com/hashicorp/terraform-plugin-framework/providerserver"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/hashicorp/terraform-plugin-mux/tf5to6server"
"github.com/hashicorp/terraform-plugin-mux/tf6muxserver"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/nexthink-oss/terraform-provider-github/v7/internal/provider"
)
var testAccProviders map[string]*schema.Provider
var testAccProviderFactories func(providers *[]*schema.Provider) map[string]func() (*schema.Provider, error)
var testAccProvider *schema.Provider
// testAccProtoV6ProviderFactories provides Protocol 6 provider factories for testing
// with muxing support (Framework + upgraded SDKv2)
var testAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){
"github": func() (tfprotov6.ProviderServer, error) {
ctx := context.Background()
// Upgrade SDKv2 provider (Protocol 5) to Protocol 6
upgradedSdkServer, err := tf5to6server.UpgradeServer(
ctx,
Provider().GRPCProvider,
)
if err != nil {
return nil, err
}
// Combine Framework (Protocol 6) and upgraded SDKv2 providers
providers := []func() tfprotov6.ProviderServer{
providerserver.NewProtocol6(provider.NewFrameworkProvider()()),
func() tfprotov6.ProviderServer { return upgradedSdkServer },
}
muxServer, err := tf6muxserver.NewMuxServer(ctx, providers...)
if err != nil {
return nil, err
}
return muxServer.ProviderServer(), nil
},
}
func init() {
testAccProvider = Provider()
testAccProviders = map[string]*schema.Provider{
"github": testAccProvider,
}
testAccProviderFactories = func(providers *[]*schema.Provider) map[string]func() (*schema.Provider, error) {
return map[string]func() (*schema.Provider, error){
"github": func() (*schema.Provider, error) {
p := Provider()
*providers = append(*providers, p)
return p, nil
},
}
}
}
func TestProvider(t *testing.T) {
t.Run("runs internal validation without error", func(t *testing.T) {
if err := Provider().InternalValidate(); err != nil {
t.Fatalf("err: %s", err)
}
})
t.Run("has an implementation", func(t *testing.T) {
// FIXME: unsure if this is useful; refactored from:
// func TestProvider_impl(t *testing.T) {
// var _ terraform.ResourceProvider = Provider()
// }
var _ = *Provider()
})
}
// TODO: this is failing
func TestAccProviderConfigure(t *testing.T) {
t.Run("can be configured to run anonymously", func(t *testing.T) {
config := `
provider "github" {}
`
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, anonymous) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
ExpectNonEmptyPlan: false,
},
},
})
})
t.Run("can be configured to run insecurely", func(t *testing.T) {
config := fmt.Sprintf(`
provider "github" {
token = "%s"
insecure = true
}`,
testToken,
)
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, anonymous) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
ExpectNonEmptyPlan: false,
},
},
})
})
t.Run("can be configured with an individual account", func(t *testing.T) {
config := fmt.Sprintf(`
provider "github" {
token = "%s"
owner = "%s"
}`,
testToken, testOwnerFunc(),
)
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, individual) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
ExpectNonEmptyPlan: false,
},
},
})
})
t.Run("can be configured with an organization account", func(t *testing.T) {
config := fmt.Sprintf(`
provider "github" {
token = "%s"
organization = "%s"
}`,
testToken, testOrganizationFunc(),
)
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, organization) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
ExpectNonEmptyPlan: false,
},
},
})
})
t.Run("can be configured with a GHES deployment", func(t *testing.T) {
config := fmt.Sprintf(`
provider "github" {
token = "%s"
base_url = "%s"
}`,
testToken, testBaseURLGHES,
)
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, individual) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
ExpectNonEmptyPlan: false,
},
},
})
})
t.Run("can be configured with max retries", func(t *testing.T) {
config := fmt.Sprintf(`
provider "github" {
token = "%s"
owner = "%s"
max_retries = 3
}`,
testToken, testOwnerFunc(),
)
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, individual) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
ExpectNonEmptyPlan: false,
},
},
})
})
}