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_api_test.go
Oliver Nocon eef3bcde60
Add step for GitHub branch protection check (2) (#2016)
* add step for GitHub branch protection check

* add command to piper command

* remove unnecessary parameter

* Update resources/metadata/githubbranchprotection.yaml

* add groovy part

* update generation & go mod tidy

* update groovy tests

* fix bug with go-github version

* Add step to check GitHub branch protection settings

* include PR review feedabck

Co-authored-by: Sven Merk <33895725+nevskrem@users.noreply.github.com>
2020-09-14 12:05:12 +02:00

65 lines
1.5 KiB
Go

// +build integration
// can be execute with go test -tags=integration ./integration/...
package main
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"time"
"github.com/SAP/jenkins-library/pkg/command"
"github.com/SAP/jenkins-library/pkg/piperenv"
"github.com/stretchr/testify/assert"
)
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)
}