github.com/kubeshop/testkube@v1.17.23/contrib/executor/jmeterd/pkg/parser/parser_test.go (about)

     1  package parser
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestParseJTLReport(t *testing.T) {
    11  	t.Parallel()
    12  
    13  	tests := []struct {
    14  		name      string
    15  		input     string
    16  		wantError bool
    17  		notEmpty  bool
    18  	}{
    19  		{
    20  			name:      "errored XML report",
    21  			input:     errorXML,
    22  			wantError: true,
    23  			notEmpty:  false,
    24  		},
    25  		{
    26  			name:      "errored CSV report",
    27  			input:     errorCSV,
    28  			wantError: true,
    29  			notEmpty:  false,
    30  		},
    31  		{
    32  			name:      "success XML report",
    33  			input:     successXML,
    34  			wantError: false,
    35  			notEmpty:  true,
    36  		},
    37  		{
    38  			name:      "success CSV report",
    39  			input:     successCSV,
    40  			wantError: false,
    41  			notEmpty:  true,
    42  		},
    43  	}
    44  
    45  	for i := range tests {
    46  		tt := tests[i]
    47  		t.Run(tt.name, func(t *testing.T) {
    48  			t.Parallel()
    49  
    50  			output := []byte("test completed\n")
    51  			result, err := ParseJTLReport(strings.NewReader(tt.input), output)
    52  
    53  			if tt.wantError {
    54  				assert.ErrorIs(t, err, ErrEmptyReport)
    55  			} else {
    56  				assert.NoError(t, err)
    57  			}
    58  
    59  			if tt.notEmpty {
    60  				assert.NotEmpty(t, result)
    61  			} else {
    62  				assert.Empty(t, result)
    63  			}
    64  		})
    65  	}
    66  }