-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests of multicluster install command (#7111)
Currently there are no tests of the output of the multicluster install command unlike the install and viz install commands. This makes it error prone to hard to validate changes. This is motivated by the addition of an ha mode to the multicluster components discussed in #7082. This change adds two test cases and refactors the install command to look like viz install making it easily testable. This means in practice that the body of the command is moved into an install function. Here we extract external data, eg. values, and delegates the values to a render function that handles the actual rendering. This is a non-functional change and the output used for the install_default.golden file is based of the main branch to validate this. Signed-off-by: Crevil <[email protected]> (cherry picked from commit fddfb74) Signed-off-by: Oliver Gould <[email protected]>
- Loading branch information
Showing
5 changed files
with
922 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package cmd | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"testing" | ||
|
||
multicluster "github.com/linkerd/linkerd2/multicluster/values" | ||
"github.com/linkerd/linkerd2/pkg/charts" | ||
) | ||
|
||
func TestRender(t *testing.T) { | ||
// pin values that are changed by render functions on each test run | ||
defaultValues := map[string]interface{}{} | ||
|
||
testCases := []struct { | ||
values map[string]interface{} | ||
multiclusterValues *multicluster.Values | ||
goldenFileName string | ||
}{ | ||
{ | ||
nil, | ||
nil, | ||
"install_default.golden", | ||
}, | ||
{ | ||
map[string]interface{}{ | ||
"enablePSP": "true", | ||
}, | ||
nil, | ||
"install_psp.golden", | ||
}, | ||
} | ||
|
||
for i, tc := range testCases { | ||
tc := tc // pin | ||
t.Run(fmt.Sprintf("%d: %s", i, tc.goldenFileName), func(t *testing.T) { | ||
var buf bytes.Buffer | ||
// Merge overrides with default | ||
if err := render(&buf, tc.multiclusterValues, charts.MergeMaps(defaultValues, tc.values)); err != nil { | ||
t.Fatalf("Failed to render templates: %v", err) | ||
} | ||
testDataDiffer.DiffTestdata(t, tc.goldenFileName, buf.String()) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package cmd | ||
|
||
import ( | ||
"flag" | ||
"os" | ||
"testing" | ||
|
||
"github.com/linkerd/linkerd2/testutil" | ||
) | ||
|
||
var ( | ||
testDataDiffer testutil.TestDataDiffer | ||
) | ||
|
||
// TestMain parses flags before running tests | ||
func TestMain(m *testing.M) { | ||
flag.BoolVar(&testDataDiffer.UpdateFixtures, "update", false, "update text fixtures in place") | ||
prettyDiff := os.Getenv("LINKERD_TEST_PRETTY_DIFF") != "" | ||
flag.BoolVar(&testDataDiffer.PrettyDiff, "pretty-diff", prettyDiff, "display the full text when diffing") | ||
flag.StringVar(&testDataDiffer.RejectPath, "reject-path", "", "write results for failed tests to this path (path is relative to the test location)") | ||
flag.Parse() | ||
os.Exit(m.Run()) | ||
} |
Oops, something went wrong.