github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/process/provisioning/external_eval_step_test.go (about)

     1  package provisioning
     2  
     3  import (
     4  	"context"
     5  	"net/http/httptest"
     6  	"testing"
     7  
     8  	"github.com/kyma-project/kyma-environment-broker/internal"
     9  	"github.com/kyma-project/kyma-environment-broker/internal/avs"
    10  	"github.com/kyma-project/kyma-environment-broker/internal/broker"
    11  	"github.com/kyma-project/kyma-environment-broker/internal/storage"
    12  	"github.com/sirupsen/logrus"
    13  	"github.com/stretchr/testify/assert"
    14  	"github.com/stretchr/testify/require"
    15  )
    16  
    17  func TestExternalEvalStep_Run(t *testing.T) {
    18  	memoryStorage := storage.NewMemoryStorage()
    19  	externalEvalCreator, mockOauthServer, mockAvsSvc := setupAvs(t, memoryStorage.Operations())
    20  	defer mockAvsSvc.server.Close()
    21  	defer mockOauthServer.Close()
    22  
    23  	operation := fixOperationRuntimeStatus(broker.GCPPlanID, internal.GCP)
    24  	operation.Avs.AvsEvaluationInternalId = fixAvsEvaluationInternalId
    25  	err := memoryStorage.Operations().InsertOperation(operation)
    26  	assert.NoError(t, err)
    27  	step := ExternalEvalStep{
    28  		externalEvalCreator: externalEvalCreator,
    29  	}
    30  
    31  	// when
    32  	_, retry, err := step.Run(operation, logrus.New())
    33  
    34  	// then
    35  	assert.Zero(t, retry)
    36  	assert.NoError(t, err)
    37  	inDB, _ := memoryStorage.Operations().GetOperationByID(operation.ID)
    38  	assert.Contains(t, mockAvsSvc.evals, inDB.Avs.AVSEvaluationExternalId)
    39  }
    40  
    41  func setupAvs(t *testing.T, operations storage.Operations) (*ExternalEvalCreator, *httptest.Server, *mockAvsService) {
    42  	mockOauthServer := newMockAvsOauthServer()
    43  	mockAvsSvc := newMockAvsService(t, false)
    44  	mockAvsSvc.startServer()
    45  	mockAvsSvc.evals[fixAvsEvaluationInternalId] = fixAvsEvaluation()
    46  	avsConfig := avsConfig(mockOauthServer, mockAvsSvc.server)
    47  	avsClient, err := avs.NewClient(context.TODO(), avsConfig, logrus.New())
    48  	require.NoError(t, err)
    49  	avsDel := avs.NewDelegator(avsClient, avsConfig, operations)
    50  	externalEvalAssistant := avs.NewExternalEvalAssistant(avsConfig)
    51  	externalEvalCreator := NewExternalEvalCreator(avsDel, false, externalEvalAssistant)
    52  
    53  	return externalEvalCreator, mockOauthServer, mockAvsSvc
    54  }