github.com/nektos/act@v0.2.63/pkg/runner/step_factory_test.go (about)

     1  package runner
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/nektos/act/pkg/model"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestStepFactoryNewStep(t *testing.T) {
    11  	table := []struct {
    12  		name  string
    13  		model *model.Step
    14  		check func(s step) bool
    15  	}{
    16  		{
    17  			name: "StepRemoteAction",
    18  			model: &model.Step{
    19  				Uses: "remote/action@v1",
    20  			},
    21  			check: func(s step) bool {
    22  				_, ok := s.(*stepActionRemote)
    23  				return ok
    24  			},
    25  		},
    26  		{
    27  			name: "StepLocalAction",
    28  			model: &model.Step{
    29  				Uses: "./action@v1",
    30  			},
    31  			check: func(s step) bool {
    32  				_, ok := s.(*stepActionLocal)
    33  				return ok
    34  			},
    35  		},
    36  		{
    37  			name: "StepDocker",
    38  			model: &model.Step{
    39  				Uses: "docker://image:tag",
    40  			},
    41  			check: func(s step) bool {
    42  				_, ok := s.(*stepDocker)
    43  				return ok
    44  			},
    45  		},
    46  		{
    47  			name: "StepRun",
    48  			model: &model.Step{
    49  				Run: "cmd",
    50  			},
    51  			check: func(s step) bool {
    52  				_, ok := s.(*stepRun)
    53  				return ok
    54  			},
    55  		},
    56  	}
    57  
    58  	for _, tt := range table {
    59  		t.Run(tt.name, func(t *testing.T) {
    60  			sf := &stepFactoryImpl{}
    61  
    62  			step, err := sf.newStep(tt.model, &RunContext{})
    63  
    64  			assert.True(t, tt.check((step)))
    65  			assert.Nil(t, err)
    66  		})
    67  	}
    68  }
    69  
    70  func TestStepFactoryInvalidStep(t *testing.T) {
    71  	model := &model.Step{
    72  		Uses: "remote/action@v1",
    73  		Run:  "cmd",
    74  	}
    75  
    76  	sf := &stepFactoryImpl{}
    77  
    78  	_, err := sf.newStep(model, &RunContext{})
    79  
    80  	assert.Error(t, err)
    81  }