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

Conversation

blamarvt
Copy link
Contributor

The composable index_template code was attempting to type switch on
meta instead of the result of getClient. Since meta is not a
client, but rather a ProviderConf this caused the 'default' case of
the type switch to run which made the tests skip and not fail.

Real World Output

Error: index_template endpoint only available from ElasticSearch >= 7.8, got version < 7.0.0 (*es.ProviderConf)

Test Output Before PR

$ TF_ACC=1 go test ./... -v -run TestAccElasticsearchComposableIndexTemplate
?   	github.com/phillbaker/terraform-provider-elasticsearch	[no test files]
=== RUN   TestAccElasticsearchComposableIndexTemplate
    TestAccElasticsearchComposableIndexTemplate: resource_elasticsearch_composable_index_template_test.go:34: /_index_template endpoint only supported on ES >= 7.8
--- SKIP: TestAccElasticsearchComposableIndexTemplate (0.00s)
=== RUN   TestAccElasticsearchComposableIndexTemplate_importBasic
    TestAccElasticsearchComposableIndexTemplate_importBasic: resource_elasticsearch_composable_index_template_test.go:68: /_index_template endpoint only supported on ES >= 7.8
--- SKIP: TestAccElasticsearchComposableIndexTemplate_importBasic (0.00s)
PASS
ok  	github.com/phillbaker/terraform-provider-elasticsearch/es	0.065s

Test Output After PR

$ TF_ACC=1 go test ./... -v -run TestAccElasticsearchComposableIndexTemplate 2>/dev/null
?   	github.com/phillbaker/terraform-provider-elasticsearch	[no test files]
=== RUN   TestAccElasticsearchComposableIndexTemplate
2020/12/23 19:50:36 [INFO] Pinging url to determine version http://127.0.0.1:9200
2020/12/23 19:50:36 [INFO] terraform: building graph: GraphTypeValidate
2020/12/23 19:50:36 [INFO] terraform: building graph: GraphTypeRefresh
2020/12/23 19:50:36 [INFO] terraform: building graph: GraphTypePlan
2020/12/23 19:50:36 [WARN] Test: Step plan: DIFF:

CREATE: elasticsearch_composable_index_template.test
  body: "" => "{\n  \"index_patterns\": [\"te*\", \"bar*\"],\n  \"template\": {\n    \"settings\": {\n      \"index\": {\n        \"number_of_shards\": 1\n      }\n    },\n    \"mappings\": {\n      \"properties\": {\n        \"host_name\": {\n          \"type\": \"keyword\"\n        },\n        \"created_at\": {\n          \"type\": \"date\",\n          \"format\": \"EEE MMM dd HH:mm:ss Z yyyy\"\n        }\n      }\n    },\n    \"aliases\": {\n      \"mydata\": { }\n    }\n  },\n  \"priority\": 200,\n  \"version\": 3\n}\n"
  id:   "" => "<computed>"
  name: "" => "terraform-test"



STATE:

<no state>
2020/12/23 19:50:36 [INFO] terraform: building graph: GraphTypeApply
2020/12/23 19:50:36 [INFO] Pinging url to determine version http://127.0.0.1:9200
2020/12/23 19:50:36 [INFO] terraform: building graph: GraphTypePlan
2020/12/23 19:50:36 [INFO] terraform: building graph: GraphTypeRefresh
2020/12/23 19:50:36 [INFO] Pinging url to determine version http://127.0.0.1:9200
2020/12/23 19:50:36 [INFO] terraform: building graph: GraphTypePlan
2020/12/23 19:50:36 [WARN] Test: Executing destroy step
2020/12/23 19:50:36 [INFO] terraform: building graph: GraphTypeValidate
2020/12/23 19:50:36 [INFO] terraform: building graph: GraphTypeRefresh
2020/12/23 19:50:37 [INFO] Pinging url to determine version http://127.0.0.1:9200
2020/12/23 19:50:37 [INFO] terraform: building graph: GraphTypePlanDestroy
2020/12/23 19:50:37 [WARN] Test: Step plan: DIFF:

DESTROY: elasticsearch_composable_index_template.test
  body: "{\"index_patterns\":[\"te*\",\"bar*\"],\"priority\":200,\"version\":3,\"template\":{\"settings\":{\"index\":{\"number_of_shards\":\"1\"}},\"mappings\":{\"properties\":{\"created_at\":{\"format\":\"EEE MMM dd HH:mm:ss Z yyyy\",\"type\":\"date\"},\"host_name\":{\"type\":\"keyword\"}}},\"aliases\":{\"mydata\":{}}}}" => ""
  id:   "terraform-test" => ""
  name: "terraform-test" => ""



STATE:

elasticsearch_composable_index_template.test:
  ID = terraform-test
  provider = provider.elasticsearch
  body = {"index_patterns":["te*","bar*"],"priority":200,"version":3,"template":{"settings":{"index":{"number_of_shards":"1"}},"mappings":{"properties":{"created_at":{"format":"EEE MMM dd HH:mm:ss Z yyyy","type":"date"},"host_name":{"type":"keyword"}}},"aliases":{"mydata":{}}}}
  name = terraform-test
