Commit 6edb1769 authored by Dylan Griffith's avatar Dylan Griffith

Merge branch 'flipper-accepts-percentage-float' into 'master'

Make `/features` API accept percentage as float to enable 0.01%

See merge request gitlab-org/gitlab!73965
parents bf717b67 22cff155
......@@ -13,10 +13,15 @@ module API
true
when '0', 'false'
false
else
# https://github.com/jnunemaker/flipper/blob/master/lib/flipper/typecast.rb#L47
if params[:value].to_s.include?('.')
params[:value].to_f
else
params[:value].to_i
end
end
end
def gate_key(params)
case params[:key]
......@@ -59,7 +64,7 @@ module API
success Entities::Feature
end
params do
requires :value, type: String, desc: '`true` or `false` to enable/disable, an integer for percentage of time'
requires :value, type: String, desc: '`true` or `false` to enable/disable, a float for percentage of time'
optional :key, type: String, desc: '`percentage_of_actors` or the default `percentage_of_time`'
optional :feature_group, type: String, desc: 'A Feature group name'
optional :user, type: String, desc: 'A GitLab username'
......
......@@ -256,6 +256,21 @@ RSpec.describe API::Features, stub_feature_flags: false do
)
end
it 'creates a feature with the given percentage of time if passed a float' do
post api("/features/#{feature_name}", admin), params: { value: '0.01' }
expect(response).to have_gitlab_http_status(:created)
expect(json_response).to match(
'name' => feature_name,
'state' => 'conditional',
'gates' => [
{ 'key' => 'boolean', 'value' => false },
{ 'key' => 'percentage_of_time', 'value' => 0.01 }
],
'definition' => known_feature_flag_definition_hash
)
end
it 'creates a feature with the given percentage of actors if passed an integer' do
post api("/features/#{feature_name}", admin), params: { value: '50', key: 'percentage_of_actors' }
......@@ -270,6 +285,21 @@ RSpec.describe API::Features, stub_feature_flags: false do
'definition' => known_feature_flag_definition_hash
)
end
it 'creates a feature with the given percentage of actors if passed a float' do
post api("/features/#{feature_name}", admin), params: { value: '0.01', key: 'percentage_of_actors' }
expect(response).to have_gitlab_http_status(:created)
expect(json_response).to match(
'name' => feature_name,
'state' => 'conditional',
'gates' => [
{ 'key' => 'boolean', 'value' => false },
{ 'key' => 'percentage_of_actors', 'value' => 0.01 }
],
'definition' => known_feature_flag_definition_hash
)
end
end
context 'when the feature exists' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment