Skip to content

Commit

Permalink
test(kubernetes): Add tests of KubernetesKind serialization (#3992)
Browse files Browse the repository at this point in the history
* test(kubernetes): Add tests of KubernetesKind serialization

Test that we properly serialize and deserialize kubernetes kinds
to/from their string representation.

* test(kubernetes): Remove extraneous extraneous word

Co-Authored-By: Maggie Neterval <mneterval@google.com>
  • Loading branch information
ezimanyi and maggieneterval committed Aug 29, 2019
1 parent c71ba04 commit e9c7342
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@

package com.netflix.spinnaker.clouddriver.kubernetes.v2.description

import com.fasterxml.jackson.databind.ObjectMapper
import com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesApiGroup
import com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesKind
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Unroll

class KubernetesKindSpec extends Specification {
@Shared ObjectMapper objectMapper = new ObjectMapper()
@Shared KubernetesKind CUSTOM_RESOURCE_KIND = KubernetesKind.from("deployment", KubernetesApiGroup.fromString("stable.example.com"))

@Unroll
void "creates built-in API kinds by name"() {
when:
Expand Down Expand Up @@ -152,4 +157,34 @@ class KubernetesKindSpec extends Specification {
name | expectedString
"deployment.stable.example.com" | "deployment.stable.example.com"
}

void "deserializes kinds from their string representation"() {
when:
def kind = objectMapper.convertValue(input, KubernetesKind.class)

then:
kind == expectedKind

where:
input | expectedKind
"replicaSet" | KubernetesKind.REPLICA_SET
"ReplicaSet" | KubernetesKind.REPLICA_SET
"replicaSet" | KubernetesKind.REPLICA_SET
"service" | KubernetesKind.SERVICE
"deployment.stable.example.com" | CUSTOM_RESOURCE_KIND
}

void "serializes kinds to their string representation"() {
when:
def serialized = objectMapper.writeValueAsString(kind)

then:
serialized == '"' + expectedSerialized + '"'

where:
kind | expectedSerialized
KubernetesKind.REPLICA_SET | "replicaSet"
KubernetesKind.SERVICE | "service"
CUSTOM_RESOURCE_KIND | "deployment.stable.example.com"
}
}

0 comments on commit e9c7342

Please sign in to comment.