Skip to content

Commit

Permalink
Use spaces and underscore in tags
Browse files Browse the repository at this point in the history
Co-authored-by: Enrique García Cota <kikito@gmail.com>
  • Loading branch information
2 people authored and Hans Huebner committed Jul 28, 2022
1 parent 64c2c05 commit dc7a0cf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
12 changes: 6 additions & 6 deletions spec/02-integration/03-db/07-tags_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ for _, strategy in helpers.each_strategy() do
local service = {
host = "example-" .. i .. ".com",
name = "service" .. i,
tags = { "team a", "level "..fmod(i, 5), "service"..i }
tags = { "team_ a", "level "..fmod(i, 5), "service"..i }
}
local row, err, err_t = bp.services:insert(service)
assert.is_nil(err)
Expand Down Expand Up @@ -62,12 +62,12 @@ for _, strategy in helpers.each_strategy() do
end)

it("list entity IDs by tag", function()
local rows, err, err_t, offset = db.tags:page_by_tag("team a")
local rows, err, err_t, offset = db.tags:page_by_tag("team_ a")
assert(is_valid_page(rows, err, err_t))
assert.is_nil(offset)
assert.equal(test_entity_count, #rows)
for _, row in ipairs(rows) do
assert.equal("team a", row.tag)
assert.equal("team_ a", row.tag)
end

rows, err, err_t, offset = db.tags:page_by_tag("team alien")
Expand Down Expand Up @@ -107,7 +107,7 @@ for _, strategy in helpers.each_strategy() do
local func, key, removed_tag = unpack(scenario)

it(func, function()
local tags = { "team_b_" .. func, "team a" }
local tags = { "team_b_" .. func, "team_ a" }
local row, err, err_t = db.services[func](db.services,
key, { tags = tags, host = 'whatever.com' })

Expand All @@ -124,7 +124,7 @@ for _, strategy in helpers.each_strategy() do
assert.is_nil(offset)
assert.equal(test_entity_count*3 - removed_tags_count, #rows)

rows, err, err_t, offset = db.tags:page_by_tag("team a")
rows, err, err_t, offset = db.tags:page_by_tag("team_ a")
assert(is_valid_page(rows, err, err_t))
assert.is_nil(offset)
assert.equal(test_entity_count, #rows)
Expand Down Expand Up @@ -170,7 +170,7 @@ for _, strategy in helpers.each_strategy() do
assert.is_nil(offset)
assert.equal(test_entity_count*3 - removed_tags_count, #rows)

rows, err, err_t, offset = db.tags:page_by_tag("team a")
rows, err, err_t, offset = db.tags:page_by_tag("team_ a")
assert(is_valid_page(rows, err, err_t))
assert.is_nil(offset)
assert.equal(test_entity_count - i, #rows)
Expand Down
38 changes: 19 additions & 19 deletions spec/02-integration/04-admin_api/14-tags_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("Admin API - tags", function()
for i = 1, 2 do
local consumer = {
username = "adminapi-filter-by-tag-" .. i,
tags = { "corp a", "consumer "..i, "🦍" }
tags = { "corp_ a", "consumer_ "..i, "🦍" }
}
local row, err, err_t = bp.consumers:insert(consumer)
assert.is_nil(err)
Expand All @@ -32,7 +32,7 @@ describe("Admin API - tags", function()
config = {
path = os.tmpname(),
},
tags = { "corp a", "consumer " .. i }
tags = { "corp_ a", "consumer_ " .. i }
})
end

Expand All @@ -50,13 +50,13 @@ describe("Admin API - tags", function()
it("filter by single tag", function()
local res = assert(client:send {
method = "GET",
path = "/consumers?tags=corp%20a"
path = "/consumers?tags=corp_%20a"
})
local body = assert.res_status(200, res)
local json = cjson.decode(body)
assert.equals(2, #json.data)
for i = 1, 2 do
assert.contains('corp a', json.data[i].tags)
assert.contains('corp_ a', json.data[i].tags)
end
end)

Expand All @@ -76,50 +76,50 @@ describe("Admin API - tags", function()
it("filter by multiple tags with AND", function()
local res = assert(client:send {
method = "GET",
path = "/consumers?tags=corp%20a,consumer%201"
path = "/consumers?tags=corp_%20a,consumer_%201"
})
local body = assert.res_status(200, res)
local json = cjson.decode(body)
assert.equals(1, #json.data)
assert.equals(3, #json.data[1].tags)
assert.contains('corp a', json.data[1].tags)
assert.contains('consumer 1', json.data[1].tags)
assert.contains('corp_ a', json.data[1].tags)
assert.contains('consumer_ 1', json.data[1].tags)
assert.contains('🦍', json.data[1].tags)
end)

it("filter by multiple tags with OR", function()
local res = assert(client:send {
method = "GET",
path = "/consumers?tags=consumer%202/consumer%201"
path = "/consumers?tags=consumer_%202/consumer_%201"
})
local body = assert.res_status(200, res)
local json = cjson.decode(body)
assert.equals(2, #json.data)
end)

it("ignores tags when filtering by multiple filters #6779", function()
local res = client:get("/consumers/adminapi-filter-by-tag-1/plugins?tags=consumer%202")
local res = client:get("/consumers/adminapi-filter-by-tag-1/plugins?tags=consumer_%202")
local body = assert.res_status(200, res)
local json = cjson.decode(body)
assert.equals(1, #json.data)

assert.contains('corp a', json.data[1].tags)
assert.contains('consumer 1', json.data[1].tags)
assert.not_contains('consumer 2', json.data[1].tags)
assert.contains('corp_ a', json.data[1].tags)
assert.contains('consumer_ 1', json.data[1].tags)
assert.not_contains('consumer_ 2', json.data[1].tags)
end)

it("errors if filter by mix of AND and OR", function()
local res = assert(client:send {
method = "GET",
path = "/consumers?tags=consumer%203,consumer%202/consumer%201"
path = "/consumers?tags=consumer_%203,consumer_%202/consumer_%201"
})
local body = assert.res_status(400, res)
local json = cjson.decode(body)
assert.equals("invalid option (tags: invalid filter syntax)", json.message)

local res = assert(client:send {
method = "GET",
path = "/consumers?tags=consumer%203/consumer%202,consumer%201"
path = "/consumers?tags=consumer_%203/consumer_%202,consumer_%201"
})
local body = assert.res_status(400, res)
local json = cjson.decode(body)
Expand All @@ -137,7 +137,7 @@ describe("Admin API - tags", function()
end)

it("returns the correct 'next' arg", function()
local tags_arg = 'tags=corp%20a'
local tags_arg = 'tags=corp_%20a'
local res = assert(client:send {
method = "GET",
path = "/consumers?" .. tags_arg .. "&size=1"
Expand All @@ -161,7 +161,7 @@ describe("Admin API - tags", function()
for i = 1, 2 do
local consumer = {
username = "adminapi-filter-by-tag-" .. i,
tags = { "corp a", "consumer "..i }
tags = { "corp_ a", "consumer_ "..i }
}
local row, err, err_t = bp.consumers:insert(consumer)
assert.is_nil(err)
Expand Down Expand Up @@ -193,7 +193,7 @@ describe("Admin API - tags", function()
it("/tags/:tags", function()
local res = assert(client:send {
method = "GET",
path = "/tags/corp%20a"
path = "/tags/corp_%20a"
})
local body = assert.res_status(200, res)
local json = cjson.decode(body)
Expand Down Expand Up @@ -231,15 +231,15 @@ describe("Admin API - tags", function()
it("/tags/:tags ignores ?tags= query", function()
local res = assert(client:send {
method = "GET",
path = "/tags/corp%20a?tags=not_a_tag"
path = "/tags/corp_%20a?tags=not_a_tag"
})
local body = assert.res_status(200, res)
local json = cjson.decode(body)
assert.equals(2, #json.data)

local res = assert(client:send {
method = "GET",
path = "/tags/corp%20a?tags=invalid@tag"
path = "/tags/corp_%20a?tags=invalid@tag"
})
local body = assert.res_status(200, res)
local json = cjson.decode(body)
Expand Down

0 comments on commit dc7a0cf

Please sign in to comment.