spotify / confidence-sdk-go

Apache License 2.0
2 stars 1 forks source link

fix: Fix nested struct bug #37

Closed fabriziodemaria closed 9 months ago

fabriziodemaria commented 9 months ago

Recursive function replaceNumbers wouldn't propagate the basePath correctly, which causes TYPE_MISMATCH error

Valkyrie00 commented 9 months ago

Hi @fabriziodemaria, sorry for the intromission 😁, first of all, nice catch!! 🥇 Can I suggest you also improve my test file (in TestReplaceNumbers group line ~251) with the following test, to cover your case? If you agree obvs 🙂

Or if you already moved to another task i can create a new PR, as you prefer. Let me know.

    t.Run("SuccessfulNestedFlowMap", func(t *testing.T) {
        schema := map[string]interface{}{
            "structKey": map[string]interface{}{
                "structSchema": map[string]interface{}{
                    "schema": map[string]interface{}{
                        "nestedStructKey": map[string]interface{}{
                            "structSchema": map[string]interface{}{
                                "schema": map[string]interface{}{
                                    "nestedDoubleKey": map[string]interface{}{
                                        "doubleSchema": map[string]interface{}{},
                                    },
                                },
                            },
                        },
                    },
                },
            },
        }

        input := map[string]interface{}{
            "structKey": map[string]interface{}{
                "nestedStructKey": map[string]interface{}{
                    "nestedDoubleKey": json.Number("123.45"),
                },
            },
        }

        expected := map[string]interface{}{
            "structKey": map[string]interface{}{
                "nestedStructKey": map[string]interface{}{
                    "nestedDoubleKey": float64(123.45),
                },
            },
        }

        updatedMap, err := replaceNumbers("", input, schema)
        assert.NoError(t, err)
        assert.Equal(t, expected, updatedMap)
    })
fabriziodemaria commented 9 months ago

@Valkyrie00 your test suggestion sounds great, feel free to open a PR!