github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/orchestration/handlers/converter_test.go (about) 1 package handlers_test 2 3 import ( 4 "testing" 5 6 "github.com/kyma-project/control-plane/components/provisioner/pkg/gqlschema" 7 "github.com/kyma-project/kyma-environment-broker/internal" 8 "github.com/kyma-project/kyma-environment-broker/internal/fixture" 9 "github.com/kyma-project/kyma-environment-broker/internal/orchestration/handlers" 10 "github.com/stretchr/testify/assert" 11 "github.com/stretchr/testify/require" 12 ) 13 14 func TestConverter_OrchestrationToDTO(t *testing.T) { 15 // given 16 c := handlers.Converter{} 17 18 id := "id" 19 givenOrchestration := &internal.Orchestration{OrchestrationID: id} 20 stats := map[string]int{"in progress": 5, "succeeded": 3} 21 22 // when 23 resp, err := c.OrchestrationToDTO(givenOrchestration, stats) 24 25 // then 26 require.NoError(t, err) 27 assert.Equal(t, id, resp.OrchestrationID) 28 assert.Equal(t, stats, resp.OperationStats) 29 } 30 31 func TestConverter_OrchestrationListToDTO(t *testing.T) { 32 // given 33 c := handlers.Converter{} 34 35 id := "id" 36 givenOrchestration := []internal.Orchestration{{OrchestrationID: id}} 37 38 // when 39 resp, err := c.OrchestrationListToDTO(givenOrchestration, 1, 5) 40 41 // then 42 require.NoError(t, err) 43 assert.Equal(t, len(givenOrchestration), len(resp.Data)) 44 assert.Equal(t, id, resp.Data[0].OrchestrationID) 45 assert.Equal(t, 1, resp.Count) 46 assert.Equal(t, 5, resp.TotalCount) 47 } 48 49 func TestConverter_UpgradeKymaOperationToDTO(t *testing.T) { 50 // given 51 c := handlers.Converter{} 52 53 id := "id" 54 givenOperation := fixUpgradeKymaOperation(id) 55 56 // when 57 resp, err := c.UpgradeKymaOperationToDTO(givenOperation) 58 59 // then 60 require.NoError(t, err) 61 assert.Equal(t, id, resp.OrchestrationID) 62 } 63 64 func TestConverter_UpgradeKymaOperationListToDTO(t *testing.T) { 65 // given 66 c := handlers.Converter{} 67 68 id := "id" 69 givenOperations := []internal.UpgradeKymaOperation{ 70 fixUpgradeKymaOperation(id), 71 fixUpgradeKymaOperation("another"), 72 } 73 74 // when 75 resp, err := c.UpgradeKymaOperationListToDTO(givenOperations, 2, 5) 76 77 // then 78 require.NoError(t, err) 79 require.Len(t, resp.Data, 2) 80 assert.Equal(t, id, resp.Data[0].OrchestrationID) 81 assert.Equal(t, 2, resp.Count) 82 assert.Equal(t, 5, resp.TotalCount) 83 } 84 85 func TestConverter_UpgradeKymaOperationToDetailDTO(t *testing.T) { 86 // given 87 c := handlers.Converter{} 88 89 id := "id" 90 givenOperation := fixUpgradeKymaOperation(id) 91 kymaConfig := gqlschema.KymaConfigInput{Version: id} 92 93 // when 94 resp, err := c.UpgradeKymaOperationToDetailDTO(givenOperation, &kymaConfig) 95 96 // then 97 require.NoError(t, err) 98 assert.Equal(t, id, resp.OrchestrationID) 99 assert.Equal(t, id, resp.KymaConfig.Version) 100 } 101 102 func fixUpgradeKymaOperation(id string) internal.UpgradeKymaOperation { 103 upgradeOperation := fixture.FixUpgradeKymaOperation("", "") 104 upgradeOperation.OrchestrationID = id 105 106 return upgradeOperation 107 } 108 109 func TestConverter_UpgradeClusterOperationToDTO(t *testing.T) { 110 // given 111 c := handlers.Converter{} 112 113 id := "id" 114 givenOperation := fixUpgradeClusterOperation(id) 115 116 // when 117 resp, err := c.UpgradeClusterOperationToDTO(givenOperation) 118 119 // then 120 require.NoError(t, err) 121 assert.Equal(t, id, resp.OrchestrationID) 122 } 123 124 func TestConverter_UpgradeClusterOperationListToDTO(t *testing.T) { 125 // given 126 c := handlers.Converter{} 127 128 id := "id" 129 givenOperations := []internal.UpgradeClusterOperation{ 130 fixUpgradeClusterOperation(id), 131 fixUpgradeClusterOperation("another"), 132 } 133 134 // when 135 resp, err := c.UpgradeClusterOperationListToDTO(givenOperations, 2, 5) 136 137 // then 138 require.NoError(t, err) 139 require.Len(t, resp.Data, 2) 140 assert.Equal(t, id, resp.Data[0].OrchestrationID) 141 assert.Equal(t, 2, resp.Count) 142 assert.Equal(t, 5, resp.TotalCount) 143 } 144 145 func TestConverter_UpgradeClusterOperationToDetailDTO(t *testing.T) { 146 // given 147 c := handlers.Converter{} 148 149 id := "id" 150 givenOperation := fixUpgradeClusterOperation(id) 151 clusterConfig := gqlschema.GardenerConfigInput{KubernetesVersion: id} 152 153 // when 154 resp, err := c.UpgradeClusterOperationToDetailDTO(givenOperation, &clusterConfig) 155 156 // then 157 require.NoError(t, err) 158 assert.Equal(t, id, resp.OrchestrationID) 159 assert.Equal(t, id, resp.ClusterConfig.KubernetesVersion) 160 } 161 162 func fixUpgradeClusterOperation(id string) internal.UpgradeClusterOperation { 163 upgradeOperation := fixture.FixUpgradeClusterOperation("", "") 164 upgradeOperation.OrchestrationID = id 165 166 return upgradeOperation 167 }