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(s3): ensure s3api calls always output json #7

Merged
merged 3 commits into from
May 11, 2023
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
4 changes: 2 additions & 2 deletions lua/s3edit/s3.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local sys = require("s3edit.system")
--- Gets the Bucket Names from S3
---@return table a list of bucket names
M.get_bucket_names = function()
local result = sys.make_system_call("aws s3api list-buckets")
local result = sys.make_system_call("aws s3api list-buckets --output json")
if result == nil then
return {}
end
Expand All @@ -23,7 +23,7 @@ end
---@param bucket string the bucket to search
---@return table a list of objects
M.get_objects = function(bucket)
local result = sys.make_system_call("aws s3api list-objects --bucket " .. bucket)
local result = sys.make_system_call("aws s3api list-objects --bucket " .. bucket .. " --output json")
if result == nil then
return {}
end
Expand Down
10 changes: 5 additions & 5 deletions lua/tests/s3_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe("get_bucket_names", function()
local result = s3.get_bucket_names()

assert.are.same({}, result)
assert.stub(mock_sys.make_system_call).was_called_with("aws s3api list-buckets")
assert.stub(mock_sys.make_system_call).was_called_with("aws s3api list-buckets --output json")
end)

it("should parse the bucket names", function()
Expand Down Expand Up @@ -39,7 +39,7 @@ describe("get_bucket_names", function()

assert.are.same("bucket1", result[1])
assert.are.same("bucket2", result[2])
assert.stub(mock_sys.make_system_call).was_called_with("aws s3api list-buckets")
assert.stub(mock_sys.make_system_call).was_called_with("aws s3api list-buckets --output json")
end)
end)

Expand All @@ -51,7 +51,7 @@ describe("get_objects", function()
local result = s3.get_objects("my_bucket")

assert.are.same({}, result)
assert.stub(mock_sys.make_system_call).was_called_with("aws s3api list-objects --bucket my_bucket")
assert.stub(mock_sys.make_system_call).was_called_with("aws s3api list-objects --bucket my_bucket --output json")
end)

it("should parse the objects", function()
Expand Down Expand Up @@ -89,7 +89,7 @@ describe("get_objects", function()

assert.are.same("key1", result[1])
assert.are.same("path/key2", result[2])
assert.stub(mock_sys.make_system_call).was_called_with("aws s3api list-objects --bucket my_bucket")
assert.stub(mock_sys.make_system_call).was_called_with("aws s3api list-objects --bucket my_bucket --output json")
end)

it("should return empty when no objects are found", function()
Expand All @@ -101,7 +101,7 @@ describe("get_objects", function()
local result = s3.get_objects("my_bucket")
assert.are.same({}, result)

assert.stub(mock_sys.make_system_call).was_called_with("aws s3api list-objects --bucket my_bucket")
assert.stub(mock_sys.make_system_call).was_called_with("aws s3api list-objects --bucket my_bucket --output json")
end)
end)

Expand Down
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ run:
nvim --cmd "set rtp+=./" --cmd 'lua require("s3edit").setup()' -o lua/s3edit/init.lua

test:
nvim --cmd "set rtp+=./" --headless -c "PlenaryBustedDirectory lua/tests/ { minimal_init = 'lua/tests/setup.vim' }"
nvim --cmd "set rtp+=./" --headless -c "PlenaryBustedDirectory lua/tests/"

help:
nvim --cmd "set rtp+=./" --cmd 'h s3edit'
Expand Down