From 07c243df2da48b76b6593e1d5081f76bd1a07e83 Mon Sep 17 00:00:00 2001 From: joshvanl Date: Mon, 7 Feb 2022 11:11:44 +0000 Subject: [PATCH] Adds a unit test to ensure serializing preserves CR spec in round trip Signed-off-by: joshvanl --- internal/controller/certificaterequests/apply.go | 2 +- internal/controller/certificaterequests/apply_test.go | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/controller/certificaterequests/apply.go b/internal/controller/certificaterequests/apply.go index 78cf6c100..f210c341e 100644 --- a/internal/controller/certificaterequests/apply.go +++ b/internal/controller/certificaterequests/apply.go @@ -1,5 +1,5 @@ /* -Copyright 2020 The cert-manager Authors. +Copyright 2022 The cert-manager Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/internal/controller/certificaterequests/apply_test.go b/internal/controller/certificaterequests/apply_test.go index 75b8001db..7c38747d2 100644 --- a/internal/controller/certificaterequests/apply_test.go +++ b/internal/controller/certificaterequests/apply_test.go @@ -1,5 +1,5 @@ /* -Copyright 2020 The cert-manager Authors. +Copyright 2022 The cert-manager Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ limitations under the License. package certificaterequests import ( + "encoding/json" "strconv" "sync" "testing" @@ -56,6 +57,11 @@ func Test_serializeApply(t *testing.T) { assert.NoError(t, err) assert.Regexp(t, expReg, string(reqData)) + // Test round trip preserves the spec and object meta. + var rtReq cmapi.CertificateRequest + assert.NoError(t, json.Unmarshal(reqData, &rtReq)) + assert.Equal(t, req.Spec, rtReq.Spec) + // String match on empty spec. req.Spec = cmapi.CertificateRequestSpec{} reqData, err = serializeApply(&req)