|
1 | 1 | // Copyright (c) HashiCorp, Inc.
|
2 | 2 | // SPDX-License-Identifier: MPL-2.0
|
3 |
| -package fwprovider |
| 3 | +package fwprovider_test |
4 | 4 |
|
5 | 5 | import (
|
6 |
| - "context" |
7 |
| - "io/ioutil" |
8 | 6 | "testing"
|
9 | 7 |
|
10 |
| - "github.com/hashicorp/terraform-plugin-framework/diag" |
11 | 8 | "github.com/hashicorp/terraform-plugin-framework/provider"
|
12 |
| - "github.com/hashicorp/terraform-plugin-framework/schema/validator" |
13 |
| - "github.com/hashicorp/terraform-plugin-framework/types" |
14 |
| - |
15 |
| - transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" |
| 9 | + "github.com/hashicorp/terraform-provider-google-beta/google-beta/fwprovider" |
16 | 10 | )
|
17 | 11 |
|
18 | 12 | func TestFrameworkProvider_impl(t *testing.T) {
|
19 |
| - var _ provider.ProviderWithMetaSchema = New() |
20 |
| -} |
21 |
| - |
22 |
| -func TestFrameworkProvider_CredentialsValidator(t *testing.T) { |
23 |
| - cases := map[string]struct { |
24 |
| - ConfigValue func(t *testing.T) types.String |
25 |
| - ExpectedWarningCount int |
26 |
| - ExpectedErrorCount int |
27 |
| - }{ |
28 |
| - "configuring credentials as a path to a credentials JSON file is valid": { |
29 |
| - ConfigValue: func(t *testing.T) types.String { |
30 |
| - return types.StringValue(transport_tpg.TestFakeCredentialsPath) // Path to a test fixture |
31 |
| - }, |
32 |
| - }, |
33 |
| - "configuring credentials as a path to a non-existant file is NOT valid": { |
34 |
| - ConfigValue: func(t *testing.T) types.String { |
35 |
| - return types.StringValue("./this/path/doesnt/exist.json") // Doesn't exist |
36 |
| - }, |
37 |
| - ExpectedErrorCount: 1, |
38 |
| - }, |
39 |
| - "configuring credentials as a credentials JSON string is valid": { |
40 |
| - ConfigValue: func(t *testing.T) types.String { |
41 |
| - contents, err := ioutil.ReadFile(transport_tpg.TestFakeCredentialsPath) |
42 |
| - if err != nil { |
43 |
| - t.Fatalf("Unexpected error: %s", err) |
44 |
| - } |
45 |
| - stringContents := string(contents) |
46 |
| - return types.StringValue(stringContents) |
47 |
| - }, |
48 |
| - }, |
49 |
| - "configuring credentials as an empty string is not valid": { |
50 |
| - ConfigValue: func(t *testing.T) types.String { |
51 |
| - return types.StringValue("") |
52 |
| - }, |
53 |
| - ExpectedErrorCount: 1, |
54 |
| - }, |
55 |
| - "leaving credentials unconfigured is valid": { |
56 |
| - ConfigValue: func(t *testing.T) types.String { |
57 |
| - return types.StringNull() |
58 |
| - }, |
59 |
| - }, |
60 |
| - } |
61 |
| - |
62 |
| - for tn, tc := range cases { |
63 |
| - t.Run(tn, func(t *testing.T) { |
64 |
| - // Arrange |
65 |
| - req := validator.StringRequest{ |
66 |
| - ConfigValue: tc.ConfigValue(t), |
67 |
| - } |
68 |
| - |
69 |
| - resp := validator.StringResponse{ |
70 |
| - Diagnostics: diag.Diagnostics{}, |
71 |
| - } |
72 |
| - |
73 |
| - cv := CredentialsValidator() |
74 |
| - |
75 |
| - // Act |
76 |
| - cv.ValidateString(context.Background(), req, &resp) |
77 |
| - |
78 |
| - // Assert |
79 |
| - if resp.Diagnostics.WarningsCount() > tc.ExpectedWarningCount { |
80 |
| - t.Errorf("Expected %d warnings, got %d", tc.ExpectedWarningCount, resp.Diagnostics.WarningsCount()) |
81 |
| - } |
82 |
| - if resp.Diagnostics.ErrorsCount() > tc.ExpectedErrorCount { |
83 |
| - t.Errorf("Expected %d errors, got %d", tc.ExpectedErrorCount, resp.Diagnostics.ErrorsCount()) |
84 |
| - } |
85 |
| - }) |
86 |
| - } |
| 13 | + var _ provider.ProviderWithMetaSchema = fwprovider.New() |
87 | 14 | }
|
0 commit comments