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
Allowing single word resources to use templates #147
Changes from 4 commits
b4b63ec
9377652
27bf553
b0001a4
d6cc333
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package provider | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
tfjson "github.com/hashicorp/terraform-json" | ||
) | ||
|
||
func Test_resourceSchema(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
schemas map[string]*tfjson.Schema | ||
providerShortName string | ||
templateFileName string | ||
expectedSchema *tfjson.Schema | ||
expectedResourceName string | ||
}{ | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add another case where you have a resource named (just for kicks) I say this because the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @detro you mean along the lines of: {
"provider short name different from template file name",
"https",
"http.md.tmpl",
"https_http",
}, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
What I'm expecting is that this test would fail, because the provider name is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @detro I've refactored following discussion. |
||
"provider short name matches schema name", | ||
map[string]*tfjson.Schema{ | ||
"http": {}, | ||
}, | ||
"http", | ||
"http.md.tmpl", | ||
&tfjson.Schema{}, | ||
"http", | ||
}, | ||
{ | ||
"provider short name does not match schema name", | ||
map[string]*tfjson.Schema{ | ||
"http": {}, | ||
}, | ||
"tls", | ||
"http.md.tmpl", | ||
nil, | ||
"", | ||
}, | ||
{ | ||
"provider short name concatenated with template file name matches schema name", | ||
map[string]*tfjson.Schema{ | ||
"tls_cert_request": {}, | ||
}, | ||
"tls", | ||
"cert_request.md.tmpl", | ||
&tfjson.Schema{}, | ||
"tls_cert_request", | ||
}, | ||
{ | ||
"provider short name concatenated with template file name does not match schema name", | ||
map[string]*tfjson.Schema{ | ||
"tls_cert_request": {}, | ||
}, | ||
"tls", | ||
"not_found.md.tmpl", | ||
nil, | ||
"", | ||
}, | ||
{ | ||
"provider short name concatenated with same template file name matches schema name", | ||
map[string]*tfjson.Schema{ | ||
"tls_tls": {}, | ||
}, | ||
"tls", | ||
"tls.md.tmpl", | ||
&tfjson.Schema{}, | ||
"tls_tls", | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: While Go allows you to omit field names, I personally find it a little more difficult to read the structs once the struct definition is "beyond the fold" since its based on ordering. e.g. my brain is like what is the 3rd field defined as "tls" here? I have to scroll up, see providerShortName, scroll back down There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
for _, c := range cases { | ||
t.Run(c.name, func(t *testing.T) { | ||
actualSchema, actualResourceName := resourceSchema(c.schemas, c.providerShortName, c.templateFileName) | ||
|
||
if !cmp.Equal(c.expectedSchema, actualSchema) { | ||
t.Errorf("expected: %+v, got: %+v", c.expectedSchema, actualSchema) | ||
} | ||
|
||
if !cmp.Equal(c.expectedResourceName, actualResourceName) { | ||
t.Errorf("expected: %s, got: %s", c.expectedResourceName, actualResourceName) | ||
} | ||
}) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
those are definitely typos I made 🤦
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries. I like that we're keeping an eye out for each other 👍