Skip to content

Commit

Permalink
fix(s3): ensure s3api calls always output json (#7)
Browse files Browse the repository at this point in the history
* fix(ci): ensure tests do not hang

* fix(s3): ensure api operations always use json
  • Loading branch information
kiran94 authored May 11, 2023
1 parent 9d83f2f commit d5d8bd9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
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

0 comments on commit d5d8bd9

Please sign in to comment.