Skip to content

Commit

Permalink
feat: refactor options
Browse files Browse the repository at this point in the history
  • Loading branch information
notdryft committed Sep 20, 2024
1 parent c3ddca5 commit 942d029
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ githubPath := "gatling/gatling-sbt-plugin"

libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.2.19" % Test,
"io.gatling" % "gatling-enterprise-plugin-commons" % "1.9.6",
"io.gatling" % "gatling-enterprise-plugin-commons" % "1.9.7",
"io.gatling" % "gatling-shared-cli" % "0.0.3"
)

Expand Down
17 changes: 10 additions & 7 deletions src/main/scala/io/gatling/sbt/GatlingKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.gatling.sbt

import _root_.io.gatling.plugin.ConfigurationConstants
import _root_.io.gatling.sbt.settings.BaseSettings

import sbt._
Expand All @@ -41,19 +42,21 @@ object GatlingKeys {
val enterpriseUrl = settingKey[URL]("URL of Gatling Enterprise.")

val enterpriseApiToken =
settingKey[String](s"""API Token on Gatling Enterprise.
|Prefer configuration using `GATLING_ENTERPRISE_API_TOKEN` environment variable, or `gatling.enterprise.apiToken` system property.
|$documentationReference.
|""".stripMargin)
settingKey[String](
s"""API Token on Gatling Enterprise.
|Prefer configuration using `${ConfigurationConstants.ApiToken.ENV_VAR}` environment variable, or `${ConfigurationConstants.ApiToken.SYS_PROP}` system property.
|$documentationReference.
|""".stripMargin
)

val enterprisePackageId = settingKey[String](s"""Package ID on Gatling Enterprise (used by `enterpriseUpload` task).
|${systemPropertyDescription("gatling.enterprise.packageId")}.
|${systemPropertyDescription(ConfigurationConstants.UploadOptions.PackageId.SYS_PROP)}.
|$documentationReference.
|""".stripMargin)

val enterpriseSimulationId =
settingKey[String](s"""Simulation ID on Gatling Enterprise. Used by `enterprisePackage` if `enterprisePackageId` isn't configured.
|${systemPropertyDescription("gatling.enterprise.simulationId")}.
|${systemPropertyDescription(ConfigurationConstants.UploadOptions.SimulationId.SYS_PROP)}.
|$documentationReference.
|""".stripMargin)

Expand All @@ -66,7 +69,7 @@ object GatlingKeys {
val waitForRunEnd =
settingKey[Boolean](
s"""Wait for the result after starting the simulation on Gatling Enterprise, and complete with an error if the simulation ends with any error status.
|${systemPropertyDescription("gatling.enterprise.waitForRunEnd")}.
|${systemPropertyDescription(ConfigurationConstants.StartOptions.WaitForRunEnd.SYS_PROP)}.
|$documentationReference.
|""".stripMargin
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.gatling.sbt.settings.gatling

import io.gatling.plugin.{ BatchEnterprisePlugin, EnterprisePlugin, EnterprisePluginProvider, PluginConfiguration }
import io.gatling.plugin.{ BatchEnterprisePlugin, ConfigurationConstants, EnterprisePlugin, EnterprisePluginProvider, PluginConfiguration }
import io.gatling.plugin.model.BuildTool
import io.gatling.sbt.BuildInfo
import io.gatling.sbt.GatlingKeys._
Expand Down Expand Up @@ -47,7 +47,7 @@ object EnterprisePluginTask {
if (apiToken.isEmpty) {
logger.error(
s"""An API token is required to call the Gatling Enterprise server; see https://gatling.io/docs/enterprise/cloud/reference/admin/api_tokens/ and create a token with the role 'Configurer'.
|You can then set your API token's value in the environment variable GATLING_ENTERPRISE_API_TOKEN, pass it with -Dgatling.enterprise.apiToken=<apiToken>, or add the configuration to your SBT settings, e.g.:
|You can then set your API token's value in the environment variable ${ConfigurationConstants.ApiToken.ENV_VAR}, pass it with -D${ConfigurationConstants.ApiToken.SYS_PROP}=<apiToken>, or add the configuration to your SBT settings, e.g.:
|${config.id} / enterpriseApiToken := MY_API_TOKEN_VALUE""".stripMargin
)
throw ErrorAlreadyLoggedException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package io.gatling.sbt.settings.gatling

import java.{ lang => jl }
import java.net.URI

import io.gatling.plugin.ConfigurationConstants
import io.gatling.sbt.GatlingKeys._

import sbt._
Expand Down Expand Up @@ -52,18 +52,17 @@ object EnterpriseSettings {
val taskStart = new TaskEnterpriseStart(config, taskDeploy)

Seq(
config / enterpriseUrl := URI.create("https://cloud.gatling.io").toURL,
config / enterpriseUrl := new URI(ConfigurationConstants.Url.value()).toURL,
config / enterprisePackage := taskPackage.buildEnterprisePackage.value,
config / enterpriseUpload := taskUpload.uploadEnterprisePackage.value,
config / enterpriseDeploy := taskDeploy.enterpriseDeploy.evaluated,
config / enterpriseStart := taskStart.enterpriseSimulationStart.evaluated,
config / enterprisePackageId := sys.props.get("gatling.enterprise.packageId").getOrElse(""),
config / enterpriseSimulationId := sys.props.get("gatling.enterprise.simulationId").getOrElse(""),
config / enterpriseControlPlaneUrl := sys.props
.get("gatling.enterprise.controlPlaneUrl")
.map(configString => URI.create(configString).toURL),
config / waitForRunEnd := jl.Boolean.getBoolean("gatling.enterprise.waitForRunEnd"),
config / enterpriseApiToken := sys.props.get("gatling.enterprise.apiToken").orElse(sys.env.get("GATLING_ENTERPRISE_API_TOKEN")).getOrElse(""),
config / enterprisePackageId := Option(ConfigurationConstants.UploadOptions.PackageId.value()).getOrElse(""),
config / enterpriseSimulationId := Option(ConfigurationConstants.UploadOptions.SimulationId.value()).getOrElse(""),
config / enterpriseControlPlaneUrl := Option(ConfigurationConstants.ControlPlaneUrl.value())
.map(configString => new URI(configString).toURL),
config / waitForRunEnd := ConfigurationConstants.StartOptions.WaitForRunEnd.value(),
config / enterpriseApiToken := Option(ConfigurationConstants.ApiToken.value()).getOrElse(""),
config / packageBin := (config / enterprisePackage).value // If we directly use config / enterprisePackage for publishing, classifiers (-tests or -it) are not correctly handled.
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package io.gatling.sbt.settings.gatling

import scala.util.{ Failure, Try }

import io.gatling.plugin.ConfigurationConstants
import io.gatling.plugin.exceptions._

import sbt.Configuration
Expand All @@ -44,7 +45,7 @@ class RecoverEnterprisePluginException(config: Configuration) {
protected def logSimulationConfiguration(logger: ManagedLogger, waitForRunEndSetting: Boolean): Unit =
if (!waitForRunEndSetting) {
logger.info(
s"""To wait for the end of the run when starting a simulation on Gatling Enterprise, specify -Dgatling.enterprise.waitForRunEnd=true, or add the configuration to your SBT settings, e.g.:
s"""To wait for the end of the run when starting a simulation on Gatling Enterprise, specify -D${ConfigurationConstants.StartOptions.WaitForRunEnd.SYS_PROP}=true, or add the configuration to your SBT settings, e.g.:
|${config.id} / waitForRunEnd := true
|""".stripMargin
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import java.util.UUID

import scala.util.Try

import io.gatling.plugin.ConfigurationConstants
import io.gatling.sbt.GatlingKeys._
import io.gatling.sbt.settings.gatling.EnterpriseUtils._

Expand All @@ -38,7 +39,7 @@ class TaskEnterpriseUpload(config: Configuration, enterprisePackage: TaskEnterpr
if (settingPackageId.isEmpty && settingSimulationId.isEmpty) {
logger.error(
s"""A package ID is required to upload a package on Gatling Enterprise; see https://gatling.io/docs/enterprise/cloud/reference/user/package_conf/ , create a package and copy its ID.
|You can then set your package ID value by passing it with -Dgatling.enterprise.packageId=<packageId>, or add the configuration to your SBT settings, e.g.:
|You can then set your package ID value by passing it with -D${ConfigurationConstants.UploadOptions.PackageId.SYS_PROP}=<packageId>, or add the configuration to your SBT settings, e.g.:
|${config.id} / enterprisePackageId := MY_PACKAGE_ID
|
|Alternately, if you don't configure a packageId, you can configure the simulationId of an existing simulation on Gatling Enterprise: your code will be uploaded to the package used by that simulation.
Expand Down

0 comments on commit 942d029

Please sign in to comment.