-
Notifications
You must be signed in to change notification settings - Fork 0
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: update (hotels&airports) #78
Open
led0nk
wants to merge
6
commits into
main
Choose a base branch
from
updating
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
83eb05c
fix: update (hotels&airports)
led0nk c82dfbf
fix: UpdateAirports/Hotels -> cleaner attempt
led0nk 270518a
printout-remove
led0nk eaa6528
add comm/add reflect.UUID, add form_test.go
led0nk 634f5aa
add licensehead to form_test.go
led0nk d2073a1
fix for UUID:updateEvent
led0nk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright (C) 2024 the lets-party maintainers | ||
// See root-dir/LICENSE for more information | ||
|
||
package form | ||
|
||
import ( | ||
"net/url" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/google/uuid" | ||
) | ||
|
||
type TestStruct struct { | ||
UUIDField uuid.UUID `form:"uuid_field"` | ||
StringField string `form:"string_field"` | ||
BoolField bool `form:"bool_field"` | ||
IntField int `form:"int_field"` | ||
FloatField float64 `form:"float_field"` | ||
SliceField []string `form:"slice_field"` | ||
StructField FieldStruct `form:"struct_field"` | ||
} | ||
|
||
type FieldStruct struct { | ||
StringField string `form:"field_struct_strfield"` | ||
BoolField bool `form:"field_struct_boolfield"` | ||
} | ||
|
||
func TestUnmarshal(t *testing.T) { | ||
led0nk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
testCases := []struct { | ||
name string | ||
input url.Values | ||
expected TestStruct | ||
expectedErr bool | ||
}{ | ||
{ | ||
name: "Valid input data", | ||
input: url.Values{ | ||
"uuid_field": {"ca07d617-c87c-4ac3-affc-27a5e941b28f"}, | ||
"string_field": {"test_string"}, | ||
"bool_field": {"true"}, | ||
"int_field": {"42"}, | ||
"float_field": {"3.14"}, | ||
"slice_field": {"1", "2", "3"}, | ||
"struct_field.field_struct_strfield": {"stringfield"}, | ||
"struct_field.field_struct_boolfield": {"true"}, | ||
}, | ||
expected: TestStruct{ | ||
UUIDField: uuid.MustParse("ca07d617-c87c-4ac3-affc-27a5e941b28f"), | ||
StringField: "test_string", | ||
BoolField: true, | ||
IntField: 42, | ||
FloatField: 3.14, | ||
SliceField: []string{"1", "2", "3"}, | ||
StructField: FieldStruct{ | ||
StringField: "stringfield", | ||
BoolField: true, | ||
}, | ||
}, | ||
expectedErr: false, | ||
}, | ||
{ | ||
name: "Empty input", | ||
input: url.Values{}, | ||
expected: TestStruct{}, | ||
expectedErr: false, | ||
}, | ||
{ | ||
name: "Missing fields", | ||
input: url.Values{ | ||
"string_field": {"test_string"}, | ||
}, | ||
expected: TestStruct{ | ||
StringField: "test_string", | ||
}, | ||
expectedErr: false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
var target TestStruct | ||
err := Unmarshal(tc.input, &target) | ||
if (err != nil) != tc.expectedErr { | ||
t.Errorf("Unexpected error: %v", err) | ||
} | ||
if !reflect.DeepEqual(target, tc.expected) { | ||
t.Errorf("Unmarshal did not produce expected result. got: %+v, expected: %+v", target, tc.expected) | ||
} | ||
}) | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good stuff, but that would mean we have to implement any new type definition?
Since uuid.UUID is a
[16]byte
, can we maybe change the case to check forreflect.Array
instead?And in case that does not work, we could maybe provide a way to extend the Unmarshal capabilities by providing a custom
HtmlFormUnmarshaler
implementation.In that case
uuid.UUID
has to implement this method:For this we could wrap the wrap the type:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reflect.Array
seems to work fine here