mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
a1988f6808
* 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>
97 lines
2.4 KiB
Go
97 lines
2.4 KiB
Go
//go:build integration
|
|
// +build integration
|
|
|
|
// can be execute with go test -tags=integration ./integration/...
|
|
|
|
package main
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/SAP/jenkins-library/pkg/command"
|
|
pipergithub "github.com/SAP/jenkins-library/pkg/github"
|
|
"github.com/SAP/jenkins-library/pkg/piperenv"
|
|
)
|
|
|
|
func TestPiperGithubPublishRelease(t *testing.T) {
|
|
t.Parallel()
|
|
token := os.Getenv("PIPER_INTEGRATION_GITHUB_TOKEN")
|
|
if len(token) == 0 {
|
|
t.Fatal("No GitHub token maintained")
|
|
}
|
|
|
|
owner := os.Getenv("PIPER_INTEGRATION_GITHUB_OWNER")
|
|
if len(owner) == 0 {
|
|
owner = "OliverNocon"
|
|
}
|
|
repository := os.Getenv("PIPER_INTEGRATION_GITHUB_REPOSITORY")
|
|
if len(repository) == 0 {
|
|
repository = "piper-integration"
|
|
}
|
|
|
|
dir, err := ioutil.TempDir("", "")
|
|
defer os.RemoveAll(dir) // clean up
|
|
assert.NoError(t, err, "Error when creating temp dir")
|
|
|
|
testAsset := filepath.Join(dir, "test.txt")
|
|
err = ioutil.WriteFile(testAsset, []byte("Test"), 0644)
|
|
assert.NoError(t, err, "Error when writing temporary file")
|
|
|
|
//prepare pipeline environment
|
|
now := time.Now()
|
|
piperenv.SetResourceParameter(filepath.Join(dir, ".pipeline"), "commonPipelineEnvironment", "artifactVersion", now.Format("20060102150405"))
|
|
|
|
cmd := command.Command{}
|
|
cmd.SetDir(dir)
|
|
|
|
piperOptions := []string{
|
|
"githubPublishRelease",
|
|
"--owner",
|
|
owner,
|
|
"--repository",
|
|
repository,
|
|
"--token",
|
|
token,
|
|
"--assetPath",
|
|
testAsset,
|
|
"--noTelemetry",
|
|
}
|
|
|
|
err = cmd.RunExecutable(getPiperExecutable(), piperOptions...)
|
|
assert.NoError(t, err, "Calling piper with arguments %v failed.", piperOptions)
|
|
}
|
|
|
|
func TestGithubFetchCommitStatistics(t *testing.T) {
|
|
t.Parallel()
|
|
// prepare
|
|
token := os.Getenv("PIPER_INTEGRATION_GITHUB_TOKEN")
|
|
if len(token) == 0 {
|
|
t.Fatal("No GitHub token maintained")
|
|
}
|
|
|
|
owner := os.Getenv("PIPER_INTEGRATION_GITHUB_OWNER")
|
|
if len(owner) == 0 {
|
|
owner = "OliverNocon"
|
|
}
|
|
repository := os.Getenv("PIPER_INTEGRATION_GITHUB_REPOSITORY")
|
|
if len(repository) == 0 {
|
|
repository = "piper-integration"
|
|
}
|
|
// test
|
|
result, err := pipergithub.FetchCommitStatistics(&pipergithub.FetchCommitOptions{
|
|
Owner: owner, Repository: repository, APIURL: "https://api.github.com", Token: token, SHA: "3601ed6"})
|
|
|
|
// assert
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, 2, result.Additions)
|
|
assert.Equal(t, 0, result.Deletions)
|
|
assert.Equal(t, 2, result.Total)
|
|
assert.Equal(t, 1, result.Files)
|
|
}
|