diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f8127cea..e174455b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest] + os: [ubuntu-22.04] scala: [2.12.13, 2.13.12, 3.3.1] java: [temurin@17] runs-on: ${{ matrix.os }} @@ -61,7 +61,7 @@ jobs: if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v')) strategy: matrix: - os: [ubuntu-latest] + os: [ubuntu-22.04] scala: [2.13.12] java: [temurin@17] runs-on: ${{ matrix.os }} @@ -125,7 +125,7 @@ jobs: name: integration-kubernetes-v1-19 strategy: matrix: - os: [ubuntu-latest] + os: [ubuntu-22.04] scala: [2.13.12] java: [temurin@8] runs-on: ${{ matrix.os }} @@ -148,7 +148,7 @@ jobs: name: integration-kubernetes-v1-20 strategy: matrix: - os: [ubuntu-latest] + os: [ubuntu-22.04] scala: [2.13.12] java: [temurin@8] runs-on: ${{ matrix.os }} @@ -171,7 +171,7 @@ jobs: name: integration-kubernetes-v1-21 strategy: matrix: - os: [ubuntu-latest] + os: [ubuntu-22.04] scala: [2.13.12] java: [temurin@8] runs-on: ${{ matrix.os }} @@ -194,7 +194,7 @@ jobs: name: integration-kubernetes-v1-22 strategy: matrix: - os: [ubuntu-latest] + os: [ubuntu-22.04] scala: [2.13.12] java: [temurin@8] runs-on: ${{ matrix.os }} @@ -217,7 +217,7 @@ jobs: name: integration-kubernetes-v1-23 strategy: matrix: - os: [ubuntu-latest] + os: [ubuntu-22.04] scala: [2.13.12] java: [temurin@8] runs-on: ${{ matrix.os }} @@ -240,7 +240,7 @@ jobs: name: integration-kubernetes-v1-24 strategy: matrix: - os: [ubuntu-latest] + os: [ubuntu-22.04] scala: [2.13.12] java: [temurin@8] runs-on: ${{ matrix.os }} diff --git a/client/src/main/scala/skuber/json/package.scala b/client/src/main/scala/skuber/json/package.scala index 6a212f80..fefc0530 100644 --- a/client/src/main/scala/skuber/json/package.scala +++ b/client/src/main/scala/skuber/json/package.scala @@ -395,9 +395,7 @@ package object format { } jsResult match { case JsSuccess(_, _) => jsResult - case JsError(_) => Json.fromJson[Int](json).flatMap { - s => JsSuccess(Resource.Quantity(s.toString)) - } + case JsError(_) => JsSuccess(Resource.Quantity(json.toString())) } } diff --git a/client/src/test/scala/skuber/model/ResourceSpec.scala b/client/src/test/scala/skuber/model/ResourceSpec.scala index d0b83436..7a77da48 100644 --- a/client/src/test/scala/skuber/model/ResourceSpec.scala +++ b/client/src/test/scala/skuber/model/ResourceSpec.scala @@ -1,7 +1,8 @@ package skuber -import org.specs2.mutable.Specification // for unit-style testing - +import org.specs2.mutable.Specification +import play.api.libs.json.{JsResult, Json} +import skuber.Resource.Quantity import scala.math.BigInt @@ -59,5 +60,19 @@ class ResourceSpec extends Specification { badVal must throwAn[Exception] } } + + "A resource quantity json formatter\n" >> { + "where quantity json formatter should accpet different types" >> { + val jsonString = """[1.3, "1.2", "50m", "1Mi", 1, "2"]""" + // Parse the JSON + val json = Json.parse(jsonString) + // Deserialize into ResourceList + import skuber.json.format.quantityFormat + val result: JsResult[List[Quantity]] = Json.fromJson[List[Quantity]](json) + val amountList = result.get.map(_.amount) + + amountList mustEqual List(1.3, 1.2, 0.05, 1048576, 1, 2) + } + } } \ No newline at end of file