github.com/kyma-project/control-plane/components/kyma-environment-broker@v0.0.0-20230911130701-f7d1ac254205/internal/provisioner/client_test.go (about)

     1  package provisioner
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"net/http"
     7  	"net/http/httptest"
     8  	"testing"
     9  
    10  	"github.com/99designs/gqlgen/handler"
    11  	"github.com/gorilla/mux"
    12  	kebError "github.com/kyma-project/control-plane/components/kyma-environment-broker/internal/error"
    13  	"github.com/kyma-project/control-plane/components/kyma-environment-broker/internal/ptr"
    14  	schema "github.com/kyma-project/control-plane/components/provisioner/pkg/gqlschema"
    15  	"github.com/stretchr/testify/assert"
    16  )
    17  
    18  const (
    19  	testAccountID    = "4346c639-32f8-4947-ae95-73bb8efad209"
    20  	testSubAccountID = "42d45043-d0fb-4077-9de0-d7f781949bce"
    21  
    22  	provisionRuntimeID            = "4e268c0f-d053-4ab7-b167-6dbc0a0e09a6"
    23  	provisionRuntimeOperationID   = "c89f7862-0ef9-4d4e-bc82-afbc5ac98b8d"
    24  	upgradeRuntimeOperationID     = "74f47e0a-9a76-4336-9974-70705500a981"
    25  	deprovisionRuntimeOperationID = "f9f7b734-7538-419c-8ac1-37060c60531a"
    26  )
    27  
    28  var (
    29  	testKubernetesVersion   = "1.17.16"
    30  	testMachineImage        = "gardenlinux"
    31  	testMachineImageVersion = "184.0.0"
    32  	testAutoScalerMin       = 2
    33  	testAutoScalerMax       = 4
    34  	testMaxSurge            = 4
    35  	testMaxUnavailable      = 1
    36  )
    37  
    38  func TestClient_ProvisionRuntime(t *testing.T) {
    39  	t.Run("should trigger provisioning", func(t *testing.T) {
    40  		// Given
    41  		tr := &testResolver{t: t, runtime: &testRuntime{}}
    42  		testServer := fixHTTPServer(tr)
    43  		defer testServer.Close()
    44  
    45  		client := NewProvisionerClient(testServer.URL, false)
    46  
    47  		// When
    48  		status, err := client.ProvisionRuntime(testAccountID, testSubAccountID, fixProvisionRuntimeInput())
    49  
    50  		// Then
    51  		assert.NoError(t, err)
    52  		assert.Equal(t, ptr.String(provisionRuntimeOperationID), status.ID)
    53  		assert.Equal(t, schema.OperationStateInProgress, status.State)
    54  		assert.Equal(t, ptr.String(provisionRuntimeID), status.RuntimeID)
    55  
    56  		assert.Equal(t, "test", tr.getRuntime().name)
    57  	})
    58  
    59  	t.Run("should trigger provisioning without dns config", func(t *testing.T) {
    60  		// Given
    61  		tr := &testResolver{t: t, runtime: &testRuntime{}}
    62  		testServer := fixHTTPServer(tr)
    63  		defer testServer.Close()
    64  
    65  		client := NewProvisionerClient(testServer.URL, false)
    66  
    67  		// When
    68  		status, err := client.ProvisionRuntime(testAccountID, testSubAccountID, fixProvisionRuntimeInputWithoutDnsConfig())
    69  
    70  		// Then
    71  		assert.NoError(t, err)
    72  		assert.Equal(t, ptr.String(provisionRuntimeOperationID), status.ID)
    73  		assert.Equal(t, schema.OperationStateInProgress, status.State)
    74  		assert.Equal(t, ptr.String(provisionRuntimeID), status.RuntimeID)
    75  
    76  		assert.Equal(t, "test", tr.getRuntime().name)
    77  	})
    78  
    79  	t.Run("provisioner should return error", func(t *testing.T) {
    80  		// Given
    81  		tr := &testResolver{t: t, runtime: &testRuntime{}, failed: true}
    82  		testServer := fixHTTPServer(tr)
    83  		defer testServer.Close()
    84  
    85  		client := NewProvisionerClient(testServer.URL, false)
    86  
    87  		// When
    88  		status, err := client.ProvisionRuntime(testAccountID, testSubAccountID, fixProvisionRuntimeInput())
    89  
    90  		// Then
    91  		assert.Error(t, err)
    92  		assert.Empty(t, status)
    93  
    94  		assert.Equal(t, "", tr.getRuntime().name)
    95  	})
    96  }
    97  
    98  func TestClient_DeprovisionRuntime(t *testing.T) {
    99  	t.Run("should trigger deprovisioning", func(t *testing.T) {
   100  		// Given
   101  		tr := &testResolver{t: t, runtime: &testRuntime{}}
   102  		testServer := fixHTTPServer(tr)
   103  		defer testServer.Close()
   104  
   105  		client := NewProvisionerClient(testServer.URL, false)
   106  		operation, err := client.ProvisionRuntime(testAccountID, testSubAccountID, fixProvisionRuntimeInput())
   107  		assert.NoError(t, err)
   108  
   109  		// When
   110  		operationId, err := client.DeprovisionRuntime(testAccountID, *operation.RuntimeID)
   111  
   112  		// Then
   113  		assert.NoError(t, err)
   114  		assert.Equal(t, deprovisionRuntimeOperationID, operationId)
   115  
   116  		assert.Empty(t, tr.getRuntime().runtimeID)
   117  	})
   118  
   119  	t.Run("provisioner should return error", func(t *testing.T) {
   120  		// Given
   121  		tr := &testResolver{t: t, runtime: &testRuntime{}}
   122  		testServer := fixHTTPServer(tr)
   123  		defer testServer.Close()
   124  
   125  		client := NewProvisionerClient(testServer.URL, false)
   126  		operation, err := client.ProvisionRuntime(testAccountID, testSubAccountID, fixProvisionRuntimeInput())
   127  		assert.NoError(t, err)
   128  
   129  		tr.failed = true
   130  
   131  		// When
   132  		operationId, err := client.DeprovisionRuntime(testAccountID, *operation.RuntimeID)
   133  
   134  		// Then
   135  		assert.Error(t, err)
   136  		assert.Equal(t, "", operationId)
   137  
   138  		assert.Equal(t, provisionRuntimeID, tr.getRuntime().runtimeID)
   139  	})
   140  }
   141  
   142  func TestClient_UpgradeRuntime(t *testing.T) {
   143  	t.Run("should trigger upgrade", func(t *testing.T) {
   144  		// given
   145  		tr := &testResolver{t: t, runtime: &testRuntime{}}
   146  		testServer := fixHTTPServer(tr)
   147  		defer testServer.Close()
   148  
   149  		client := NewProvisionerClient(testServer.URL, false)
   150  		operation, err := client.ProvisionRuntime(testAccountID, testSubAccountID, fixProvisionRuntimeInput())
   151  		assert.NoError(t, err)
   152  
   153  		// when
   154  		status, err := client.UpgradeRuntime(testAccountID, *operation.RuntimeID, fixUpgradeRuntimeInput("1.14.0"))
   155  
   156  		// then
   157  		assert.NoError(t, err)
   158  		assert.Equal(t, ptr.String(upgradeRuntimeOperationID), status.ID)
   159  		assert.Equal(t, schema.OperationStateInProgress, status.State)
   160  		assert.Equal(t, schema.OperationTypeUpgrade, status.Operation)
   161  		assert.Equal(t, ptr.String(provisionRuntimeID), status.RuntimeID)
   162  	})
   163  
   164  	t.Run("provisioner should return error", func(t *testing.T) {
   165  		// given
   166  		tr := &testResolver{t: t, runtime: &testRuntime{}}
   167  		testServer := fixHTTPServer(tr)
   168  		defer testServer.Close()
   169  
   170  		client := NewProvisionerClient(testServer.URL, false)
   171  		operation, err := client.ProvisionRuntime(testAccountID, testSubAccountID, fixProvisionRuntimeInput())
   172  		assert.NoError(t, err)
   173  
   174  		tr.failed = true
   175  
   176  		// when
   177  		status, err := client.UpgradeRuntime(testAccountID, *operation.RuntimeID, fixUpgradeRuntimeInput("1.14.0"))
   178  
   179  		// Then
   180  		assert.Error(t, err)
   181  		assert.Empty(t, status)
   182  
   183  		assert.Equal(t, "", tr.getRuntime().upgradeOperationID)
   184  	})
   185  }
   186  
   187  func TestClient_UpgradeShoot(t *testing.T) {
   188  	t.Run("should trigger shoot upgrade", func(t *testing.T) {
   189  		// given
   190  		tr := &testResolver{t: t, runtime: &testRuntime{}}
   191  		testServer := fixHTTPServer(tr)
   192  		defer testServer.Close()
   193  
   194  		client := NewProvisionerClient(testServer.URL, false)
   195  		operation, err := client.ProvisionRuntime(testAccountID, testSubAccountID, fixProvisionRuntimeInput())
   196  		assert.NoError(t, err)
   197  
   198  		// when
   199  		status, err := client.UpgradeShoot(testAccountID, *operation.RuntimeID, fixUpgradeShootInput())
   200  
   201  		// then
   202  		assert.NoError(t, err)
   203  		assert.Equal(t, ptr.String(upgradeRuntimeOperationID), status.ID)
   204  		assert.Equal(t, schema.OperationStateInProgress, status.State)
   205  		assert.Equal(t, schema.OperationTypeUpgradeShoot, status.Operation)
   206  		assert.Equal(t, ptr.String(provisionRuntimeID), status.RuntimeID)
   207  	})
   208  
   209  	t.Run("provisioner should return error", func(t *testing.T) {
   210  		// given
   211  		tr := &testResolver{t: t, runtime: &testRuntime{}}
   212  		testServer := fixHTTPServer(tr)
   213  		defer testServer.Close()
   214  
   215  		client := NewProvisionerClient(testServer.URL, false)
   216  		operation, err := client.ProvisionRuntime(testAccountID, testSubAccountID, fixProvisionRuntimeInput())
   217  		assert.NoError(t, err)
   218  
   219  		tr.failed = true
   220  
   221  		// when
   222  		status, err := client.UpgradeShoot(testAccountID, *operation.RuntimeID, fixUpgradeShootInput())
   223  
   224  		// Then
   225  		assert.Error(t, err)
   226  		assert.Empty(t, status)
   227  
   228  		assert.Equal(t, "", tr.getRuntime().upgradeOperationID)
   229  	})
   230  }
   231  
   232  func TestClient_ReconnectRuntimeAgent(t *testing.T) {
   233  	t.Run("should reconnect runtime agent", func(t *testing.T) {
   234  		// Given
   235  		tr := &testResolver{t: t, runtime: &testRuntime{}}
   236  		testServer := fixHTTPServer(tr)
   237  		defer testServer.Close()
   238  
   239  		client := NewProvisionerClient(testServer.URL, false)
   240  		operation, err := client.ProvisionRuntime(testAccountID, testSubAccountID, fixProvisionRuntimeInput())
   241  		assert.NoError(t, err)
   242  
   243  		// When
   244  		operationId, err := client.ReconnectRuntimeAgent(testAccountID, *operation.RuntimeID)
   245  
   246  		// Then
   247  		assert.NoError(t, err)
   248  		assert.Equal(t, provisionRuntimeOperationID, operationId)
   249  	})
   250  
   251  	t.Run("provisioner should return error", func(t *testing.T) {
   252  		// Given
   253  		tr := &testResolver{t: t, runtime: &testRuntime{}}
   254  		testServer := fixHTTPServer(tr)
   255  		defer testServer.Close()
   256  
   257  		client := NewProvisionerClient(testServer.URL, false)
   258  		operation, err := client.ProvisionRuntime(testAccountID, testSubAccountID, fixProvisionRuntimeInput())
   259  		assert.NoError(t, err)
   260  
   261  		tr.failed = true
   262  
   263  		// When
   264  		operationId, err := client.ReconnectRuntimeAgent(testAccountID, *operation.RuntimeID)
   265  
   266  		// Then
   267  		assert.Error(t, err)
   268  		assert.Equal(t, "", operationId)
   269  	})
   270  
   271  	t.Run("provisioner returns bad request code error", func(t *testing.T) {
   272  		server := fixHTTPMockServer(`{
   273  			  "errors": [
   274  				{
   275  				  "message": "tenant header is empty",
   276  				  "path": [
   277  					"runtimeStatus"
   278  				  ],
   279  				  "extensions": {
   280  					"error_code": 400,
   281  					"error_reason": "Object not found",
   282  					"error_component": "compass director"
   283  				  }
   284  				}
   285  			  ],
   286  			  "data": {
   287  				"runtimeStatus": null
   288  			  }
   289  			}`)
   290  		defer server.Close()
   291  
   292  		client := NewProvisionerClient(server.URL, false)
   293  
   294  		// when
   295  		_, err := client.ProvisionRuntime(testAccountID, testSubAccountID, fixProvisionRuntimeInput())
   296  		lastErr := kebError.ReasonForError(err)
   297  
   298  		// Then
   299  		assert.Error(t, err)
   300  		assert.False(t, kebError.IsTemporaryError(err))
   301  		assert.Equal(t, kebError.ErrReason("Object not found"), lastErr.Reason())
   302  		assert.Equal(t, kebError.ErrComponent("compass director"), lastErr.Component())
   303  	})
   304  
   305  	t.Run("provisioner returns temporary code error", func(t *testing.T) {
   306  		server := fixHTTPMockServer(`{
   307  			  "errors": [
   308  				{
   309  				  "message": "tenant header is empty",
   310  				  "path": [
   311  					"runtimeStatus"
   312  				  ],
   313  				  "extensions": {
   314  					"error_code": 500,
   315  					"error_reason": "whatever",
   316  					"error_component": "db - provisioner"
   317  				  }
   318  				}
   319  			  ],
   320  			  "data": {
   321  				"runtimeStatus": null
   322  			  }
   323  			}`)
   324  		defer server.Close()
   325  
   326  		client := NewProvisionerClient(server.URL, false)
   327  
   328  		// when
   329  		_, err := client.ProvisionRuntime(testAccountID, testSubAccountID, fixProvisionRuntimeInput())
   330  		lastErr := kebError.ReasonForError(err)
   331  
   332  		// Then
   333  		assert.Error(t, err)
   334  		assert.True(t, kebError.IsTemporaryError(err))
   335  		assert.Equal(t, kebError.ErrReason("whatever"), lastErr.Reason())
   336  		assert.Equal(t, kebError.ErrComponent("db - provisioner"), lastErr.Component())
   337  	})
   338  
   339  	t.Run("network error", func(t *testing.T) {
   340  		client := NewProvisionerClient("http://not-existing", false)
   341  
   342  		// when
   343  		_, err := client.ProvisionRuntime(testAccountID, testSubAccountID, fixProvisionRuntimeInput())
   344  
   345  		// Then
   346  		assert.Error(t, err)
   347  		assert.True(t, kebError.IsTemporaryError(err))
   348  	})
   349  }
   350  
   351  func TestClient_RuntimeOperationStatus(t *testing.T) {
   352  	t.Run("should return runtime operation status", func(t *testing.T) {
   353  		// Given
   354  		tr := &testResolver{t: t, runtime: &testRuntime{}}
   355  		testServer := fixHTTPServer(tr)
   356  		defer testServer.Close()
   357  
   358  		client := NewProvisionerClient(testServer.URL, false)
   359  		_, err := client.ProvisionRuntime(testAccountID, testSubAccountID, fixProvisionRuntimeInput())
   360  		assert.NoError(t, err)
   361  
   362  		// When
   363  		status, err := client.RuntimeOperationStatus(testAccountID, provisionRuntimeID)
   364  
   365  		// Then
   366  		assert.NoError(t, err)
   367  		assert.Equal(t, ptr.String(provisionRuntimeID), status.RuntimeID)
   368  		assert.Equal(t, ptr.String(provisionRuntimeOperationID), status.ID)
   369  		assert.Equal(t, schema.OperationStateInProgress, status.State)
   370  		assert.Equal(t, schema.OperationTypeProvision, status.Operation)
   371  	})
   372  
   373  	t.Run("provisioner should return error", func(t *testing.T) {
   374  		// Given
   375  		tr := &testResolver{t: t, runtime: &testRuntime{}}
   376  		testServer := fixHTTPServer(tr)
   377  		defer testServer.Close()
   378  
   379  		client := NewProvisionerClient(testServer.URL, false)
   380  		_, err := client.ProvisionRuntime(testAccountID, testSubAccountID, fixProvisionRuntimeInput())
   381  		assert.NoError(t, err)
   382  
   383  		tr.failed = true
   384  
   385  		// When
   386  		status, err := client.RuntimeOperationStatus(testAccountID, provisionRuntimeID)
   387  
   388  		// Then
   389  		assert.Error(t, err)
   390  		assert.Empty(t, status)
   391  	})
   392  }
   393  
   394  func TestClient_OperationStatusLastError(t *testing.T) {
   395  	t.Run("nil last error", func(t *testing.T) {
   396  		// Given
   397  		response := schema.OperationStatus{
   398  			ID:        ptr.String(provisionRuntimeOperationID),
   399  			State:     schema.OperationStateInProgress,
   400  			RuntimeID: ptr.String(provisionRuntimeID),
   401  		}
   402  
   403  		// When
   404  		lastErr := OperationStatusLastError(response.LastError)
   405  
   406  		// Then
   407  		assert.Equal(t, kebError.ErrProvisioner, lastErr.Component())
   408  		assert.Equal(t, kebError.ErrProvisionerNilLastError, lastErr.Reason())
   409  		assert.Equal(t, "", lastErr.Error())
   410  	})
   411  
   412  	t.Run("with last error", func(t *testing.T) {
   413  		// Given
   414  		response := schema.OperationStatus{
   415  			ID:        ptr.String(provisionRuntimeOperationID),
   416  			State:     schema.OperationStateInProgress,
   417  			RuntimeID: ptr.String(provisionRuntimeID),
   418  			LastError: &schema.LastError{
   419  				ErrMessage: "error msg",
   420  				Reason:     "not found",
   421  				Component:  "provisioner-db",
   422  			},
   423  		}
   424  
   425  		// When
   426  		lastErr := OperationStatusLastError(response.LastError)
   427  
   428  		// Then
   429  		assert.Equal(t, kebError.ErrComponent("provisioner-db"), lastErr.Component())
   430  		assert.Equal(t, kebError.ErrReason("not found"), lastErr.Reason())
   431  		assert.Equal(t, "error msg", lastErr.Error())
   432  
   433  		err := fmt.Errorf("something: %w", lastErr)
   434  		lastErr = kebError.ReasonForError(err)
   435  
   436  		// Then
   437  		assert.Equal(t, kebError.ErrComponent("provisioner-db"), lastErr.Component())
   438  		assert.Equal(t, kebError.ErrReason("not found"), lastErr.Reason())
   439  		assert.Equal(t, "something: error msg", lastErr.Error())
   440  	})
   441  }
   442  
   443  type testRuntime struct {
   444  	tenant                 string
   445  	clientID               string
   446  	name                   string
   447  	runtimeID              string
   448  	provisionOperationID   string
   449  	upgradeOperationID     string
   450  	deprovisionOperationID string
   451  }
   452  
   453  type testResolver struct {
   454  	t       *testing.T
   455  	runtime *testRuntime
   456  	failed  bool
   457  }
   458  
   459  type httpHandler struct {
   460  	r string
   461  }
   462  
   463  func (h httpHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
   464  	rw.Write([]byte(h.r))
   465  }
   466  
   467  func fixHandler(resp string) http.Handler {
   468  	return httpHandler{
   469  		r: resp,
   470  	}
   471  }
   472  
   473  func fixHTTPMockServer(resp string) *httptest.Server {
   474  	return httptest.NewServer(fixHandler(resp))
   475  }
   476  
   477  func fixHTTPServer(tr *testResolver) *httptest.Server {
   478  	r := mux.NewRouter()
   479  
   480  	r.Use(func(h http.Handler) http.Handler {
   481  		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
   482  			accountID := r.Header.Get(accountIDKey)
   483  			subAccountID := r.Header.Get(subAccountIDKey)
   484  			if accountID != testAccountID {
   485  				w.WriteHeader(http.StatusForbidden)
   486  				return
   487  			}
   488  			tr.runtime.tenant = accountID
   489  			tr.runtime.clientID = subAccountID
   490  
   491  			h.ServeHTTP(w, r)
   492  		})
   493  	})
   494  	r.HandleFunc("/", handler.GraphQL(schema.NewExecutableSchema(schema.Config{Resolvers: tr})))
   495  
   496  	return httptest.NewServer(r)
   497  }
   498  
   499  func (tr testResolver) Mutation() schema.MutationResolver {
   500  	tr.t.Log("Mutation TestResolver")
   501  	return &testMutationResolver{t: tr.t, runtime: tr.runtime, failed: tr.failed}
   502  }
   503  
   504  func (tr testResolver) Query() schema.QueryResolver {
   505  	tr.t.Log("Query TestResolver")
   506  	return &testQueryResolver{t: tr.t, runtime: tr.runtime, failed: tr.failed}
   507  }
   508  
   509  func (tr testResolver) getRuntime() *testRuntime {
   510  	return tr.runtime
   511  }
   512  
   513  type testMutationResolver struct {
   514  	t       *testing.T
   515  	runtime *testRuntime
   516  	failed  bool
   517  }
   518  
   519  func (tmr *testMutationResolver) ProvisionRuntime(_ context.Context, config schema.ProvisionRuntimeInput) (*schema.OperationStatus, error) {
   520  	tmr.t.Log("ProvisionRuntime testMutationResolver")
   521  
   522  	if tmr.failed {
   523  		return nil, fmt.Errorf("provision runtime failed for %s", config.RuntimeInput.Name)
   524  	}
   525  
   526  	tmr.runtime.name = config.RuntimeInput.Name
   527  	tmr.runtime.runtimeID = provisionRuntimeID
   528  	tmr.runtime.provisionOperationID = provisionRuntimeOperationID
   529  
   530  	return &schema.OperationStatus{
   531  		ID:        ptr.String(tmr.runtime.provisionOperationID),
   532  		State:     schema.OperationStateInProgress,
   533  		RuntimeID: ptr.String(tmr.runtime.runtimeID),
   534  	}, nil
   535  }
   536  
   537  func (tmr testMutationResolver) UpgradeRuntime(_ context.Context, id string, config schema.UpgradeRuntimeInput) (*schema.OperationStatus, error) {
   538  	tmr.t.Log("UpgradeTuntime testMutationResolver")
   539  
   540  	if tmr.failed {
   541  		return nil, fmt.Errorf("upgrade runtime failed for version %s", id)
   542  	}
   543  
   544  	if tmr.runtime.runtimeID == id {
   545  		tmr.runtime.upgradeOperationID = upgradeRuntimeOperationID
   546  	}
   547  
   548  	return &schema.OperationStatus{
   549  		ID:        ptr.String(tmr.runtime.upgradeOperationID),
   550  		State:     schema.OperationStateInProgress,
   551  		Operation: schema.OperationTypeUpgrade,
   552  		RuntimeID: ptr.String(tmr.runtime.runtimeID),
   553  	}, nil
   554  }
   555  
   556  func (tmr testMutationResolver) DeprovisionRuntime(_ context.Context, id string) (string, error) {
   557  	tmr.t.Log("DeprovisionRuntime testMutationResolver")
   558  
   559  	if tmr.failed {
   560  		return "", fmt.Errorf("deprovision failed for %s", id)
   561  	}
   562  
   563  	if tmr.runtime.runtimeID == id {
   564  		tmr.runtime.runtimeID = ""
   565  		tmr.runtime.name = ""
   566  		tmr.runtime.deprovisionOperationID = deprovisionRuntimeOperationID
   567  	}
   568  
   569  	return tmr.runtime.deprovisionOperationID, nil
   570  }
   571  
   572  func (tmr testMutationResolver) HibernateRuntime(ctx context.Context, id string) (*schema.OperationStatus, error) {
   573  	return nil, fmt.Errorf("not implemented")
   574  }
   575  
   576  func (tmr testMutationResolver) RollBackUpgradeOperation(_ context.Context, id string) (*schema.RuntimeStatus, error) {
   577  	return nil, nil
   578  }
   579  
   580  func (tmr testMutationResolver) ReconnectRuntimeAgent(_ context.Context, id string) (string, error) {
   581  	tmr.t.Log("ReconnectRuntimeAgent testMutationResolver")
   582  
   583  	if tmr.failed {
   584  		return "", fmt.Errorf("reconnect runtime agent failed for %s", id)
   585  	}
   586  
   587  	if tmr.runtime.runtimeID == id {
   588  		return tmr.runtime.provisionOperationID, nil
   589  	}
   590  
   591  	return "", nil
   592  }
   593  
   594  func (tmr testMutationResolver) UpgradeShoot(_ context.Context, id string, config schema.UpgradeShootInput) (*schema.OperationStatus, error) {
   595  	tmr.t.Log("UpgradeShoot testMutationResolver")
   596  
   597  	if tmr.failed {
   598  		return nil, fmt.Errorf("upgrade runtime failed for version %s", id)
   599  	}
   600  
   601  	if tmr.runtime.runtimeID == id {
   602  		tmr.runtime.upgradeOperationID = upgradeRuntimeOperationID
   603  	}
   604  
   605  	return &schema.OperationStatus{
   606  		ID:        ptr.String(tmr.runtime.upgradeOperationID),
   607  		State:     schema.OperationStateInProgress,
   608  		Operation: schema.OperationTypeUpgradeShoot,
   609  		RuntimeID: ptr.String(tmr.runtime.runtimeID),
   610  	}, nil
   611  }
   612  
   613  type testQueryResolver struct {
   614  	t       *testing.T
   615  	runtime *testRuntime
   616  	failed  bool
   617  }
   618  
   619  func (tqr testQueryResolver) RuntimeStatus(_ context.Context, id string) (*schema.RuntimeStatus, error) {
   620  	return nil, nil
   621  }
   622  
   623  func (tqr testQueryResolver) RuntimeOperationStatus(_ context.Context, id string) (*schema.OperationStatus, error) {
   624  	tqr.t.Log("RuntimeOperationStatus - testQueryResolver")
   625  
   626  	if tqr.failed {
   627  		return nil, fmt.Errorf("query about runtime operation status failed for %s", id)
   628  	}
   629  
   630  	if tqr.runtime.runtimeID == id {
   631  		return &schema.OperationStatus{
   632  			ID:        ptr.String(tqr.runtime.provisionOperationID),
   633  			Operation: schema.OperationTypeProvision,
   634  			State:     schema.OperationStateInProgress,
   635  			Message:   ptr.String("test message"),
   636  			RuntimeID: ptr.String(tqr.runtime.runtimeID),
   637  		}, nil
   638  	}
   639  
   640  	return nil, nil
   641  }
   642  
   643  func fixProvisionRuntimeInput() schema.ProvisionRuntimeInput {
   644  	disabled := false
   645  	return schema.ProvisionRuntimeInput{
   646  		RuntimeInput: &schema.RuntimeInput{
   647  			Name:        "test",
   648  			Description: nil,
   649  			Labels:      nil,
   650  		},
   651  		ClusterConfig: &schema.ClusterConfigInput{
   652  			GardenerConfig: &schema.GardenerConfigInput{
   653  				ProviderSpecificConfig: &schema.ProviderSpecificInput{},
   654  				Name:                   "abcd",
   655  				VolumeSizeGb:           ptr.Integer(50),
   656  				DNSConfig: &schema.DNSConfigInput{
   657  					Domain: "test.devtest.kyma.ondemand.com",
   658  					Providers: []*schema.DNSProviderInput{
   659  						{
   660  							DomainsInclude: []string{"devtest.kyma.ondemand.com"},
   661  							Primary:        true,
   662  							SecretName:     "efg",
   663  							Type:           "route53_type_test",
   664  						},
   665  					},
   666  				},
   667  				ShootNetworkingFilterDisabled: &disabled,
   668  			},
   669  		},
   670  		KymaConfig: &schema.KymaConfigInput{
   671  			Components: []*schema.ComponentConfigurationInput{
   672  				{
   673  					Component: "test",
   674  				},
   675  			},
   676  		},
   677  	}
   678  }
   679  
   680  func fixProvisionRuntimeInputWithoutDnsConfig() schema.ProvisionRuntimeInput {
   681  	disabled := false
   682  	return schema.ProvisionRuntimeInput{
   683  		RuntimeInput: &schema.RuntimeInput{
   684  			Name:        "test",
   685  			Description: nil,
   686  			Labels:      nil,
   687  		},
   688  		ClusterConfig: &schema.ClusterConfigInput{
   689  			GardenerConfig: &schema.GardenerConfigInput{
   690  				ProviderSpecificConfig:        &schema.ProviderSpecificInput{},
   691  				Name:                          "abcd",
   692  				VolumeSizeGb:                  ptr.Integer(50),
   693  				ShootNetworkingFilterDisabled: &disabled,
   694  			},
   695  		},
   696  		KymaConfig: &schema.KymaConfigInput{
   697  			Components: []*schema.ComponentConfigurationInput{
   698  				{
   699  					Component: "test",
   700  				},
   701  			},
   702  		},
   703  	}
   704  }
   705  
   706  func fixUpgradeRuntimeInput(kymaVersion string) schema.UpgradeRuntimeInput {
   707  	return schema.UpgradeRuntimeInput{KymaConfig: &schema.KymaConfigInput{
   708  		Version: kymaVersion,
   709  		Configuration: []*schema.ConfigEntryInput{
   710  			{
   711  				Key:   "a.config.key",
   712  				Value: "a.config.value",
   713  			},
   714  		},
   715  		Components: []*schema.ComponentConfigurationInput{
   716  			{
   717  				Component: "test-component",
   718  				Namespace: "test-namespace",
   719  			},
   720  		},
   721  	}}
   722  }
   723  
   724  func fixUpgradeShootInput() schema.UpgradeShootInput {
   725  	disabled := false
   726  	return schema.UpgradeShootInput{
   727  		GardenerConfig: &schema.GardenerUpgradeInput{
   728  			KubernetesVersion:             &testKubernetesVersion,
   729  			MachineImage:                  &testMachineImage,
   730  			MachineImageVersion:           &testMachineImageVersion,
   731  			AutoScalerMin:                 &testAutoScalerMin,
   732  			AutoScalerMax:                 &testAutoScalerMax,
   733  			MaxSurge:                      &testMaxSurge,
   734  			MaxUnavailable:                &testMaxUnavailable,
   735  			ShootNetworkingFilterDisabled: &disabled,
   736  		},
   737  	}
   738  }