Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/hagai/add-more-json-errors #437

Merged
merged 4 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}

}
Loading