Skip to content

Commit

Permalink
Correcting interface usage in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
john-delivuk-rl committed Dec 9, 2020
1 parent eaca8de commit d5e0b35
Show file tree
Hide file tree
Showing 24 changed files with 108 additions and 193 deletions.
7 changes: 2 additions & 5 deletions es/data_source_elasticsearch_opendistro_destination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ func TestAccElasticsearchDataSourceDestination_basic(t *testing.T) {
}
meta := provider.Meta()
var allowed bool
esClient, err := getClient(meta.(*ProviderConf))
if err != nil {
t.Skipf("err: %s", err)
}
switch esClient.(type) {

switch meta.(type) {
case *elastic5.Client:
allowed = false
default:
Expand Down
14 changes: 7 additions & 7 deletions es/resource_elasticsearch_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func resourceElasticsearchIndexCreate(d *schema.ResourceData, meta interface{})
}

default:
elastic5Client := meta.(*elastic5.Client)
elastic5Client := client.(*elastic5.Client)
resp, requestErr := elastic5Client.CreateIndex(name).BodyJson(body).Do(ctx)
err = requestErr
if err == nil {
Expand Down Expand Up @@ -247,7 +247,7 @@ func resourceElasticsearchIndexDelete(d *schema.ResourceData, meta interface{})
_, err = client.DeleteIndex(name).Do(ctx)

default:
elastic5Client := meta.(*elastic5.Client)
elastic5Client := client.(*elastic5.Client)
_, err = elastic5Client.DeleteIndex(name).Do(ctx)
}

Expand All @@ -274,7 +274,7 @@ func allowIndexDestroy(indexName string, d *schema.ResourceData, meta interface{
count, err = client.Count(indexName).Do(ctx)

default:
elastic5Client := meta.(*elastic5.Client)
elastic5Client := client.(*elastic5.Client)
count, err = elastic5Client.Count(indexName).Do(ctx)
}

Expand Down Expand Up @@ -328,12 +328,12 @@ func resourceElasticsearchIndexUpdate(d *schema.ResourceData, meta interface{})
_, err = client.IndexPutSettings(name).BodyJson(body).Do(ctx)

default:
elastic5Client := meta.(*elastic5.Client)
elastic5Client := client.(*elastic5.Client)
_, err = elastic5Client.IndexPutSettings(name).BodyJson(body).Do(ctx)
}

if err == nil {
return resourceElasticsearchIndexRead(d, meta)
return resourceElasticsearchIndexRead(d, meta.(*ProviderConf))
}
return err
}
Expand Down Expand Up @@ -376,7 +376,7 @@ func getWriteIndexByAlias(alias string, d *schema.ResourceData, meta interface{}
}

default:
elastic5Client := meta.(*elastic5.Client)
elastic5Client := client.(*elastic5.Client)
r, err := elastic5Client.CatAliases().Alias(alias).Columns(columns...).Do(ctx)
if err != nil {
log.Printf("[INFO] getWriteIndexByAlias: %+v", err)
Expand Down Expand Up @@ -428,7 +428,7 @@ func resourceElasticsearchIndexRead(d *schema.ResourceData, meta interface{}) er
settings = resp.Settings["index"].(map[string]interface{})
}
default:
elastic5Client := meta.(*elastic5.Client)
elastic5Client := client.(*elastic5.Client)
r, err := elastic5Client.IndexGet(index).Do(ctx)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion es/resource_elasticsearch_index_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func resourceElasticsearchIndexTemplateDelete(d *schema.ResourceData, meta inter
case *elastic6.Client:
err = elastic6IndexDeleteTemplate(client, id)
default:
elastic5Client := meta.(*elastic5.Client)
elastic5Client := client.(*elastic5.Client)
err = elastic5IndexDeleteTemplate(elastic5Client, id)
}

