2018-05-22 21:43:36 +02:00
|
|
|
// Copyright 2016-2018, Pulumi Corporation.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
|
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/pulumi/pulumi/pkg/util/cmdutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
// RunCommand executes the specified command and additional arguments, wrapping any output in the
|
|
|
|
// specialized test output streams that list the location the test is running in.
|
|
|
|
func RunCommand(t *testing.T, name string, args []string, wd string, opts *ProgramTestOptions) error {
|
|
|
|
path := args[0]
|
|
|
|
command := strings.Join(args, " ")
|
2018-01-17 02:32:49 +01:00
|
|
|
fprintf(opts.Stdout, "**** Invoke '%v' in '%v'\n", command, wd)
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
|
|
|
|
// Spawn a goroutine to print out "still running..." messages.
|
|
|
|
finished := false
|
2019-01-26 01:34:37 +01:00
|
|
|
defer func() { finished = true }()
|
|
|
|
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
go func() {
|
|
|
|
for !finished {
|
2019-03-30 01:34:16 +01:00
|
|
|
time.Sleep(120 * time.Second)
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
if !finished {
|
2018-01-17 02:32:49 +01:00
|
|
|
fprintf(opts.Stderr, "Still running command '%s' (%s)...\n", command, wd)
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2018-04-05 00:31:01 +02:00
|
|
|
env := os.Environ()
|
|
|
|
if opts.Env != nil {
|
|
|
|
env = append(env, opts.Env...)
|
|
|
|
}
|
2019-04-19 00:25:15 +02:00
|
|
|
env = append(env, "PULUMI_DEBUG_COMMANDS=true")
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
env = append(env, "PULUMI_RETAIN_CHECKPOINTS=true")
|
|
|
|
env = append(env, "PULUMI_CONFIG_PASSPHRASE=correct horse battery staple")
|
|
|
|
|
|
|
|
cmd := exec.Cmd{
|
|
|
|
Path: path,
|
|
|
|
Dir: wd,
|
|
|
|
Args: args,
|
|
|
|
Env: env,
|
|
|
|
}
|
|
|
|
|
|
|
|
startTime := time.Now()
|
|
|
|
|
|
|
|
var runout []byte
|
|
|
|
var runerr error
|
|
|
|
if opts.Verbose || os.Getenv("PULUMI_VERBOSE_TEST") != "" {
|
|
|
|
cmd.Stdout = opts.Stdout
|
|
|
|
cmd.Stderr = opts.Stderr
|
|
|
|
runerr = cmd.Run()
|
|
|
|
} else {
|
|
|
|
runout, runerr = cmd.CombinedOutput()
|
|
|
|
}
|
|
|
|
|
|
|
|
endTime := time.Now()
|
|
|
|
|
|
|
|
if opts.ReportStats != nil {
|
|
|
|
// Note: This data is archived and used by external analytics tools. Take care if changing the schema or format
|
|
|
|
// of this data.
|
|
|
|
opts.ReportStats.ReportCommand(TestCommandStats{
|
|
|
|
StartTime: startTime.Format("2006/01/02 15:04:05"),
|
|
|
|
EndTime: endTime.Format("2006/01/02 15:04:05"),
|
|
|
|
ElapsedSeconds: float64((endTime.Sub(startTime)).Nanoseconds()) / 1000000000,
|
|
|
|
StepName: name,
|
|
|
|
CommandLine: command,
|
|
|
|
StackName: string(opts.GetStackName()),
|
|
|
|
TestID: wd,
|
|
|
|
TestName: filepath.Base(opts.Dir),
|
|
|
|
IsError: runerr != nil,
|
2018-01-30 22:10:32 +01:00
|
|
|
CloudURL: opts.CloudURL,
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
if runerr != nil {
|
2018-01-17 02:32:49 +01:00
|
|
|
fprintf(opts.Stderr, "Invoke '%v' failed: %s\n", command, cmdutil.DetailedError(runerr))
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
|
|
|
|
if !opts.Verbose {
|
|
|
|
// We've seen long fprintf's fail on Travis, so avoid panicing.
|
|
|
|
if _, err := fmt.Fprintf(opts.Stderr, "%s\n", string(runout)); err != nil {
|
2018-01-17 02:32:49 +01:00
|
|
|
fprintf(opts.Stderr, "\n\nOutput truncated: %v\n", err)
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we collected any program output, write it to a log file -- success or failure.
|
|
|
|
if len(runout) > 0 {
|
|
|
|
if logFile, err := writeCommandOutput(name, wd, runout); err != nil {
|
2018-01-17 02:32:49 +01:00
|
|
|
fprintf(opts.Stderr, "Failed to write output: %v\n", err)
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
} else {
|
2018-01-17 02:32:49 +01:00
|
|
|
fprintf(opts.Stderr, "Wrote output to %s\n", logFile)
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
}
|
2019-01-26 01:34:37 +01:00
|
|
|
} else {
|
|
|
|
fprintf(opts.Stderr, "Command completed without output\n")
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return runerr
|
|
|
|
}
|
|
|
|
|
|
|
|
func withOptionalYarnFlags(args []string) []string {
|
|
|
|
flags := os.Getenv("YARNFLAGS")
|
|
|
|
|
|
|
|
if flags != "" {
|
|
|
|
return append(args, flags)
|
|
|
|
}
|
|
|
|
|
|
|
|
return args
|
|
|
|
}
|
|
|
|
|
|
|
|
// addFlagIfNonNil will take a set of command-line flags, and add a new one if the provided flag value is not empty.
|
|
|
|
func addFlagIfNonNil(args []string, flag, flagValue string) []string {
|
|
|
|
if flagValue != "" {
|
|
|
|
args = append(args, flag, flagValue)
|
|
|
|
}
|
|
|
|
return args
|
|
|
|
}
|