test: extract GenerateCIArtifactName to test helpers

A bit of deduplication can never hurt.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
This commit is contained in:
Ondřej Budai 2020-11-30 10:50:42 +01:00 committed by msehnout
parent 9f80c2ac8e
commit 18258238d9
3 changed files with 24 additions and 33 deletions

View file

@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"fmt"
"io/ioutil"
"net"
"net/http"
@ -226,3 +227,17 @@ func SetUpTemporaryRepository() (string, error) {
func TearDownTemporaryRepository(dir string) error {
return os.RemoveAll(dir)
}
// GenerateCIArtifactName generates a new identifier for CI artifacts which is based
// on environment variables specified by Jenkins
// note: in case of migration to sth else like Github Actions, change it to whatever variables GH Action provides
func GenerateCIArtifactName(prefix string) (string, error) {
distroCode := os.Getenv("DISTRO_CODE")
branchName := os.Getenv("BRANCH_NAME")
buildId := os.Getenv("BUILD_ID")
if branchName == "" || buildId == "" || distroCode == "" {
return "", fmt.Errorf("The environment variables must specify BRANCH_NAME, BUILD_ID, and DISTRO_CODE")
}
return fmt.Sprintf("%s%s-%s-%s", prefix, distroCode, branchName, buildId), nil
}