hashicorp / terraform-plugin-codegen-openapi

OpenAPI to Terraform Provider Code Generation Specification
Mozilla Public License 2.0
50 stars 9 forks source link

Added some e2e tests for existing examples, GitHub, Scaleway, and Petstore #3

Closed austinvalle closed 1 year ago

austinvalle commented 1 year ago

I didn't add the functionality for "updating" the golden files as we haven't had much time to discuss it, but this will at least codify what I've been running manually in VSCode.

Example output for failure:

=== CONT  TestGenerate_WithConfig/Swagger_Petstore_-_OpenAPI_3.0
    /Users/austin.valle/code/terraform-plugin-codegen-openapi/internal/cmd/generate_test.go:65: unexpected difference:   []uint8(Inverse(ParseIRJSON, ir.IntermediateRepresentation{
                Provider: {Name: "petstore"},
                Resources: []ir.Resource{
                        {
                                Name: "order",
                                Schema: ir.ResourceSchema{
                                        Attributes: []ir.ResourceAttribute{
                                                {
                                                        Name:    "complete",
        -                                               Bool:    &ir.ResourceBoolAttribute{ComputedOptionalRequired: "computed_optional", Description: &""},
        +                                               Bool:    nil,
                                                        String:  nil,
        -                                               Int64:   nil,
        +                                               Int64:   &ir.ResourceInt64Attribute{ComputedOptionalRequired: "computed_optional", Description: &""},
                                                        Number:  nil,
                                                        Float64: nil,
                                                        ... // 3 identical fields
                                                },
                                                {Name: "id", Int64: &{ComputedOptionalRequired: "computed_optional", Description: &""}},
                                                {Name: "petId", Int64: &{ComputedOptionalRequired: "computed_optional", Description: &""}},
                                                ... // 4 identical elements
                                        },
                                },
                        },
                        {Name: "pet", Schema: {Attributes: {{Name: "category", SingleNested: &{Attributes: {{Name: "id", Int64: &{ComputedOptionalRequired: "computed_optional", Description: &""}}, {Name: "name", String: &{ComputedOptionalRequired: "computed_optional", Description: &"", Sensitive: &false}}}, ComputedOptionalRequired: "computed_optional", Description: &""}}, {Name: "id", Int64: &{ComputedOptionalRequired: "computed_optional", Description: &""}}, {Name: "name", String: &{ComputedOptionalRequired: "required", Description: &"", Sensitive: &false}}, {Name: "photoUrls", List: &{ComputedOptionalRequired: "required", Description: &"", ElementType: {String: &{}}}}, ...}}},
                        {Name: "user", Schema: {Attributes: {{Name: "email", String: &{ComputedOptionalRequired: "computed_optional", Description: &"", Sensitive: &false}}, {Name: "firstName", String: &{ComputedOptionalRequired: "computed_optional", Description: &"", Sensitive: &false}}, {Name: "id", Int64: &{ComputedOptionalRequired: "computed_optional", Description: &""}}, {Name: "lastName", String: &{ComputedOptionalRequired: "computed_optional", Description: &"", Sensitive: &false}}, ...}}},
                },
                DataSources: {{Name: "order", Schema: {Attributes: {{Name: "orderId", Int64: &{ComputedOptionalRequired: "required", Description: &""}}, {Name: "complete", Bool: &{ComputedOptionalRequired: "computed_optional", Description: &""}}, {Name: "id", Int64: &{ComputedOptionalRequired: "computed_optional", Description: &""}}, {Name: "petId", Int64: &{ComputedOptionalRequired: "computed_optional", Description: &""}}, ...}}}, {Name: "pet", Schema: {Attributes: {{Name: "petId", Int64: &{ComputedOptionalRequired: "required", Description: &""}}, {Name: "category", SingleNested: &{Attributes: {{Name: "id", Int64: &{ComputedOptionalRequired: "computed_optional", Description: &""}}, {Name: "name", String: &{ComputedOptionalRequired: "computed_optional", Description: &"", Sensitive: &false}}}, ComputedOptionalRequired: "computed_optional", Description: &""}}, {Name: "id", Int64: &{ComputedOptionalRequired: "computed_optional", Description: &""}}, {Name: "name", String: &{ComputedOptionalRequired: "required", Desc
ription: &"", Sensitive: &false}}, ...}}}, {Name: "pets", Schema: {Attributes: {{Name: "status", String: &{ComputedOptionalRequired: "computed_optional", Description: &"", Sensitive: &false}}}}}},
          }))
--- FAIL: TestGenerate_WithConfig/Swagger_Petstore_-_OpenAPI_3.0 (0.02s)
austinvalle commented 1 year ago

Overall looks good to me 🚀

I'm not sure if I have a specific opinion on the testing question at the moment. Trying to test against JSON bytes can be problematic since that specification enables unordered properties, etc. so it does seem safer to test at the Go struct level unless there is some unit testing dependency we want to use specifically for JSON comparison. There is https://pkg.go.dev/github.com/nsf/jsondiff, which uses shell command sequences to output the differences and doesn't appear to have other dependencies, however any library selection here inherently may introduce its own oddities/complexity.

Cool, I'm in the same boat, so will worry about that at a later date!

github-actions[bot] commented 3 months ago

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.