2020-02-18 16:19:50 +02:00
|
|
|
// +build integration
|
|
|
|
// can be execute with go test -tags=integration ./integration/...
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2020-02-27 13:43:38 +02:00
|
|
|
"fmt"
|
|
|
|
"github.com/SAP/jenkins-library/pkg/piperutils"
|
2020-02-18 16:19:50 +02:00
|
|
|
"os"
|
2020-02-27 13:43:38 +02:00
|
|
|
"path"
|
2020-02-18 16:19:50 +02:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/SAP/jenkins-library/pkg/command"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPiperHelp(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
piperHelpCmd := command.Command{}
|
|
|
|
|
|
|
|
var commandOutput bytes.Buffer
|
|
|
|
piperHelpCmd.Stdout(&commandOutput)
|
|
|
|
|
|
|
|
err := piperHelpCmd.RunExecutable(getPiperExecutable(), "--help")
|
|
|
|
|
|
|
|
assert.NoError(t, err, "Calling piper --help failed")
|
|
|
|
assert.Contains(t, commandOutput.String(), "Use \"piper [command] --help\" for more information about a command.")
|
|
|
|
}
|
|
|
|
|
|
|
|
func getPiperExecutable() string {
|
|
|
|
if p := os.Getenv("PIPER_INTEGRATION_EXECUTABLE"); len(p) > 0 {
|
2020-02-27 13:43:38 +02:00
|
|
|
fmt.Println("Piper executable for integration test: " + p)
|
2020-02-18 16:19:50 +02:00
|
|
|
return p
|
|
|
|
}
|
2020-02-27 13:43:38 +02:00
|
|
|
|
|
|
|
f := piperutils.Files{}
|
|
|
|
wd, _ := os.Getwd()
|
|
|
|
localPiper := path.Join(wd, "piper")
|
|
|
|
exists, _ := f.FileExists(localPiper)
|
|
|
|
if exists {
|
|
|
|
fmt.Println("Piper executable for integration test: " + localPiper)
|
|
|
|
return localPiper
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("Piper executable for integration test: Using 'piper' from PATH")
|
2020-02-18 16:19:50 +02:00
|
|
|
return "piper"
|
|
|
|
}
|