github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/model/operation_test.go (about)

     1  package model_test
     2  
     3  import (
     4  	"encoding/json"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/kyma-incubator/compass/components/director/internal/model"
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestOperationInput_ToOperation(t *testing.T) {
    13  	// GIVEN
    14  	id := "foo"
    15  
    16  	testCases := []struct {
    17  		Name     string
    18  		Input    *model.OperationInput
    19  		Expected *model.Operation
    20  	}{
    21  		{
    22  			Name: "All properties given",
    23  			Input: &model.OperationInput{
    24  				OpType:     "OP_TYPE",
    25  				Status:     "OP_STATUS",
    26  				Data:       json.RawMessage("{}"),
    27  				Error:      json.RawMessage("{}"),
    28  				Priority:   1,
    29  				CreatedAt:  &time.Time{},
    30  				FinishedAt: &time.Time{},
    31  			},
    32  			Expected: &model.Operation{
    33  				ID:         id,
    34  				OpType:     "OP_TYPE",
    35  				Status:     "OP_STATUS",
    36  				Data:       json.RawMessage("{}"),
    37  				Error:      json.RawMessage("{}"),
    38  				Priority:   1,
    39  				CreatedAt:  &time.Time{},
    40  				FinishedAt: &time.Time{},
    41  			},
    42  		},
    43  		{
    44  			Name:     "Nil",
    45  			Input:    nil,
    46  			Expected: nil,
    47  		},
    48  	}
    49  
    50  	for _, testCase := range testCases {
    51  		t.Run(testCase.Name, func(t *testing.T) {
    52  			// WHEN
    53  			result := testCase.Input.ToOperation(id)
    54  
    55  			// THEN
    56  			assert.Equal(t, testCase.Expected, result)
    57  		})
    58  	}
    59  }