Skip to content

Commit

Permalink
feat: Added code generation for new provider functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
skyzyx committed Oct 15, 2023
1 parent e78d887 commit 6433e19
Show file tree
Hide file tree
Showing 24 changed files with 738 additions and 83 deletions.
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,11 @@ issues:
- gochecknoinits
source: lint:allow_init

- text: (cuddle)
linters:
- wsl
source: lint:allow_cuddle

# Independently from option `exclude` we use default exclude patterns, it can be disabled by this
# option. To list all excluded by default patterns execute `golangci-lint run --help`. Default
# value for this option is true.
Expand Down
12 changes: 12 additions & 0 deletions bats/env_ensure.bats.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bats
# https://bats-core.readthedocs.io/en/stable/writing-tests.html

@test "corefunc_env_ensure: attrs" {
run bash -c "tfschema data show -format=json corefunc_env_ensure | jq -Mrc '.attributes[]'"

[ "$status" -eq 0 ]
[[ ${lines[0]} == '{"name":"id","type":"number","required":false,"optional":false,"computed":true,"sensitive":false}' ]]
[[ ${lines[1]} == '{"name":"name","type":"string","required":true,"optional":false,"computed":false,"sensitive":false}' ]]
[[ ${lines[2]} == '{"name":"pattern","type":"string","required":false,"optional":true,"computed":false,"sensitive":false}' ]]
[[ ${lines[3]} == '{"name":"value","type":"string","required":false,"optional":false,"computed":true,"sensitive":false}' ]]
}
11 changes: 11 additions & 0 deletions bats/str_camel.bats.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bats
# https://bats-core.readthedocs.io/en/stable/writing-tests.html

@test "corefunc_str_camel: attrs" {
run bash -c "tfschema data show -format=json corefunc_str_camel | jq -Mrc '.attributes[]'"

[ "$status" -eq 0 ]
[[ ${lines[0]} == '{"name":"id","type":"number","required":false,"optional":false,"computed":true,"sensitive":false}' ]]
[[ ${lines[1]} == '{"name":"string","type":"string","required":true,"optional":false,"computed":false,"sensitive":false}' ]]
[[ ${lines[2]} == '{"name":"value","type":"string","required":false,"optional":false,"computed":true,"sensitive":false}' ]]
}
11 changes: 11 additions & 0 deletions bats/str_constant.bats.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bats
# https://bats-core.readthedocs.io/en/stable/writing-tests.html

@test "corefunc_str_constant: attrs" {
run bash -c "tfschema data show -format=json corefunc_str_constant | jq -Mrc '.attributes[]'"

[ "$status" -eq 0 ]
[[ ${lines[0]} == '{"name":"id","type":"number","required":false,"optional":false,"computed":true,"sensitive":false}' ]]
[[ ${lines[1]} == '{"name":"string","type":"string","required":true,"optional":false,"computed":false,"sensitive":false}' ]]
[[ ${lines[2]} == '{"name":"value","type":"string","required":false,"optional":false,"computed":true,"sensitive":false}' ]]
}
11 changes: 11 additions & 0 deletions bats/str_kebab.bats.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bats
# https://bats-core.readthedocs.io/en/stable/writing-tests.html

@test "corefunc_str_kebab: attrs" {
run bash -c "tfschema data show -format=json corefunc_str_kebab | jq -Mrc '.attributes[]'"

[ "$status" -eq 0 ]
[[ ${lines[0]} == '{"name":"id","type":"number","required":false,"optional":false,"computed":true,"sensitive":false}' ]]
[[ ${lines[1]} == '{"name":"string","type":"string","required":true,"optional":false,"computed":false,"sensitive":false}' ]]
[[ ${lines[2]} == '{"name":"value","type":"string","required":false,"optional":false,"computed":true,"sensitive":false}' ]]
}
12 changes: 12 additions & 0 deletions bats/str_pascal.bats.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bats
# https://bats-core.readthedocs.io/en/stable/writing-tests.html

@test "corefunc_str_pascal: attrs" {
run bash -c "tfschema data show -format=json corefunc_str_pascal | jq -Mrc '.attributes[]'"

[ "$status" -eq 0 ]
[[ ${lines[0]} == '{"name":"acronym_caps","type":"bool","required":false,"optional":true,"computed":false,"sensitive":false}' ]]
[[ ${lines[1]} == '{"name":"id","type":"number","required":false,"optional":false,"computed":true,"sensitive":false}' ]]
[[ ${lines[2]} == '{"name":"string","type":"string","required":true,"optional":false,"computed":false,"sensitive":false}' ]]
[[ ${lines[3]} == '{"name":"value","type":"string","required":false,"optional":false,"computed":true,"sensitive":false}' ]]
}
11 changes: 11 additions & 0 deletions bats/str_snake.bats.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bats
# https://bats-core.readthedocs.io/en/stable/writing-tests.html

