Skip to content
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

fix: 短絡評価によるバグを修正 #41

Merged
merged 1 commit into from
Feb 12, 2025
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
35 changes: 34 additions & 1 deletion path_not_specified_add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,39 @@ func TestPathNotSpecifiedAdd(t *testing.T) {
expected map[string]interface{}
expectedChanged bool
}{
// Replace Multi Attribute
{
name: "Add operation - Core Singular Attributes - add",
op: scim.PatchOperation{
Op: "add",
Value: map[string]interface{}{
"displayName": "Alice Green",
"name": map[string]interface{}{
"familyName": "Green",
},
"emails": []interface{}{
map[string]interface{}{
"type": "work",
"value": "[email protected]",
},
},
},
},
data: map[string]interface{}{},
expected: map[string]interface{}{
"displayName": "Alice Green",
"name": map[string]interface{}{
"familyName": "Green",
},
"emails": []interface{}{
map[string]interface{}{
"type": "work",
"value": "[email protected]",
},
},
},
expectedChanged: true,
},
// Singular Attribute
{
name: "Add operation - Core Singular Attributes - add",
Expand Down Expand Up @@ -466,7 +499,7 @@ func TestPathNotSpecifiedAdd(t *testing.T) {
}, nil)

// Apply the PatchOperation
result, changed, err := patcher.Apply(context.TODO(),tc.op, tc.data)
result, changed, err := patcher.Apply(context.TODO(), tc.op, tc.data)
if err != nil {
t.Fatalf("Apply() returned an unexpected error: %v", err)
}
Expand Down
33 changes: 33 additions & 0 deletions path_not_specified_replace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,39 @@ func TestPathNotSpecifiedReplace(t *testing.T) {
expected map[string]interface{}
expectedChanged bool
}{
// Replace Multi Attribute
{
name: "Replace operation - Core Singular Attributes - add",
op: scim.PatchOperation{
Op: "replace",
Value: map[string]interface{}{
"displayName": "Alice Green",
"name": map[string]interface{}{
"familyName": "Green",
},
"emails": []interface{}{
map[string]interface{}{
"type": "work",
"value": "[email protected]",
},
},
},
},
data: map[string]interface{}{},
expected: map[string]interface{}{
"displayName": "Alice Green",
"name": map[string]interface{}{
"familyName": "Green",
},
"emails": []interface{}{
map[string]interface{}{
"type": "work",
"value": "[email protected]",
},
},
},
expectedChanged: true,
},
// Singular Attribute
{
name: "Replace operation - Core Singular Attributes - add",
Expand Down
8 changes: 6 additions & 2 deletions scimpatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ func (p *Patcher) pathUnspecifiedOperate(
uriPrefix, ok := p.schemas[attr]
// Core Attributes
if !ok {
changed = changed || operator.Direct(ctx, data, attr, value)
if operator.Direct(ctx, data, attr, value) {
changed = true
}
continue
}

Expand All @@ -195,7 +197,9 @@ func (p *Patcher) pathUnspecifiedOperate(
// if exists, write by every attributes
if newUriMap, ok := value.(map[string]interface{}); ok {
for scopedAttr, scopedValue := range newUriMap {
changed = changed || operator.Direct(ctx, oldMap, scopedAttr, scopedValue)
if operator.Direct(ctx, oldMap, scopedAttr, scopedValue) {
changed = true
}
}
}
}
Expand Down
Loading