@@ -2,6 +2,7 @@ package controllers_test
22
33import (
44 "context"
5+ "encoding/base64"
56 "math/rand"
67
78 . "github.com/onsi/ginkgo/v2"
@@ -81,11 +82,9 @@ var _ = Describe("IPFS Reconciler", func() {
8182 It ("creates a new peer ids" , func () {
8283 fn , _ := ipfsReconciler .SecretConfig (ctx , ipfs , secretConfig , clusterSec , bootstrapKey )
8384 Expect (fn ()).To (BeNil ())
84- expectedKeys := int (replicas ) * 2
85- // in the real world, StringData will be copied to Data as part of k8s.
86- // However, we are checking it before it has the opportunity.
87- Expect (len (secretConfig .Data )).To (Equal (alwaysKeys ))
88- Expect (len (secretConfig .StringData )).To (Equal (expectedKeys ))
85+ secretStringToData (secretConfig )
86+ expectedKeys := int (replicas )* 2 + alwaysKeys
87+ Expect (len (secretConfig .Data )).To (Equal (expectedKeys ))
8988
9089 // save this so we can check for changes later.
9190 dataCopy := make (map [string ][]byte )
@@ -101,8 +100,8 @@ var _ = Describe("IPFS Reconciler", func() {
101100 ipfs .Spec .Replicas ++
102101 fn , _ = ipfsReconciler .SecretConfig (ctx , ipfs , secretConfig , clusterSec , bootstrapKey )
103102 Expect (fn ()).To (BeNil ())
104- Expect ( len ( secretConfig . Data )). To ( Equal ( alwaysKeys ) )
105- Expect (len (secretConfig .StringData )).To (Equal (expectedKeys + 2 ))
103+ secretStringToData ( secretConfig )
104+ Expect (len (secretConfig .Data )).To (Equal (alwaysKeys + 2 ))
106105
107106 // expect the old keys to still be the same
108107 for k := range dataCopy {
@@ -114,3 +113,14 @@ var _ = Describe("IPFS Reconciler", func() {
114113 })
115114 })
116115})
116+
117+ // The k8s client will encode and copy data from the StringData to Data
118+ // This function mimics the behavior for tests.
119+ func secretStringToData (secret * v1.Secret ) {
120+ for k , v := range secret .StringData {
121+ var encoded []byte
122+ base64 .StdEncoding .Encode (encoded , []byte (v ))
123+ secret .Data [k ] = encoded
124+ delete (secret .StringData , k )
125+ }
126+ }
0 commit comments