@test "corefunc_str_snake: attrs" {
run bash -c "tfschema data show -format=json corefunc_str_snake | jq -Mrc '.attributes[]'"

[ "$status" -eq 0 ]
[[ ${lines[0]} == '{"name":"id","type":"number","required":false,"optional":false,"computed":true,"sensitive":false}' ]]
[[ ${lines[1]} == '{"name":"string","type":"string","required":true,"optional":false,"computed":false,"sensitive":false}' ]]
[[ ${lines[2]} == '{"name":"value","type":"string","required":false,"optional":false,"computed":true,"sensitive":false}' ]]
}
13 changes: 13 additions & 0 deletions bats/str_truncate_label.bats.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bats
# https://bats-core.readthedocs.io/en/stable/writing-tests.html

@test "corefunc_str_truncate_label: attrs" {
run bash -c "tfschema data show -format=json corefunc_str_truncate_label | jq -Mrc '.attributes[]'"

[ "$status" -eq 0 ]
[[ ${lines[0]} == '{"name":"id","type":"number","required":false,"optional":false,"computed":true,"sensitive":false}' ]]
[[ ${lines[1]} == '{"name":"label","type":"string","required":true,"optional":false,"computed":false,"sensitive":false}' ]]
[[ ${lines[2]} == '{"name":"max_length","type":"number","required":false,"optional":true,"computed":false,"sensitive":false}' ]]
[[ ${lines[3]} == '{"name":"prefix","type":"string","required":true,"optional":false,"computed":false,"sensitive":false}' ]]
[[ ${lines[4]} == '{"name":"value","type":"string","required":false,"optional":false,"computed":true,"sensitive":false}' ]]
}
83 changes: 0 additions & 83 deletions bats/tfschema.bats.sh

This file was deleted.

16 changes: 16 additions & 0 deletions bats/tfschema_listing.bats.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bats
# https://bats-core.readthedocs.io/en/stable/writing-tests.html

@test "listing the data sources" {
run tfschema data list corefunc

[ "$status" -eq 0 ]
[[ ${lines[0]} == "corefunc_env_ensure" ]]
[[ ${lines[1]} == "corefunc_str_camel" ]]
[[ ${lines[2]} == "corefunc_str_constant" ]]
[[ ${lines[3]} == "corefunc_str_kebab" ]]
[[ ${lines[4]} == "corefunc_str_pascal" ]]
[[ ${lines[5]} == "corefunc_str_snake" ]]
[[ ${lines[6]} == "corefunc_str_truncate_label" ]]

}
33 changes: 33 additions & 0 deletions generator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Stub Generator

## Generator

This will accept a name, then generate the correct files needed to implement the provider functionality.

The name should match what the Terraform data source will be called (e.g., `corefunc_example`).

From this `generator/` directory, run the command.

```bash
go run main.go --name corefunc_example
```

After that, search the project for `@TODO` and make the appropriate changes. Exclude `./generator,*.md,.*.yml`.

## Checklist

* [ ] Generate the stub files.
* [ ] In the new `*_data_source.go` file, update the `*SourceModel` struct.
* [ ] In the new `*_data_source.go` file, update the Schema Attributes to match the `*SourceModel` struct.
* [ ] In the new `*_data_source.go` file, implement the remainder of the `Read` function.
* [ ] In the new test fixture file, implement the test cases.
* [ ] In the new `*_data_source_fixture.tftpl` file, ensure the fixture is implemented correctly.
* [ ] In the new `*_data_source_test.go` file, ensure the test references the fixture correctly.
* [ ] Run the integration tests.
* [ ] In the new `examples/data-sources/*/data-source.tf` file, ensure the example is implemented correctly.
* [ ] In the new `examples/data-sources/*/terraform-plan.example` file, copy content or delete.
* [ ] In the new `templates/data-sources/*.tmpl` file, update the template that will be used by the `tfplugindocs` package.
* [ ] Generate the Terraform provider documentation.
* [ ] Run `tfschema data show -format=json DATASOURCE | jq -Mrc '.attributes[]'`.
* [ ] In the new `bats/*.bats.sh` file, update its contents to match the `tfschema` output.
* [ ] Run the bats tests.
9 changes: 9 additions & 0 deletions generator/bats/test.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bats
# https://bats-core.readthedocs.io/en/stable/writing-tests.html

@test "{{ .Snake }}: attrs" {
run bash -c "tfschema data show -format=json {{ .Snake }} | jq -Mrc '.attributes[]'"

[ "$status" -eq 0 ]
[[ ${lines[0]} == '@TODO' ]]
}
Loading

0 comments on commit 6433e19

Please sign in to comment.