-
Notifications
You must be signed in to change notification settings - Fork 652
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 bucket keys as ints format #590
Conversation
13d5867
to
b6beb26
Compare
If the data isn't an integer, the output of Currently the default output format is |
b6beb26
to
f0c88bb
Compare
@ahrtr fixed 👍🏽 |
I meant to change the default format from Line 912 in d094cd7
Please also let's go through the default format for all commands, and decide whether we should change the default format. At least, let's list them firstly. |
Signed-off-by: Mustafa Elbehery <[email protected]>
f0c88bb
to
4db9e03
Compare
@ahrtr sorry for the delay, i pushed the change now also found that the bbolt/cmd/bbolt/page_command.go Line 285 in 393e10e
|
i will go through all the commands now in a separate commit |
thx, we can discuss the details on next Monday's meeting. |
I think we should set the default output format as " Lines 1580 to 1587 in 2b28986
Suggest not to change the |
Signed-off-by: Mustafa Elbehery <[email protected]>
e7fbaff
to
121b2b4
Compare
Signed-off-by: Mustafa Elbehery <[email protected]>
The func is not exposed, and the Please let me know :) |
We don't test the function directly. Instead, we test the command, and verify whether the command's output is expected, similar to Line 75 in 2b28986
|
@@ -456,7 +456,7 @@ func (cmd *pageItemCommand) Run(args ...string) error { | |||
fs := flag.NewFlagSet("", flag.ContinueOnError) | |||
fs.BoolVar(&options.keyOnly, "key-only", false, "Print only the key") | |||
fs.BoolVar(&options.valueOnly, "value-only", false, "Print only the value") | |||
fs.StringVar(&options.format, "format", "ascii-encoded", "Output format. One of: "+FORMAT_MODES) | |||
fs.StringVar(&options.format, "format", "auto", "Output format. One of: "+FORMAT_MODES) |
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.
@ahrtr Hello ✋🏽
So to test this change, I ran the TestPageItemCommand_Run
and it passes.
currently the test case assert the keys and values are being inserted in
Lines 143 to 146 in 4154f9c
err := db.Fill([]byte("data"), 1, 100, | |
func(tx int, k int) []byte { return []byte(fmt.Sprintf("key_%d", k)) }, | |
func(tx int, k int) []byte { return []byte(fmt.Sprintf("value_%d", k)) }, | |
) |
Main.Stdout
as a string here Line 165 in 4154f9c
if !strings.Contains(m.Stdout.String(), "key_0") || !strings.Contains(m.Stdout.String(), "value_0") { |
Although the key and value are being inserted are int
typed, they are asserted as a string prefix
I am stuck in what should I assert to test the changes ?
I can insert hex
data for instance, but still I will capture the output as a string
, please correct me if I am wrong ?
for i := 0; i < 3; i++ { | ||
key := fmt.Sprintf("%s-%d", name, i) | ||
if err := b.Put([]byte(key), []byte{0}); err != nil { | ||
for _, k := range []int64{10001, 10002} { |
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.
@ahrtr I added this sub-test
- insert keys in int64 format
- asserting the keys are retrieved correctly
running this test fails on
--- FAIL: TestKeysCommand_Run/test_keys_in_int_format (0.08s)
btesting.go:47: Opening bbolt DB at: /var/folders/vh/wkbmyt411316pt46h81d6_300000gn/T/TestKeysCommand_Runtest_keys_in_int_format3069027896/001/db
btesting.go:87: Closing bbolt DB at: /var/folders/vh/wkbmyt411316pt46h81d6_300000gn/T/TestKeysCommand_Runtest_keys_in_int_format3069027896/001/db
main_test.go:341: unexpected stdout:
a29c01
a49c01
08a9acd
to
0e2ab60
Compare
key := fmt.Sprintf("%s-%d", name, i) | ||
val := fmt.Sprintf("val-%s-%d", name, i) | ||
if err := b.Put([]byte(key), []byte(val)); err != nil { | ||
for k, v := range map[string]int64{ |
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.
same here added subtest for string
keys and int64
values, similar issue
go test -run TestGetCommand_Run ‹git:fix_bucket_keys_as_ints ✔› 11:34.33 Mon Nov 06 2023 >>>
--- FAIL: TestGetCommand_Run (0.17s)
--- FAIL: TestGetCommand_Run/test_values_in_int64_format (0.08s)
btesting.go:47: Opening bbolt DB at: /var/folders/vh/wkbmyt411316pt46h81d6_300000gn/T/TestGetCommand_Runtest_values_in_int64_format893707620/001/db
btesting.go:87: Closing bbolt DB at: /var/folders/vh/wkbmyt411316pt46h81d6_300000gn/T/TestGetCommand_Runtest_values_in_int64_format893707620/001/db
main_test.go:422: unexpected stdout:
a29c01
0e2ab60
to
4be6eb8
Compare
leafPageId = int(p.Id()) | ||
} | ||
} | ||
require.NotEqual(t, 0, leafPageId) |
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.
it fails here
Error: Should not be: 0
we sat the pageId
above to 0 and it is the same as the above subtest !!!
Signed-off-by: Mustafa Elbehery <[email protected]>
4be6eb8
to
436947d
Compare
I suggest to split this PR into three small PRs, and each of them takes care of one change for one command mentioned in #590 (comment), so as to make the review easier. I will work together with you to resolve them one by one. What do you think? |
on it :+1 |
@ahrtr closing this |
This PR fixes the output format when bucket keys are numbers.
resolves #588
cc @ahrtr