Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix composable_index_template + tests #123

Merged
merged 1 commit into from
Dec 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions es/resource_elasticsearch_composable_index_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ func resourceElasticsearchComposableIndexTemplateRead(d *schema.ResourceData, me
id := d.Id()

var result, version string
var err error
switch client := meta.(type) {

esClient, err := getClient(meta.(*ProviderConf))
if err != nil {
return err
}

switch client := esClient.(type) {
case *elastic7.Client:
version, err = elastic7GetVersion(client)
if err == nil {
Expand Down Expand Up @@ -103,8 +108,13 @@ func resourceElasticsearchComposableIndexTemplateDelete(d *schema.ResourceData,
id := d.Id()

var version string
var err error
switch client := meta.(type) {

esClient, err := getClient(meta.(*ProviderConf))
if err != nil {
return err
}

switch client := esClient.(type) {
case *elastic7.Client:
version, err = elastic7GetVersion(client)
if err == nil {
Expand Down Expand Up @@ -134,8 +144,12 @@ func resourceElasticsearchPutComposableIndexTemplate(d *schema.ResourceData, met
name := d.Get("name").(string)
body := d.Get("body").(string)

var err error
switch client := meta.(type) {
esClient, err := getClient(meta.(*ProviderConf))
if err != nil {
return err
}

switch client := esClient.(type) {
case *elastic7.Client:
err = elastic7PutIndexTemplate(client, name, body, create)
default:
Expand Down
32 changes: 26 additions & 6 deletions es/resource_elasticsearch_composable_index_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ func TestAccElasticsearchComposableIndexTemplate(t *testing.T) {
t.Skipf("err: %s", err)
}
meta := provider.Meta()

esClient, err := getClient(meta.(*ProviderConf))
if err != nil {
t.Skipf("err: %s", err)
}

var allowed bool
switch meta.(type) {
switch esClient.(type) {
case *elastic7.Client:
allowed = true
default:
Expand Down Expand Up @@ -54,8 +60,14 @@ func TestAccElasticsearchComposableIndexTemplate_importBasic(t *testing.T) {
t.Skipf("err: %s", err)
}
meta := provider.Meta()

esClient, err := getClient(meta.(*ProviderConf))
if err != nil {
t.Skipf("err: %s", err)
}

var allowed bool
switch meta.(type) {
switch esClient.(type) {
case *elastic7.Client:
allowed = true
default:
Expand Down Expand Up @@ -95,8 +107,12 @@ func testCheckElasticsearchComposableIndexTemplateExists(name string) resource.T

meta := testAccProvider.Meta()

var err error
switch client := meta.(type) {
esClient, err := getClient(meta.(*ProviderConf))
if err != nil {
return err
}

switch client := esClient.(type) {
case *elastic7.Client:
_, err = client.IndexGetIndexTemplate(rs.Primary.ID).Do(context.TODO())
default:
Expand All @@ -119,8 +135,12 @@ func testCheckElasticsearchComposableIndexTemplateDestroy(s *terraform.State) er

meta := testAccProvider.Meta()

var err error
switch client := meta.(type) {
esClient, err := getClient(meta.(*ProviderConf))
if err != nil {
return err
}

switch client := esClient.(type) {
case *elastic7.Client:
_, err = client.IndexGetTemplate(rs.Primary.ID).Do(context.TODO())
default:
Expand Down