|
| 1 | +// Copyright 2019 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 mesh |
| 16 | + |
| 17 | +import ( |
| 18 | + "path/filepath" |
| 19 | + "testing" |
| 20 | + |
| 21 | + "istio.io/operator/pkg/util" |
| 22 | +) |
| 23 | + |
| 24 | +func TestProfileDump(t *testing.T) { |
| 25 | + testDataDir = filepath.Join(repoRootDir, "cmd/mesh/testdata/profile-dump") |
| 26 | + tests := []struct { |
| 27 | + desc string |
| 28 | + }{ |
| 29 | + { |
| 30 | + desc: "all_off", |
| 31 | + }, |
| 32 | + { |
| 33 | + desc: "demo-auth_certmanager_on", |
| 34 | + }, |
| 35 | + { |
| 36 | + desc: "sds_policy_off", |
| 37 | + }, |
| 38 | + } |
| 39 | + for _, tt := range tests { |
| 40 | + t.Run(tt.desc, func(t *testing.T) { |
| 41 | + inPath := filepath.Join(testDataDir, "input", tt.desc+".yaml") |
| 42 | + outPath := filepath.Join(testDataDir, "output", tt.desc+".yaml") |
| 43 | + |
| 44 | + got, err := runProfileDump(inPath) |
| 45 | + if err != nil { |
| 46 | + t.Fatal(err) |
| 47 | + } |
| 48 | + want, err := readFile(outPath) |
| 49 | + if err != nil { |
| 50 | + t.Fatal(err) |
| 51 | + } |
| 52 | + if !util.IsYAMLEqual(got, want) { |
| 53 | + t.Errorf("profile-dump command(%s): got:\n%s\n\nwant:\n%s\nDiff:\n%s\n", tt.desc, got, want, util.YAMLDiff(got, want)) |
| 54 | + } |
| 55 | + }) |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +func runProfileDump(path string) (string, error) { |
| 60 | + return runCommand("profile dump -f " + path) |
| 61 | +} |
0 commit comments