Expand Down
16 changes: 4 additions & 12 deletions es/resource_elasticsearch_index_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ func TestAccElasticsearchIndexTemplate(t *testing.T) {
}
meta := provider.Meta()
var config string
esClient, err := getClient(meta.(*ProviderConf))
if err != nil {
t.Skipf("err: %s", err)
}
switch esClient.(type) {
switch meta.(type) {
case *elastic7.Client:
config = testAccElasticsearchIndexTemplateV7
case *elastic6.Client:
Expand Down Expand Up @@ -59,11 +55,7 @@ func TestAccElasticsearchIndexTemplate_importBasic(t *testing.T) {
}
meta := provider.Meta()
var config string
esClient, err := getClient(meta.(*ProviderConf))
if err != nil {
t.Skipf("err: %s", err)
}
switch esClient.(type) {
switch meta.(type) {
case *elastic7.Client:
config = testAccElasticsearchIndexTemplateV7
case *elastic6.Client:
Expand Down Expand Up @@ -114,7 +106,7 @@ func testCheckElasticsearchIndexTemplateExists(name string) resource.TestCheckFu
case *elastic6.Client:
_, err = client.IndexGetTemplate(rs.Primary.ID).Do(context.TODO())
default:
elastic5Client := meta.(*elastic5.Client)
elastic5Client := client.(*elastic5.Client)
_, err = elastic5Client.IndexGetTemplate(rs.Primary.ID).Do(context.TODO())
}

Expand Down Expand Up @@ -145,7 +137,7 @@ func testCheckElasticsearchIndexTemplateDestroy(s *terraform.State) error {
case *elastic6.Client:
_, err = client.IndexGetTemplate(rs.Primary.ID).Do(context.TODO())
default:
elastic5Client := meta.(*elastic5.Client)
elastic5Client := client.(*elastic5.Client)
_, err = elastic5Client.IndexGetTemplate(rs.Primary.ID).Do(context.TODO())
}

Expand Down
30 changes: 10 additions & 20 deletions es/resource_elasticsearch_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,7 @@ func TestAccElasticsearchIndex_handleInvalid(t *testing.T) {
}
meta := provider.Meta()
var allowed bool
esClient, err := getClient(meta.(*ProviderConf))
if err != nil {
t.Skipf("err: %s", err)
}
switch esClient.(type) {
switch meta.(type) {
case *elastic5.Client:
allowed = false
default:
Expand Down Expand Up @@ -291,11 +287,8 @@ func TestAccElasticsearchIndex_rolloverAliasXpack(t *testing.T) {
}
meta := provider.Meta()
var allowed bool
esClient, err := getClient(meta.(*ProviderConf))
if err != nil {
t.Skipf("err: %s", err)
}
switch esClient.(type) {

switch meta.(type) {
case *elastic5.Client:
allowed = false
default:
Expand Down Expand Up @@ -340,11 +333,8 @@ func TestAccElasticsearchIndex_rolloverAliasOpendistro(t *testing.T) {
}
meta := provider.Meta()
var allowed bool
esClient, err := getClient(meta.(*ProviderConf))
if err != nil {
t.Skipf("err: %s", err)
}
switch esClient.(type) {

switch meta.(type) {
case *elastic6.Client:
allowed = false
case *elastic5.Client:
Expand Down Expand Up @@ -406,7 +396,7 @@ func checkElasticsearchIndexExists(name string) resource.TestCheckFunc {
case *elastic6.Client:
_, err = client.IndexGetSettings(rs.Primary.ID).Do(context.TODO())
default:
elastic5Client := meta.(*elastic5.Client)
elastic5Client := client.(*elastic5.Client)
_, err = elastic5Client.IndexGetSettings(rs.Primary.ID).Do(context.TODO())
}

Expand Down Expand Up @@ -448,7 +438,7 @@ func checkElasticsearchIndexUpdated(name string) resource.TestCheckFunc {
settings = resp[rs.Primary.ID].Settings["index"].(map[string]interface{})

default:
elastic5Client := meta.(*elastic5.Client)
elastic5Client := client.(*elastic5.Client)
resp, err := elastic5Client.IndexGetSettings(rs.Primary.ID).Do(context.TODO())
if err != nil {
return err
Expand Down Expand Up @@ -488,7 +478,7 @@ func checkElasticsearchIndexDestroy(s *terraform.State) error {
case *elastic6.Client:
_, err = client.IndexGetSettings(rs.Primary.ID).Do(context.TODO())
default:
elastic5Client := meta.(*elastic5.Client)
elastic5Client := client.(*elastic5.Client)
_, err = elastic5Client.IndexGetSettings(rs.Primary.ID).Do(context.TODO())
}

Expand Down Expand Up @@ -525,7 +515,7 @@ func checkElasticsearchIndexRolloverAliasExists(provider *schema.Provider, alias
}
count = len(r)
default:
elastic5Client := meta.(*elastic5.Client)
elastic5Client := client.(*elastic5.Client)
r, err := elastic5Client.CatAliases().Alias(alias).Do(context.TODO())
if err != nil {
return err
Expand Down Expand Up @@ -578,7 +568,7 @@ func checkElasticsearchIndexRolloverAliasDestroy(provider *schema.Provider, alia
}
count = len(r)
default:
elastic5Client := meta.(*elastic5.Client)
elastic5Client := client.(*elastic5.Client)
r, err := elastic5Client.CatAliases().Alias(alias).Do(context.TODO())
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions es/resource_elasticsearch_ingest_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func resourceElasticsearchIngestPipelineRead(d *schema.ResourceData, meta interf
case *elastic6.Client:
result, err = elastic6IngestGetPipeline(client, id)
default:
elastic5Client := meta.(*elastic5.Client)
elastic5Client := client.(*elastic5.Client)
result, err = elastic5IngestGetPipeline(elastic5Client, id)
}
if err != nil {
Expand Down Expand Up @@ -138,7 +138,7 @@ func resourceElasticsearchIngestPipelineDelete(d *schema.ResourceData, meta inte
case *elastic6.Client:
_, err = client.IngestDeletePipeline(id).Do(context.TODO())
default:
elastic5Client := meta.(*elastic5.Client)
elastic5Client := client.(*elastic5.Client)
_, err = elastic5Client.IngestDeletePipeline(id).Do(context.TODO())
}

Expand All @@ -164,7 +164,7 @@ func resourceElasticsearchPutIngestPipeline(d *schema.ResourceData, meta interfa
case *elastic6.Client:
_, err = client.IngestPutPipeline(name).BodyString(body).Do(context.TODO())
default:
elastic5Client := meta.(*elastic5.Client)
elastic5Client := client.(*elastic5.Client)
_, err = elastic5Client.IngestPutPipeline(name).BodyString(body).Do(context.TODO())
}

Expand Down
17 changes: 5 additions & 12 deletions es/resource_elasticsearch_ingest_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ func TestAccElasticsearchIngestPipeline(t *testing.T) {
}
meta := provider.Meta()
var config string
esClient, err := getClient(meta.(*ProviderConf))
if err != nil {
t.Skipf("err: %s", err)
}
switch esClient.(type) {

switch meta.(type) {
case *elastic7.Client:
config = testAccElasticsearchIngestPipelineV7
case *elastic6.Client:
Expand Down Expand Up @@ -59,11 +56,7 @@ func TestAccElasticsearchIngestPipeline_importBasic(t *testing.T) {
}
meta := provider.Meta()
var config string
esClient, err := getClient(meta.(*ProviderConf))
if err != nil {
t.Skipf("err: %s", err)
}
switch esClient.(type) {
switch meta.(type) {
case *elastic7.Client:
config = testAccElasticsearchIngestPipelineV7
case *elastic6.Client:
Expand Down Expand Up @@ -114,7 +107,7 @@ func testCheckElasticsearchIngestPipelineExists(name string) resource.TestCheckF
case *elastic6.Client:
_, err = client.IngestGetPipeline(rs.Primary.ID).Do(context.TODO())
default:
elastic5Client := meta.(*elastic5.Client)
elastic5Client := client.(*elastic5.Client)
_, err = elastic5Client.IngestGetPipeline(rs.Primary.ID).Do(context.TODO())
}

Expand Down Expand Up @@ -145,7 +138,7 @@ func testCheckElasticsearchIngestPipelineDestroy(s *terraform.State) error {
case *elastic6.Client:
_, err = client.IngestGetPipeline(rs.Primary.ID).Do(context.TODO())
default:
elastic5Client := meta.(*elastic5.Client)
elastic5Client := client.(*elastic5.Client)
_, err = elastic5Client.IngestGetPipeline(rs.Primary.ID).Do(context.TODO())
}

Expand Down
8 changes: 4 additions & 4 deletions es/resource_elasticsearch_kibana_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func resourceElasticsearchKibanaObjectCreate(d *schema.ResourceData, meta interf
case *elastic6.Client:
success, err = elastic6CreateIndexIfNotExists(client, index, mapping_index)
default:
elastic5Client := meta.(*elastic5.Client)
elastic5Client := client.(*elastic5.Client)
success, err = elastic5CreateIndexIfNotExists(elastic5Client, index, mapping_index)
}

Expand Down Expand Up @@ -213,7 +213,7 @@ func resourceElasticsearchKibanaObjectRead(d *schema.ResourceData, meta interfac
case *elastic6.Client:
result, err = elastic6GetObject(client, objectType, index, id)
default:
elastic5Client := meta.(*elastic5.Client)
elastic5Client := client.(*elastic5.Client)
result, err = elastic5GetObject(elastic5Client, objectType, index, id)
}

Expand Down Expand Up @@ -262,7 +262,7 @@ func resourceElasticsearchKibanaObjectDelete(d *schema.ResourceData, meta interf
case *elastic6.Client:
err = elastic6DeleteIndex(client, objectType, index, id)
default:
elastic5Client := meta.(*elastic5.Client)
elastic5Client := client.(*elastic5.Client)
err = elastic5DeleteIndex(elastic5Client, objectType, index, id)
}

Expand Down Expand Up @@ -329,7 +329,7 @@ func resourceElasticsearchPutKibanaObject(d *schema.ResourceData, meta interface
case *elastic6.Client:
err = elastic6PutIndex(client, objectType, index, id, data)
default:
elastic5Client := meta.(*elastic5.Client)
elastic5Client := client.(*elastic5.Client)
err = elastic5PutIndex(elastic5Client, objectType, index, id, data)
}

Expand Down
18 changes: 6 additions & 12 deletions es/resource_elasticsearch_kibana_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ func TestAccElasticsearchKibanaObject(t *testing.T) {
var visualizationConfig string
var indexPatternConfig string
meta := testAccProvider.Meta()
esClient, err := getClient(meta.(*ProviderConf))
if err != nil {
t.Skipf("err: %s", err)
}
switch esClient.(type) {

switch meta.(type) {
case *elastic7.Client:
visualizationConfig = testAccElasticsearch7KibanaVisualization
indexPatternConfig = testAccElasticsearch7KibanaIndexPattern
Expand Down Expand Up @@ -90,11 +87,8 @@ func TestAccElasticsearchKibanaObject_Rejected(t *testing.T) {
}
meta := provider.Meta()
var allowed bool
esClient, err := getClient(meta.(*ProviderConf))
if err != nil {
t.Skipf("err: %s", err)
}
switch esClient.(type) {

switch meta.(type) {
case *elastic6.Client:
allowed = true
default:
Expand Down Expand Up @@ -142,7 +136,7 @@ func testCheckElasticsearchKibanaObjectExists(name string, objectType string, id
case *elastic6.Client:
_, err = client.Get().Index(".kibana").Type(deprecatedDocType).Id(id).Do(context.TODO())
default:
elastic5Client := meta.(*elastic5.Client)
elastic5Client := client.(*elastic5.Client)
_, err = elastic5Client.Get().Index(".kibana").Type(objectType).Id(id).Do(context.TODO())
}

Expand Down Expand Up @@ -174,7 +168,7 @@ func testCheckElasticsearchKibanaObjectDestroy(s *terraform.State) error {
case *elastic6.Client:
_, err = client.Get().Index(".kibana").Type("visualization").Id("response-time-percentile").Do(context.TODO())
default:
elastic5Client := meta.(*elastic5.Client)
elastic5Client := client.(*elastic5.Client)
_, err = elastic5Client.Get().Index(".kibana").Type("visualization").Id("response-time-percentile").Do(context.TODO())
}

Expand Down
14 changes: 4 additions & 10 deletions es/resource_elasticsearch_opendistro_destination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ func TestAccElasticsearchOpenDistroDestination(t *testing.T) {
}
meta := provider.Meta()
var allowed bool
esClient, err := getClient(meta.(*ProviderConf))
if err != nil {
t.Skipf("err: %s", err)
}
switch esClient.(type) {

switch meta.(type) {
case *elastic5.Client:
allowed = false
default:
Expand Down Expand Up @@ -60,11 +57,8 @@ func TestAccElasticsearchOpenDistroDestination_importBasic(t *testing.T) {
}
meta := provider.Meta()
var allowed bool
esClient, err := getClient(meta.(*ProviderConf))
if err != nil {
t.Skipf("err: %s", err)
}
switch esClient.(type) {

switch meta.(type) {
case *elastic5.Client:
allowed = false
default:
Expand Down
Loading

0 comments on commit d5e0b35

Please sign in to comment.