github.com/kubeshop/testkube@v1.17.23/contrib/executor/postman/pkg/runner/newman/mapper_test.go (about)

     1  package newman
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  
     8  	"github.com/kubeshop/testkube/pkg/api/v1/testkube"
     9  )
    10  
    11  func TestMapNewmanMetadataToResult(t *testing.T) {
    12  
    13  	t.Run("timings", func(t *testing.T) {
    14  
    15  		newmanResult := NewmanExecutionResult{
    16  			Output: "output",
    17  			Metadata: ExecutionJSONResult{
    18  				Run: Run{
    19  					Timings: RunTimings{
    20  						Started:   1,
    21  						Completed: 60,
    22  					},
    23  					Failures: []Failure{},
    24  				},
    25  			},
    26  		}
    27  
    28  		result := MapMetadataToResult(newmanResult)
    29  
    30  		assert.Equal(t, testkube.PASSED_ExecutionStatus, *result.Status)
    31  		assert.Equal(t, newmanResult.Output, result.Output)
    32  		assert.Equal(t, "text/plain", result.OutputType)
    33  	})
    34  
    35  	t.Run("check success result", func(t *testing.T) {
    36  
    37  		newmanResult := NewmanExecutionResult{
    38  			Output: "some text result",
    39  			Metadata: ExecutionJSONResult{
    40  				Run: Run{
    41  					Timings: RunTimings{
    42  						Started:   1,
    43  						Completed: 60,
    44  					},
    45  					Failures: []Failure{},
    46  				},
    47  			},
    48  		}
    49  
    50  		result := MapMetadataToResult(newmanResult)
    51  
    52  		assert.Equal(t, "passed", string(*result.Status), "no failures, expecting success status")
    53  	})
    54  
    55  	t.Run("check for failures", func(t *testing.T) {
    56  		newmanResult := NewmanExecutionResult{
    57  			Metadata: ExecutionJSONResult{
    58  				Run: Run{
    59  					Timings: RunTimings{
    60  						Started:   1,
    61  						Completed: 60,
    62  					},
    63  					Failures: []Failure{
    64  						{
    65  							Error: FailureError{
    66  								Name:      "AssertionError",
    67  								Index:     0,
    68  								Test:      "Environment variables are set",
    69  								Message:   "expected undefined to equal 'dupa'",
    70  								Stack:     "AssertionError: expected undefined to equal 'dupa'\n   at Object.eval sandbox-script.js:1:1)",
    71  								Checksum:  "85bbd591a93fc0aa946f5db3fe3033c3",
    72  								ID:        "33d4aa87-7911-4b60-b545-4fc1e20d671d",
    73  								Timestamp: 1628767471559,
    74  							},
    75  						},
    76  					},
    77  				},
    78  			},
    79  		}
    80  
    81  		result := MapMetadataToResult(newmanResult)
    82  
    83  		assert.Equal(t, "failed", string(*result.Status), "failure, expecting failed status")
    84  	})
    85  
    86  	t.Run("steps mappings", func(t *testing.T) {
    87  
    88  		newmanResult := NewmanExecutionResult{
    89  			Metadata: ExecutionJSONResult{
    90  				Run: Run{
    91  					Timings: RunTimings{
    92  						Started:   1,
    93  						Completed: 60,
    94  					},
    95  					Failures: []Failure{
    96  						{
    97  							Error: FailureError{
    98  								Name:      "AssertionError",
    99  								Index:     0,
   100  								Test:      "Environment variables are set",
   101  								Message:   "expected undefined to equal 'dupa'",
   102  								Stack:     "AssertionError: expected undefined to equal 'dupa'\n   at Object.eval sandbox-script.js:1:1)",
   103  								Checksum:  "85bbd591a93fc0aa946f5db3fe3033c3",
   104  								ID:        "33d4aa87-7911-4b60-b545-4fc1e20d671d",
   105  								Timestamp: 1628767471559,
   106  							},
   107  						},
   108  					},
   109  
   110  					Executions: []Execution{
   111  						{
   112  							Item: Item{
   113  								Name: "Users details for use exu",
   114  							},
   115  							Assertions: []Assertion{
   116  								{
   117  									Assertion: "User details page renders correctly",
   118  									Skipped:   false,
   119  								},
   120  								{
   121  									Assertion: "User id should be greater than 0",
   122  									Skipped:   false,
   123  									Error: &RunError{
   124  										Name:    "AssertionError",
   125  										Index:   0,
   126  										Test:    "User id should be greater than 0",
   127  										Message: "expected undefined to be greater than 0",
   128  										Stack:   "AssertionError: expected undefined to be greater than 0\n   at Object.eval sandbox-script.js:1:1)",
   129  									},
   130  								},
   131  							},
   132  						},
   133  						{
   134  							Item: Item{
   135  								Name: "User friends list",
   136  							},
   137  							Assertions: []Assertion{
   138  								{
   139  									Assertion: "List should have user phone",
   140  									Skipped:   false,
   141  									Error: &RunError{
   142  										Name:    "AssertionError",
   143  										Index:   0,
   144  										Test:    "Phone exists on list",
   145  										Message: "can't find phone pattern on list",
   146  										Stack:   "AssertionError: can't find phone pattern on list\n   at Object.eval sandbox-script.js:1:1)",
   147  									},
   148  								},
   149  							},
   150  						},
   151  						{
   152  							Item: Item{
   153  								Name: "User friends list",
   154  							},
   155  							Assertions: []Assertion{
   156  								{
   157  									Assertion: "User should have at least one friend added",
   158  									Skipped:   false,
   159  								},
   160  								{
   161  									Assertion: "List should be visible",
   162  									Skipped:   false,
   163  								},
   164  							},
   165  						},
   166  					},
   167  				},
   168  			},
   169  		}
   170  
   171  		result := MapMetadataToResult(newmanResult)
   172  
   173  		assert.Equal(t, "failed", string(*result.Status), "expecting failed status")
   174  		assert.Equal(t, "failed", result.Steps[0].Status)
   175  		assert.Equal(t, "failed", result.Steps[1].Status)
   176  		assert.Equal(t, "passed", result.Steps[2].Status)
   177  	})
   178  
   179  }