istio.io/istio@v0.0.0-20240520182934-d79c90f27776/istioctl/pkg/writer/envoy/configdump/secret_test.go (about) 1 // Copyright Istio Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package configdump 16 17 import ( 18 "bytes" 19 "io" 20 "os" 21 "testing" 22 23 "istio.io/istio/pkg/test/util/assert" 24 ) 25 26 func TestSDSWriter_ValidCert(t *testing.T) { 27 configDumpFile, err := os.Open("testdata/secret/config_dump.json") 28 if err != nil { 29 t.Errorf("error opening test data file: %v", err) 30 } 31 defer configDumpFile.Close() 32 configDump, err := io.ReadAll(configDumpFile) 33 if err != nil { 34 t.Errorf("error reading test data file: %v", err) 35 } 36 37 outFile, err := os.Open("testdata/secret/output") 38 if err != nil { 39 t.Errorf("error opening test data output file: %v", err) 40 } 41 defer outFile.Close() 42 expectedOut, err := io.ReadAll(outFile) 43 if err != nil { 44 t.Errorf("error reading test data output file: %v", err) 45 } 46 47 gotOut := &bytes.Buffer{} 48 cw := &ConfigWriter{Stdout: gotOut} 49 err = cw.Prime(configDump) 50 assert.NoError(t, err) 51 err = cw.PrintSecretSummary() 52 assert.NoError(t, err) 53 54 assert.Equal(t, string(expectedOut), gotOut.String()) 55 }