Skip to content

Commit

Permalink
testing for application strategies (#1184)
Browse files Browse the repository at this point in the history
  • Loading branch information
rvowles authored Oct 3, 2024
1 parent 6608e52 commit b5a31b9
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 6 deletions.
2 changes: 1 addition & 1 deletion backend/mr-api/mr-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ openapi: 3.0.1
info:
title: ManagementResourceApi
description: This describes the API clients use for accessing features. This reflects the API from 1.6.1 onwards.
version: "1.2.2"
version: "1.2.3"
# CRUD for portfolios, environments, features, service account, people, and groups (edited)
# roles are fixed
# then people<->group association
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import java.time.LocalDateTime
import java.util.*

class ApplicationRolloutStrategySqlApi @Inject constructor(
private val database: Database, private val conversions: Conversions, private val cacheSource: CacheSource
private val conversions: Conversions, private val cacheSource: CacheSource
) : ApplicationRolloutStrategyApi {

override fun createStrategy(
Expand Down Expand Up @@ -97,7 +97,7 @@ class ApplicationRolloutStrategySqlApi @Inject constructor(

@Transactional
private fun save(rs: DbApplicationRolloutStrategy) {
database.save(rs)
rs.save()
}


Expand All @@ -115,7 +115,7 @@ class ApplicationRolloutStrategySqlApi @Inject constructor(
if (strategy.application.id == app.id) {
// check if we are renaming it and if so, are we using a duplicate name
update.name?.let { newName ->
if (!strategy.name.equals(update.name, ignoreCase = true)) {
if (!strategy.name.equals(newName, ignoreCase = true)) {
// is there something using the existing name?
val existing = QDbApplicationRolloutStrategy().application
.eq(app).name
Expand All @@ -127,6 +127,9 @@ class ApplicationRolloutStrategySqlApi @Inject constructor(
throw ApplicationRolloutStrategyApi.DuplicateNameException()
}
}

strategy.name = newName
strategy.strategy.name = newName
}

update.percentage?.let { percent ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.featurehub.db.services

import io.featurehub.db.api.Opts
import io.featurehub.mr.model.CreateApplicationRolloutStrategy
import io.featurehub.mr.model.RolloutStrategyAttribute
import io.featurehub.mr.model.RolloutStrategyAttributeConditional
import io.featurehub.mr.model.RolloutStrategyFieldType
import io.featurehub.mr.model.UpdateApplicationRolloutStrategy

class ApplicationStrategySpec extends Base3Spec {
ApplicationRolloutStrategySqlApi appStrategyApi

def setup() {
appStrategyApi = new ApplicationRolloutStrategySqlApi(convertUtils, cacheSource)
}

def "i can create, update and delete an application strategy"() {
given: "i have an app strategy"
def create = new CreateApplicationRolloutStrategy()
.name("phred").disabled(false)
.percentage(20000)
.attributes([new RolloutStrategyAttribute().id("abcde")
.type(RolloutStrategyFieldType.BOOLEAN)
.values([true])
.fieldName("jxtq")
.conditional(RolloutStrategyAttributeConditional.ENDS_WITH)])
when: "i save it"
def strat = appStrategyApi.createStrategy(app1.id, create, superuser, Opts.empty())
then:
strat.name == "phred"
strat.percentage == 20000
when: "i update it with the same name, its ok"
def updated = appStrategyApi.updateStrategy(app1.id, strat.id,
new UpdateApplicationRolloutStrategy().name("phred22")
.attributes([new RolloutStrategyAttribute().id("abcde")
.type(RolloutStrategyFieldType.BOOLEAN)
.values([false])
.fieldName("jxtq")
.conditional(RolloutStrategyAttributeConditional.ENDS_WITH)])
.percentage(10000), superuser, Opts.empty())
then:
updated.name == "phred22"
updated.percentage == 10000
}
}
5 changes: 3 additions & 2 deletions infra/api-bucket/files/releases.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"latest": "1.8.0",
"latest": "1.8.1",

"versions": [
{
Expand All @@ -26,6 +26,7 @@
{ "version": "1.6.0" },
{ "version": "1.7.0" },
{ "version": "1.7.1" },
{ "version": "1.8.0" }
{ "version": "1.8.0" },
{ "version": "1.8.1" }
]
}

0 comments on commit b5a31b9

Please sign in to comment.