Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions libs/structs/structdiff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,15 @@ func diffStruct(ctx *diffContext, path *structpath.PathNode, s1, s2 reflect.Valu
continue
}

// Only the exact tag json:"-" skips a field; json:"-," names it "-".
if structaccess.IsSkippedField(sf) {
continue
}

jsonTag := structtag.JSONTag(sf.Tag.Get("json"))

// Resolve field name from JSON tag or fall back to Go field name
fieldName := jsonTag.Name()
if fieldName == "-" {
continue
}

isEmbed := sf.Name == structaccess.EmbeddedSliceFieldName

Expand Down
25 changes: 25 additions & 0 deletions libs/structs/structdiff/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"testing"
"time"

"github.com/databricks/cli/libs/structs/structaccess"

"github.com/databricks/databricks-sdk-go/common/types/duration"
sdktime "github.com/databricks/databricks-sdk-go/common/types/time"
"github.com/databricks/databricks-sdk-go/service/jobs"
Expand Down Expand Up @@ -1034,3 +1036,26 @@ func TestGetStructDiffWholeBlock(t *testing.T) {
})
}
}

type dashNamed struct {
Skipped string `json:"-"`
Named string `json:"-,omitempty"` //nolint:staticcheck // odd tag is the point
}

// TestGetStructDiffDashNamedField checks that only the exact tag json:"-" skips a
// field: encoding/json serializes json:"-,omitempty" under the key "-", and
// structaccess resolves the path "-" to it.
func TestGetStructDiffDashNamedField(t *testing.T) {
before := &dashNamed{Skipped: "a", Named: "a"}
after := &dashNamed{Skipped: "b", Named: "b"}

changes, err := GetStructDiff(before, after, nil)
require.NoError(t, err)
assert.Equal(t, []ResolvedChange{{Field: "-", Old: "a", New: "b"}}, resolveChanges(changes))

value, err := structaccess.Get(after, changes[0].Path)
require.NoError(t, err)
assert.Equal(t, "b", value)

assert.Equal(t, len(changes) == 0, IsEqual(before, after))
}
Loading