generated from QubitPi/packer-plugin-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests to internal shell command executor (#31)
- Loading branch information
Showing
5 changed files
with
90 additions
and
37 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
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,37 @@ | ||
// Copyright (c) Jiaqi Liu | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package shell | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func Test_loadCommandsIntoScript(t *testing.T) { | ||
actualScript, err := loadCommandsIntoScript([]string{ | ||
"sudo apt update && sudo apt upgrade -y", | ||
"sudo apt install software-properties-common -y", | ||
}) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
defer os.Remove(actualScript.Name()) | ||
|
||
b, err := os.ReadFile(actualScript.Name()) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
expectedScript := `#!/bin/bash | ||
set -x | ||
set -e | ||
sudo apt update && sudo apt upgrade -y | ||
sudo apt install software-properties-common -y | ||
` | ||
|
||
if string(b) != expectedScript { | ||
t.Errorf("Expected and actual scripts do not match: %s\n\n%s", expectedScript, string(b)) | ||
} | ||
} |
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