2021-04-02 09:01:45 -05:00
package model
import (
"path/filepath"
"testing"
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)
2021-05-03 09:57:24 -05:00
type WorkflowPlanTest struct {
workflowPath string
errorMessage string
noWorkflowRecurse bool
2021-04-02 09:01:45 -05:00
}
func TestPlanner ( t * testing . T ) {
2021-05-03 09:57:24 -05:00
log . SetLevel ( log . DebugLevel )
2021-04-02 09:01:45 -05:00
2021-05-03 09:57:24 -05:00
tables := [ ] WorkflowPlanTest {
{ "invalid-job-name/invalid-1.yml" , "workflow is not valid. 'invalid-job-name-1': Job name 'invalid-JOB-Name-v1.2.3-docker_hub' is invalid. Names must start with a letter or '_' and contain only alphanumeric characters, '-', or '_'" , false } ,
{ "invalid-job-name/invalid-2.yml" , "workflow is not valid. 'invalid-job-name-2': Job name '1234invalid-JOB-Name-v123-docker_hub' is invalid. Names must start with a letter or '_' and contain only alphanumeric characters, '-', or '_'" , false } ,
{ "invalid-job-name/valid-1.yml" , "" , false } ,
{ "invalid-job-name/valid-2.yml" , "" , false } ,
2022-06-10 16:16:42 -05:00
{ "empty-workflow" , "unable to read workflow 'push.yml': file is empty: EOF" , false } ,
{ "nested" , "unable to read workflow 'fail.yml': file is empty: EOF" , false } ,
2021-05-03 09:57:24 -05:00
{ "nested" , "" , true } ,
2021-04-02 09:01:45 -05:00
}
workdir , err := filepath . Abs ( "testdata" )
assert . NoError ( t , err , workdir )
for _ , table := range tables {
fullWorkflowPath := filepath . Join ( workdir , table . workflowPath )
2021-05-03 09:57:24 -05:00
_ , err = NewWorkflowPlanner ( fullWorkflowPath , table . noWorkflowRecurse )
2021-04-02 09:01:45 -05:00
if table . errorMessage == "" {
assert . NoError ( t , err , "WorkflowPlanner should exit without any error" )
} else {
assert . EqualError ( t , err , table . errorMessage )
}
}
}
2023-08-21 12:53:47 -05:00
func TestWorkflow ( t * testing . T ) {
log . SetLevel ( log . DebugLevel )
workflow := Workflow {
Jobs : map [ string ] * Job {
"valid_job" : {
Name : "valid_job" ,
} ,
} ,
}
// Check that an invalid job id returns error
result , err := createStages ( & workflow , "invalid_job_id" )
assert . NotNil ( t , err )
assert . Nil ( t , result )
// Check that an valid job id returns non-error
result , err = createStages ( & workflow , "valid_job" )
assert . Nil ( t , err )
assert . NotNil ( t , result )
}