-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allowing single word resources to use templates (#147)
* Allowing single word resources to use templates * Updating CHANGELOG.md * Add unit test for resourceName * Returning error if resource not found * Adding field names to test structs
- Loading branch information
1 parent
ed20132
commit cbd432b
Showing
5 changed files
with
134 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package provider | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
tfjson "github.com/hashicorp/terraform-json" | ||
) | ||
|
||
func Test_resourceSchema(t *testing.T) { | ||
cases := map[string]struct { | ||
schemas map[string]*tfjson.Schema | ||
providerShortName string | ||
templateFileName string | ||
expectedSchema *tfjson.Schema | ||
expectedResourceName string | ||
}{ | ||
"provider short name matches schema name": { | ||
schemas: map[string]*tfjson.Schema{ | ||
"http": {}, | ||
}, | ||
providerShortName: "http", | ||
templateFileName: "http.md.tmpl", | ||
expectedSchema: &tfjson.Schema{}, | ||
expectedResourceName: "http", | ||
}, | ||
"provider short name does not match schema name": { | ||
schemas: map[string]*tfjson.Schema{ | ||
"http": {}, | ||
}, | ||
providerShortName: "tls", | ||
templateFileName: "http.md.tmpl", | ||
expectedSchema: nil, | ||
expectedResourceName: "", | ||
}, | ||
"provider short name concatenated with template file name matches schema name": { | ||
schemas: map[string]*tfjson.Schema{ | ||
"tls_cert_request": {}, | ||
}, | ||
providerShortName: "tls", | ||
templateFileName: "cert_request.md.tmpl", | ||
expectedSchema: &tfjson.Schema{}, | ||
expectedResourceName: "tls_cert_request", | ||
}, | ||
"provider short name concatenated with template file name does not match schema name": { | ||
schemas: map[string]*tfjson.Schema{ | ||
"tls_cert_request": {}, | ||
}, | ||
providerShortName: "tls", | ||
templateFileName: "not_found.md.tmpl", | ||
expectedSchema: nil, | ||
expectedResourceName: "", | ||
}, | ||
"provider short name concatenated with same template file name matches schema name": { | ||
schemas: map[string]*tfjson.Schema{ | ||
"tls_tls": {}, | ||
}, | ||
providerShortName: "tls", | ||
templateFileName: "tls.md.tmpl", | ||
expectedSchema: &tfjson.Schema{}, | ||
expectedResourceName: "tls_tls", | ||
}, | ||
} | ||
|
||
for name, c := range cases { | ||
t.Run(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) | ||
} | ||
}) | ||
} | ||
} |