github.com/kubeshop/testkube@v1.17.23/contrib/executor/example/pkg/runner/runner_test.go (about)

     1  package runner
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  
     9  	"github.com/kubeshop/testkube/pkg/api/v1/testkube"
    10  )
    11  
    12  func TestRun(t *testing.T) {
    13  	ctx := context.Background()
    14  
    15  	t.Run("successful result", func(t *testing.T) {
    16  		runner := NewRunner()
    17  		res, err := runner.Run(
    18  			ctx,
    19  			testkube.Execution{
    20  				Content: &testkube.TestContent{
    21  					Uri: "https://testkube.io",
    22  				},
    23  			})
    24  
    25  		assert.NoError(t, err)
    26  		assert.Equal(t, testkube.ExecutionStatusPassed, res.Status)
    27  	})
    28  
    29  	t.Run("failed 404 result", func(t *testing.T) {
    30  		runner := NewRunner()
    31  		res, err := runner.Run(
    32  			ctx,
    33  			testkube.Execution{
    34  				Content: &testkube.TestContent{
    35  					Uri: "https://testkube.io/some-non-existing-uri-blablablabl",
    36  				},
    37  			})
    38  
    39  		assert.NoError(t, err)
    40  		assert.Equal(t, testkube.ExecutionStatusFailed, res.Status)
    41  
    42  	})
    43  
    44  	t.Run("network connection issues returns errors", func(t *testing.T) {
    45  		runner := NewRunner()
    46  		_, err := runner.Run(
    47  			ctx,
    48  			testkube.Execution{
    49  				Content: &testkube.TestContent{
    50  					Uri: "blabla://non-existing-uri",
    51  				},
    52  			})
    53  
    54  		assert.Error(t, err)
    55  	})
    56  
    57  }