2020/12/23 19:50:37 [INFO] terraform: building graph: GraphTypeApply
2020/12/23 19:50:37 DestroyEdgeTransformer: pruning unused resource node elasticsearch_composable_index_template.test (prepare state)
2020/12/23 19:50:37 [INFO] Pinging url to determine version http://127.0.0.1:9200
2020/12/23 19:50:37 [INFO] terraform: building graph: GraphTypePlanDestroy
2020/12/23 19:50:37 [INFO] terraform: building graph: GraphTypeRefresh
2020/12/23 19:50:37 [INFO] terraform: building graph: GraphTypePlanDestroy
--- PASS: TestAccElasticsearchComposableIndexTemplate (0.28s)
=== RUN   TestAccElasticsearchComposableIndexTemplate_importBasic
2020/12/23 19:50:37 [INFO] Pinging url to determine version http://127.0.0.1:9200
2020/12/23 19:50:37 [INFO] terraform: building graph: GraphTypeValidate
2020/12/23 19:50:37 [INFO] terraform: building graph: GraphTypeRefresh
2020/12/23 19:50:37 [INFO] terraform: building graph: GraphTypePlan
2020/12/23 19:50:37 [WARN] Test: Step plan: DIFF:

CREATE: elasticsearch_composable_index_template.test
  body: "" => "{\n  \"index_patterns\": [\"te*\", \"bar*\"],\n  \"template\": {\n    \"settings\": {\n      \"index\": {\n        \"number_of_shards\": 1\n      }\n    },\n    \"mappings\": {\n      \"properties\": {\n        \"host_name\": {\n          \"type\": \"keyword\"\n        },\n        \"created_at\": {\n          \"type\": \"date\",\n          \"format\": \"EEE MMM dd HH:mm:ss Z yyyy\"\n        }\n      }\n    },\n    \"aliases\": {\n      \"mydata\": { }\n    }\n  },\n  \"priority\": 200,\n  \"version\": 3\n}\n"
  id:   "" => "<computed>"
  name: "" => "terraform-test"



STATE:

<no state>
2020/12/23 19:50:37 [INFO] terraform: building graph: GraphTypeApply
2020/12/23 19:50:37 [INFO] Pinging url to determine version http://127.0.0.1:9200
2020/12/23 19:50:37 [INFO] terraform: building graph: GraphTypePlan
2020/12/23 19:50:37 [INFO] terraform: building graph: GraphTypeRefresh
2020/12/23 19:50:37 [INFO] Pinging url to determine version http://127.0.0.1:9200
2020/12/23 19:50:37 [INFO] terraform: building graph: GraphTypePlan
2020/12/23 19:50:37 [INFO] Pinging url to determine version http://127.0.0.1:9200
2020/12/23 19:50:37 [WARN] Test: Executing destroy step
2020/12/23 19:50:37 [INFO] terraform: building graph: GraphTypeValidate
2020/12/23 19:50:37 [WARN] Not fixing up EachModes for elasticsearch_composable_index_template.test because it has no config
2020/12/23 19:50:37 [INFO] terraform: building graph: GraphTypeRefresh
2020/12/23 19:50:37 [INFO] Pinging url to determine version http://127.0.0.1:9200
2020/12/23 19:50:37 [INFO] terraform: building graph: GraphTypePlanDestroy
2020/12/23 19:50:37 [WARN] Test: Step plan: DIFF:

DESTROY: elasticsearch_composable_index_template.test
  body: "{\"index_patterns\":[\"te*\",\"bar*\"],\"priority\":200,\"version\":3,\"template\":{\"settings\":{\"index\":{\"number_of_shards\":\"1\"}},\"mappings\":{\"properties\":{\"created_at\":{\"format\":\"EEE MMM dd HH:mm:ss Z yyyy\",\"type\":\"date\"},\"host_name\":{\"type\":\"keyword\"}}},\"aliases\":{\"mydata\":{}}}}" => ""
  id:   "terraform-test" => ""
  name: "terraform-test" => ""



STATE:

elasticsearch_composable_index_template.test:
  ID = terraform-test
  provider = provider.elasticsearch
  body = {"index_patterns":["te*","bar*"],"priority":200,"version":3,"template":{"settings":{"index":{"number_of_shards":"1"}},"mappings":{"properties":{"created_at":{"format":"EEE MMM dd HH:mm:ss Z yyyy","type":"date"},"host_name":{"type":"keyword"}}},"aliases":{"mydata":{}}}}
  name = terraform-test
2020/12/23 19:50:37 [INFO] terraform: building graph: GraphTypeApply
2020/12/23 19:50:37 [INFO] Pinging url to determine version http://127.0.0.1:9200
2020/12/23 19:50:37 [INFO] terraform: building graph: GraphTypePlanDestroy
2020/12/23 19:50:37 [INFO] terraform: building graph: GraphTypeRefresh
2020/12/23 19:50:37 [INFO] terraform: building graph: GraphTypePlanDestroy
--- PASS: TestAccElasticsearchComposableIndexTemplate_importBasic (0.32s)
PASS
ok  	github.com/phillbaker/terraform-provider-elasticsearch/es	(cached)

The composable index_template code was attempting to type switch on
`meta` instead of the result of `getClient`. Since `meta` is not a
client, but rather a `ProviderConf` this caused the 'default' case of
the type switch to run which made the tests skip and not fail.
@phillbaker
Copy link
Owner

Thanks! Missed this when updating #120

@phillbaker phillbaker merged commit 0e9d427 into phillbaker:master Dec 24, 2020
@blamarvt blamarvt deleted the composable_index branch December 24, 2020 17:42
@blamarvt
Copy link
Contributor Author

Thanks for the merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants