|
|
@ -14,14 +14,15 @@ See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
package main
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"bytes"
|
|
|
|
"io"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
|
|
|
|
"runtime"
|
|
|
|
// "os/exec"
|
|
|
|
|
|
|
|
// "runtime"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
|
@ -97,7 +98,7 @@ func executeActionCommandStdinC(store *storage.Storage, in *os.File, cmd string)
|
|
|
|
Log: func(format string, v ...interface{}) {},
|
|
|
|
Log: func(format string, v ...interface{}) {},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
root, err := newRootCmd(actionConfig, buf, args)
|
|
|
|
root, err := NewRootCmd(actionConfig, settings, buf, args)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, "", err
|
|
|
|
return nil, "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -165,58 +166,59 @@ func testChdir(t *testing.T, dir string) func() {
|
|
|
|
return func() { os.Chdir(old) }
|
|
|
|
return func() { os.Chdir(old) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestPluginExitCode(t *testing.T) {
|
|
|
|
// TODO(eddiezane): can't call main like this anymore
|
|
|
|
if os.Getenv("RUN_MAIN_FOR_TESTING") == "1" {
|
|
|
|
// func TestPluginExitCode(t *testing.T) {
|
|
|
|
os.Args = []string{"helm", "exitwith", "2"}
|
|
|
|
// if os.Getenv("RUN_MAIN_FOR_TESTING") == "1" {
|
|
|
|
|
|
|
|
// os.Args = []string{"helm", "exitwith", "2"}
|
|
|
|
// We DO call helm's main() here. So this looks like a normal `helm` process.
|
|
|
|
//
|
|
|
|
main()
|
|
|
|
// // We DO call helm's main() here. So this looks like a normal `helm` process.
|
|
|
|
|
|
|
|
// main()
|
|
|
|
// As main calls os.Exit, we never reach this line.
|
|
|
|
//
|
|
|
|
// But the test called this block of code catches and verifies the exit code.
|
|
|
|
// // As main calls os.Exit, we never reach this line.
|
|
|
|
return
|
|
|
|
// // But the test called this block of code catches and verifies the exit code.
|
|
|
|
}
|
|
|
|
// return
|
|
|
|
|
|
|
|
// }
|
|
|
|
// Currently, plugins assume a Linux subsystem. Skip the execution
|
|
|
|
//
|
|
|
|
// tests until this is fixed
|
|
|
|
// // Currently, plugins assume a Linux subsystem. Skip the execution
|
|
|
|
if runtime.GOOS != "windows" {
|
|
|
|
// // tests until this is fixed
|
|
|
|
// Do a second run of this specific test(TestPluginExitCode) with RUN_MAIN_FOR_TESTING=1 set,
|
|
|
|
// if runtime.GOOS != "windows" {
|
|
|
|
// So that the second run is able to run main() and this first run can verify the exit status returned by that.
|
|
|
|
// // Do a second run of this specific test(TestPluginExitCode) with RUN_MAIN_FOR_TESTING=1 set,
|
|
|
|
//
|
|
|
|
// // So that the second run is able to run main() and this first run can verify the exit status returned by that.
|
|
|
|
// This technique originates from https://talks.golang.org/2014/testing.slide#23.
|
|
|
|
// //
|
|
|
|
cmd := exec.Command(os.Args[0], "-test.run=TestPluginExitCode")
|
|
|
|
// // This technique originates from https://talks.golang.org/2014/testing.slide#23.
|
|
|
|
cmd.Env = append(
|
|
|
|
// cmd := exec.Command(os.Args[0], "-test.run=TestPluginExitCode")
|
|
|
|
os.Environ(),
|
|
|
|
// cmd.Env = append(
|
|
|
|
"RUN_MAIN_FOR_TESTING=1",
|
|
|
|
// os.Environ(),
|
|
|
|
// See pkg/cli/environment.go for which envvars can be used for configuring these passes
|
|
|
|
// "RUN_MAIN_FOR_TESTING=1",
|
|
|
|
// and also see plugin_test.go for how a plugin env can be set up.
|
|
|
|
// // See pkg/cli/environment.go for which envvars can be used for configuring these passes
|
|
|
|
// We just does the same setup as plugin_test.go via envvars
|
|
|
|
// // and also see plugin_test.go for how a plugin env can be set up.
|
|
|
|
"HELM_PLUGINS=testdata/helmhome/helm/plugins",
|
|
|
|
// // We just does the same setup as plugin_test.go via envvars
|
|
|
|
"HELM_REPOSITORY_CONFIG=testdata/helmhome/helm/repositories.yaml",
|
|
|
|
// "HELM_PLUGINS=testdata/helmhome/helm/plugins",
|
|
|
|
"HELM_REPOSITORY_CACHE=testdata/helmhome/helm/repository",
|
|
|
|
// "HELM_REPOSITORY_CONFIG=testdata/helmhome/helm/repositories.yaml",
|
|
|
|
)
|
|
|
|
// "HELM_REPOSITORY_CACHE=testdata/helmhome/helm/repository",
|
|
|
|
stdout := &bytes.Buffer{}
|
|
|
|
// )
|
|
|
|
stderr := &bytes.Buffer{}
|
|
|
|
// stdout := &bytes.Buffer{}
|
|
|
|
cmd.Stdout = stdout
|
|
|
|
// stderr := &bytes.Buffer{}
|
|
|
|
cmd.Stderr = stderr
|
|
|
|
// cmd.Stdout = stdout
|
|
|
|
err := cmd.Run()
|
|
|
|
// cmd.Stderr = stderr
|
|
|
|
exiterr, ok := err.(*exec.ExitError)
|
|
|
|
// err := cmd.Run()
|
|
|
|
|
|
|
|
// exiterr, ok := err.(*exec.ExitError)
|
|
|
|
if !ok {
|
|
|
|
//
|
|
|
|
t.Fatalf("Unexpected error returned by os.Exit: %T", err)
|
|
|
|
// if !ok {
|
|
|
|
}
|
|
|
|
// t.Fatalf("Unexpected error returned by os.Exit: %T", err)
|
|
|
|
|
|
|
|
// }
|
|
|
|
if stdout.String() != "" {
|
|
|
|
//
|
|
|
|
t.Errorf("Expected no write to stdout: Got %q", stdout.String())
|
|
|
|
// if stdout.String() != "" {
|
|
|
|
}
|
|
|
|
// t.Errorf("Expected no write to stdout: Got %q", stdout.String())
|
|
|
|
|
|
|
|
// }
|
|
|
|
expectedStderr := "Error: plugin \"exitwith\" exited with error\n"
|
|
|
|
//
|
|
|
|
if stderr.String() != expectedStderr {
|
|
|
|
// expectedStderr := "Error: plugin \"exitwith\" exited with error\n"
|
|
|
|
t.Errorf("Expected %q written to stderr: Got %q", expectedStderr, stderr.String())
|
|
|
|
// if stderr.String() != expectedStderr {
|
|
|
|
}
|
|
|
|
// t.Errorf("Expected %q written to stderr: Got %q", expectedStderr, stderr.String())
|
|
|
|
|
|
|
|
// }
|
|
|
|
if exiterr.ExitCode() != 2 {
|
|
|
|
//
|
|
|
|
t.Errorf("Expected exit code 2: Got %d", exiterr.ExitCode())
|
|
|
|
// if exiterr.ExitCode() != 2 {
|
|
|
|
}
|
|
|
|
// t.Errorf("Expected exit code 2: Got %d", exiterr.ExitCode())
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|