Skip to content

Commit

Permalink
Merge pull request #437 from hagay3/feature/hagai/addMoreJsonErrors
Browse files Browse the repository at this point in the history
feature/hagai/add-more-json-errors
  • Loading branch information
hagay3 authored Dec 24, 2024
2 parents ec43fb2 + 338c076 commit 27c34e5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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 }}
Expand Down Expand Up @@ -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 }}
Expand All @@ -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 }}
Expand All @@ -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 }}
Expand All @@ -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 }}
Expand All @@ -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 }}
Expand All @@ -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 }}
Expand Down
4 changes: 1 addition & 3 deletions client/src/main/scala/skuber/json/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
}

Expand Down
19 changes: 17 additions & 2 deletions client/src/test/scala/skuber/model/ResourceSpec.scala
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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)
}
}

}

0 comments on commit 27c34e5

Please sign in to comment.