mirror of https://github.com/knative/pkg.git
Do not hardcode knative in test/prow library (#1344)
* do not hardcode knative in test/prow library * fix unit test
This commit is contained in:
parent
60f4ae1dbe
commit
3afddc40ce
|
|
@ -34,9 +34,6 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
// OrgName is the name of knative org
|
||||
OrgName = "knative"
|
||||
|
||||
// BucketName is the gcs bucket for all knative builds
|
||||
BucketName = "knative-prow"
|
||||
// Latest is the filename storing latest build number
|
||||
|
|
@ -71,6 +68,7 @@ type Job struct {
|
|||
Name string
|
||||
Type string
|
||||
Bucket string // optional
|
||||
Org string // optional
|
||||
Repo string // optional
|
||||
StoragePath string // optional
|
||||
PullID int // only for Presubmit jobs
|
||||
|
|
@ -135,11 +133,13 @@ func Initialize(serviceAccount string) error {
|
|||
|
||||
// NewJob creates new job struct
|
||||
// pullID is only saved by Presubmit job for determining StoragePath
|
||||
func NewJob(jobName, jobType, repoName string, pullID int) *Job {
|
||||
func NewJob(jobName, jobType, orgName, repoName string, pullID int) *Job {
|
||||
job := Job{
|
||||
Name: jobName,
|
||||
Type: jobType,
|
||||
Bucket: BucketName,
|
||||
Org: orgName,
|
||||
Repo: repoName,
|
||||
}
|
||||
|
||||
switch jobType {
|
||||
|
|
@ -147,7 +147,7 @@ func NewJob(jobName, jobType, repoName string, pullID int) *Job {
|
|||
job.StoragePath = path.Join("logs", jobName)
|
||||
case PresubmitJob:
|
||||
job.PullID = pullID
|
||||
job.StoragePath = path.Join("pr-logs", "pull", OrgName+"_"+repoName, strconv.Itoa(pullID), jobName)
|
||||
job.StoragePath = path.Join("pr-logs", "pull", orgName+"_"+repoName, strconv.Itoa(pullID), jobName)
|
||||
case BatchJob:
|
||||
job.StoragePath = path.Join("pr-logs", "pull", "batch", jobName)
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
orgName = "test-org"
|
||||
repoName = "test-repo"
|
||||
invalidJobType = "invalid"
|
||||
testJobName = "job_0"
|
||||
|
|
@ -35,13 +36,13 @@ var jobPathTests = []struct {
|
|||
}{
|
||||
{PeriodicJob, "logs/job_0"},
|
||||
{PostsubmitJob, "logs/job_0"},
|
||||
{PresubmitJob, "pr-logs/pull/knative_test-repo/0/job_0"},
|
||||
{PresubmitJob, "pr-logs/pull/test-org_test-repo/0/job_0"},
|
||||
{BatchJob, "pr-logs/pull/batch/job_0"},
|
||||
}
|
||||
|
||||
func TestJobPath(t *testing.T) {
|
||||
for _, testData := range jobPathTests {
|
||||
job := NewJob(testJobName, testData.in, repoName, 0)
|
||||
job := NewJob(testJobName, testData.in, orgName, repoName, 0)
|
||||
if job.StoragePath != testData.out {
|
||||
t.Errorf("Expected '%s', actual '%s'", testData.out, job.StoragePath)
|
||||
}
|
||||
|
|
@ -58,7 +59,7 @@ func TestInvalidJobPath(t *testing.T) {
|
|||
exitString = expectedExitString
|
||||
}
|
||||
|
||||
NewJob(testJobName, invalidJobType, repoName, 0)
|
||||
NewJob(testJobName, invalidJobType, orgName, repoName, 0)
|
||||
if exitString != expectedExitString {
|
||||
t.Fatalf("Expected: %s, actual: %s", exitString, expectedExitString)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue