Skip to content

Commit

Permalink
Un-randomize TestConvertScripts_WithBreakpoint_OnFailure
Browse files Browse the repository at this point in the history
Prior to this commit we iterated over a map when building up the args
passed to a step container with debug breakpoint enabled. Map iteration
can be random, so sometimes our unit tests would flake out.

This commit switches the map to a list and uses a struct to provide
the fields as the key/values from the map.
  • Loading branch information
Scott authored and tekton-robot committed Aug 30, 2021
1 parent 8afd156 commit c8c7291
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions pkg/pod/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,29 +176,25 @@ cat > ${scriptfile} << '%s'

// Place debug scripts if breakpoints are enabled
if len(breakpoints) > 0 {
// Debug script names
debugContinueScriptName := "continue"
debugFailContinueScriptName := "fail-continue"

// debugContinueScript can be used by the user to mark the failing step as a success
debugContinueScript := defaultScriptPreamble + fmt.Sprintf(debugContinueScriptTemplate, len(steps), debugInfoDir, mountPoint)

// debugFailContinueScript can be used by the user to mark the failing step as a failure
debugFailContinueScript := defaultScriptPreamble + fmt.Sprintf(debugFailScriptTemplate, len(steps), debugInfoDir, mountPoint)

// Script names and their content
debugScripts := map[string]string{
debugContinueScriptName: debugContinueScript,
debugFailContinueScriptName: debugFailContinueScript,
type script struct {
name string
content string
}
debugScripts := []script{{
name: "continue",
content: defaultScriptPreamble + fmt.Sprintf(debugContinueScriptTemplate, len(steps), debugInfoDir, mountPoint),
}, {
name: "fail-continue",
content: defaultScriptPreamble + fmt.Sprintf(debugFailScriptTemplate, len(steps), debugInfoDir, mountPoint),
}}

// Add debug or breakpoint related scripts to /tekton/debug/scripts
// Iterate through the debugScripts and add routine for each of them in the initContainer for their creation
for debugScriptName, debugScript := range debugScripts {
tmpFile := filepath.Join(debugScriptsDir, fmt.Sprintf("%s-%s", "debug", debugScriptName))
heredoc := names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(fmt.Sprintf("%s-%s-heredoc-randomly-generated", "debug", debugScriptName))
for _, debugScript := range debugScripts {
tmpFile := filepath.Join(debugScriptsDir, fmt.Sprintf("%s-%s", "debug", debugScript.name))
heredoc := names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(fmt.Sprintf("%s-%s-heredoc-randomly-generated", "debug", debugScript.name))

initContainer.Args[1] += fmt.Sprintf(initScriptDirective, tmpFile, heredoc, debugScript, heredoc)
initContainer.Args[1] += fmt.Sprintf(initScriptDirective, tmpFile, heredoc, debugScript.content, heredoc)
}

}
Expand Down

0 comments on commit c8c7291

Please sign in to comment.