|
| 1 | +package tf6testserver |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + "github.com/hashicorp/terraform-plugin-go/tfprotov6" |
| 7 | +) |
| 8 | + |
| 9 | +var _ tfprotov6.ProviderServer = &TestServer{} |
| 10 | + |
| 11 | +type TestServer struct { |
| 12 | + DataSourceSchemas map[string]*tfprotov6.Schema |
| 13 | + ProviderMetaSchema *tfprotov6.Schema |
| 14 | + ProviderSchema *tfprotov6.Schema |
| 15 | + ResourceSchemas map[string]*tfprotov6.Schema |
| 16 | + |
| 17 | + ApplyResourceChangeCalled map[string]bool |
| 18 | + |
| 19 | + ConfigureProviderCalled bool |
| 20 | + |
| 21 | + ImportResourceStateCalled map[string]bool |
| 22 | + |
| 23 | + PlanResourceChangeCalled map[string]bool |
| 24 | + |
| 25 | + ReadDataSourceCalled map[string]bool |
| 26 | + |
| 27 | + ReadResourceCalled map[string]bool |
| 28 | + |
| 29 | + StopProviderCalled bool |
| 30 | + StopProviderError string |
| 31 | + |
| 32 | + UpgradeResourceStateCalled map[string]bool |
| 33 | + |
| 34 | + ValidateDataResourceConfigCalled map[string]bool |
| 35 | + |
| 36 | + ValidateProviderConfigCalled bool |
| 37 | + ValidateProviderConfigResponse *tfprotov6.ValidateProviderConfigResponse |
| 38 | + |
| 39 | + ValidateResourceConfigCalled map[string]bool |
| 40 | +} |
| 41 | + |
| 42 | +func (s *TestServer) ProviderServer() tfprotov6.ProviderServer { |
| 43 | + return s |
| 44 | +} |
| 45 | + |
| 46 | +func (s *TestServer) ApplyResourceChange(_ context.Context, req *tfprotov6.ApplyResourceChangeRequest) (*tfprotov6.ApplyResourceChangeResponse, error) { |
| 47 | + if s.ApplyResourceChangeCalled == nil { |
| 48 | + s.ApplyResourceChangeCalled = make(map[string]bool) |
| 49 | + } |
| 50 | + |
| 51 | + s.ApplyResourceChangeCalled[req.TypeName] = true |
| 52 | + return nil, nil |
| 53 | +} |
| 54 | + |
| 55 | +func (s *TestServer) ConfigureProvider(_ context.Context, _ *tfprotov6.ConfigureProviderRequest) (*tfprotov6.ConfigureProviderResponse, error) { |
| 56 | + s.ConfigureProviderCalled = true |
| 57 | + return &tfprotov6.ConfigureProviderResponse{}, nil |
| 58 | +} |
| 59 | + |
| 60 | +func (s *TestServer) GetProviderSchema(_ context.Context, _ *tfprotov6.GetProviderSchemaRequest) (*tfprotov6.GetProviderSchemaResponse, error) { |
| 61 | + if s.DataSourceSchemas == nil { |
| 62 | + s.DataSourceSchemas = make(map[string]*tfprotov6.Schema) |
| 63 | + } |
| 64 | + |
| 65 | + if s.ResourceSchemas == nil { |
| 66 | + s.ResourceSchemas = make(map[string]*tfprotov6.Schema) |
| 67 | + } |
| 68 | + |
| 69 | + return &tfprotov6.GetProviderSchemaResponse{ |
| 70 | + Provider: s.ProviderSchema, |
| 71 | + ProviderMeta: s.ProviderMetaSchema, |
| 72 | + ResourceSchemas: s.ResourceSchemas, |
| 73 | + DataSourceSchemas: s.DataSourceSchemas, |
| 74 | + }, nil |
| 75 | +} |
| 76 | + |
| 77 | +func (s *TestServer) ImportResourceState(_ context.Context, req *tfprotov6.ImportResourceStateRequest) (*tfprotov6.ImportResourceStateResponse, error) { |
| 78 | + if s.ImportResourceStateCalled == nil { |
| 79 | + s.ImportResourceStateCalled = make(map[string]bool) |
| 80 | + } |
| 81 | + |
| 82 | + s.ImportResourceStateCalled[req.TypeName] = true |
| 83 | + return nil, nil |
| 84 | +} |
| 85 | + |
| 86 | +func (s *TestServer) PlanResourceChange(_ context.Context, req *tfprotov6.PlanResourceChangeRequest) (*tfprotov6.PlanResourceChangeResponse, error) { |
| 87 | + if s.PlanResourceChangeCalled == nil { |
| 88 | + s.PlanResourceChangeCalled = make(map[string]bool) |
| 89 | + } |
| 90 | + |
| 91 | + s.PlanResourceChangeCalled[req.TypeName] = true |
| 92 | + return nil, nil |
| 93 | +} |
| 94 | + |
| 95 | +func (s *TestServer) ReadDataSource(_ context.Context, req *tfprotov6.ReadDataSourceRequest) (*tfprotov6.ReadDataSourceResponse, error) { |
| 96 | + if s.ReadDataSourceCalled == nil { |
| 97 | + s.ReadDataSourceCalled = make(map[string]bool) |
| 98 | + } |
| 99 | + |
| 100 | + s.ReadDataSourceCalled[req.TypeName] = true |
| 101 | + return nil, nil |
| 102 | +} |
| 103 | + |
| 104 | +func (s *TestServer) ReadResource(_ context.Context, req *tfprotov6.ReadResourceRequest) (*tfprotov6.ReadResourceResponse, error) { |
| 105 | + if s.ReadResourceCalled == nil { |
| 106 | + s.ReadResourceCalled = make(map[string]bool) |
| 107 | + } |
| 108 | + |
| 109 | + s.ReadResourceCalled[req.TypeName] = true |
| 110 | + return nil, nil |
| 111 | +} |
| 112 | + |
| 113 | +func (s *TestServer) StopProvider(_ context.Context, _ *tfprotov6.StopProviderRequest) (*tfprotov6.StopProviderResponse, error) { |
| 114 | + s.StopProviderCalled = true |
| 115 | + |
| 116 | + if s.StopProviderError != "" { |
| 117 | + return &tfprotov6.StopProviderResponse{ |
| 118 | + Error: s.StopProviderError, |
| 119 | + }, nil |
| 120 | + } |
| 121 | + |
| 122 | + return &tfprotov6.StopProviderResponse{}, nil |
| 123 | +} |
| 124 | + |
| 125 | +func (s *TestServer) UpgradeResourceState(_ context.Context, req *tfprotov6.UpgradeResourceStateRequest) (*tfprotov6.UpgradeResourceStateResponse, error) { |
| 126 | + if s.UpgradeResourceStateCalled == nil { |
| 127 | + s.UpgradeResourceStateCalled = make(map[string]bool) |
| 128 | + } |
| 129 | + |
| 130 | + s.UpgradeResourceStateCalled[req.TypeName] = true |
| 131 | + return nil, nil |
| 132 | +} |
| 133 | + |
| 134 | +func (s *TestServer) ValidateDataResourceConfig(_ context.Context, req *tfprotov6.ValidateDataResourceConfigRequest) (*tfprotov6.ValidateDataResourceConfigResponse, error) { |
| 135 | + if s.ValidateDataResourceConfigCalled == nil { |
| 136 | + s.ValidateDataResourceConfigCalled = make(map[string]bool) |
| 137 | + } |
| 138 | + |
| 139 | + s.ValidateDataResourceConfigCalled[req.TypeName] = true |
| 140 | + return nil, nil |
| 141 | +} |
| 142 | + |
| 143 | +func (s *TestServer) ValidateResourceConfig(_ context.Context, req *tfprotov6.ValidateResourceConfigRequest) (*tfprotov6.ValidateResourceConfigResponse, error) { |
| 144 | + if s.ValidateResourceConfigCalled == nil { |
| 145 | + s.ValidateResourceConfigCalled = make(map[string]bool) |
| 146 | + } |
| 147 | + |
| 148 | + s.ValidateResourceConfigCalled[req.TypeName] = true |
| 149 | + return nil, nil |
| 150 | +} |
| 151 | + |
| 152 | +func (s *TestServer) ValidateProviderConfig(_ context.Context, req *tfprotov6.ValidateProviderConfigRequest) (*tfprotov6.ValidateProviderConfigResponse, error) { |
| 153 | + s.ValidateProviderConfigCalled = true |
| 154 | + return s.ValidateProviderConfigResponse, nil |
| 155 | +} |
0 commit comments