1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/integration/integration_piper_test.go

128 lines
2.9 KiB
Go
Raw Normal View History

feat(whitesourceExecuteScan): GitHub issue creation + SARIF (#3535) * Add GH issue creation + SARIF * Code cleanup * Fix fmt, add debug * Code enhancements * Fix * Added debug info * Rework UA log scan * Fix code * read UA version * Fix nil reference * Extraction * Credentials * Issue creation * Error handling * Fix issue creation * query escape * Query escape 2 * Revert * Test avoid update * HTTP client * Add support for custom TLS certs * Fix code * Fix code 2 * Fix code 3 * Disable cert check * Fix auth * Remove implicit trust * Skip verification * Fix * Fix client * Fix HTTP auth * Fix trusted certs * Trim version * Code * Add token * Added token handling to client * Fix token * Cleanup * Fix token * Token rework * Fix code * Kick out oauth client * Kick out oauth client * Transport wrapping * Token * Simplification * Refactor * Variation * Check * Fix * Debug * Switch client * Variation * Debug * Switch to cert check * Add debug * Parse self * Cleanup * Update resources/metadata/whitesourceExecuteScan.yaml * Add debug * Expose subjects * Patch * Debug * Debug2 * Debug3 * Fix logging response body * Cleanup * Cleanup * Fix request body logging * Cleanup import * Fix import cycle * Cleanup * Fix fmt * Fix NopCloser reference * Regenerate * Reintroduce * Fix test * Fix tests * Correction * Fix error * Code fix * Fix tests * Add tests * Fix code climate issues * Code climate * Code climate again * Code climate again * Fix fmt * Fix fmt 2 Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2022-02-23 10:30:19 +02:00
//go:build integration
// +build integration
feat(whitesourceExecuteScan): GitHub issue creation + SARIF (#3535) * Add GH issue creation + SARIF * Code cleanup * Fix fmt, add debug * Code enhancements * Fix * Added debug info * Rework UA log scan * Fix code * read UA version * Fix nil reference * Extraction * Credentials * Issue creation * Error handling * Fix issue creation * query escape * Query escape 2 * Revert * Test avoid update * HTTP client * Add support for custom TLS certs * Fix code * Fix code 2 * Fix code 3 * Disable cert check * Fix auth * Remove implicit trust * Skip verification * Fix * Fix client * Fix HTTP auth * Fix trusted certs * Trim version * Code * Add token * Added token handling to client * Fix token * Cleanup * Fix token * Token rework * Fix code * Kick out oauth client * Kick out oauth client * Transport wrapping * Token * Simplification * Refactor * Variation * Check * Fix * Debug * Switch client * Variation * Debug * Switch to cert check * Add debug * Parse self * Cleanup * Update resources/metadata/whitesourceExecuteScan.yaml * Add debug * Expose subjects * Patch * Debug * Debug2 * Debug3 * Fix logging response body * Cleanup * Cleanup * Fix request body logging * Cleanup import * Fix import cycle * Cleanup * Fix fmt * Fix NopCloser reference * Regenerate * Reintroduce * Fix test * Fix tests * Correction * Fix error * Code fix * Fix tests * Add tests * Fix code climate issues * Code climate * Code climate again * Code climate again * Fix fmt * Fix fmt 2 Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2022-02-23 10:30:19 +02:00
// can be executed with
// go test -v -tags integration -run TestPiperIntegration ./integration/...
package main
import (
"bytes"
"fmt"
2020-05-20 13:41:23 +02:00
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
2020-05-20 13:41:23 +02:00
"github.com/SAP/jenkins-library/pkg/command"
"github.com/SAP/jenkins-library/pkg/piperutils"
)
func TestPiperIntegrationHelp(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 {
fmt.Println("Piper executable for integration test: " + p)
return p
}
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")
return "piper"
}
2020-05-20 13:41:23 +02:00
// copyDir copies a directory
func copyDir(source string, target string) error {
var err error
var fileInfo []os.FileInfo
var sourceInfo os.FileInfo
if sourceInfo, err = os.Stat(source); err != nil {
return err
}
if err = os.MkdirAll(target, sourceInfo.Mode()); err != nil {
return err
}
if fileInfo, err = ioutil.ReadDir(source); err != nil {
return err
}
for _, info := range fileInfo {
sourcePath := path.Join(source, info.Name())
targetPath := path.Join(target, info.Name())
if info.IsDir() {
if err = copyDir(sourcePath, targetPath); err != nil {
return err
}
} else {
if err = copyFile(sourcePath, targetPath); err != nil {
return err
}
}
}
return nil
}
func copyFile(source, target string) error {
var err error
var sourceFile *os.File
var targetFile *os.File
var sourceInfo os.FileInfo
if sourceFile, err = os.Open(source); err != nil {
return err
}
defer sourceFile.Close()
if targetFile, err = os.Create(target); err != nil {
return err
}
defer targetFile.Close()
if _, err = io.Copy(targetFile, sourceFile); err != nil {
return err
}
if sourceInfo, err = os.Stat(source); err != nil {
return err
}
return os.Chmod(target, sourceInfo.Mode())
}
// createTmpDir calls t.TempDir() and returns the path name after the evaluation
// of any symbolic links.
//
// On Docker for Mac, t.TempDir() returns e.g.
// /var/folders/bl/wbxjgtzx7j5_mjsmfr3ynlc00000gp/T/<the-test-name>/001
func createTmpDir(t *testing.T) (string, error) {
tmpDir, err := filepath.EvalSymlinks(t.TempDir())
2020-05-20 13:41:23 +02:00
if err != nil {
return "", err
}
return tmpDir, nil
2020-05-20 13:41:23 +02:00
}