github.com/Axway/agent-sdk@v1.1.101/pkg/migrate/ardmigration_test.go (about)

     1  package migrate
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	apiv1 "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/api/v1"
     8  	management "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/management/v1alpha1"
     9  	"github.com/Axway/agent-sdk/pkg/config"
    10  	"github.com/stretchr/testify/assert"
    11  )
    12  
    13  func TestArdMigration(t *testing.T) {
    14  	cfg := &config.CentralConfiguration{
    15  		Environment: "mock-env",
    16  	}
    17  	c := &mockArdMigClient{}
    18  	mig := NewArdMigration(c, cfg)
    19  	ard := management.NewAccessRequestDefinition("asdf", cfg.GetEnvironmentName())
    20  	ard.Spec.Schema = map[string]interface{}{
    21  		"properties": map[string]interface{}{
    22  			"scopes": []string{"scope1", "scope2"},
    23  		},
    24  	}
    25  	ri, _ := ard.AsInstance()
    26  	ri, err := mig.Migrate(context.Background(), ri)
    27  	ard.FromInstance(ri)
    28  	assert.Nil(t, err)
    29  	scopes := mig.getScopes(ard.Spec.Schema)
    30  	assert.Nil(t, scopes)
    31  }
    32  
    33  type mockArdMigClient struct{}
    34  
    35  func (m mockArdMigClient) ExecuteAPI(method, url string, queryParam map[string]string, buffer []byte) ([]byte, error) {
    36  	return nil, nil
    37  }
    38  
    39  func (m mockArdMigClient) GetAPIV1ResourceInstances(query map[string]string, URL string) ([]*apiv1.ResourceInstance, error) {
    40  	return nil, nil
    41  }
    42  
    43  func (m mockArdMigClient) UpdateResourceInstance(ri apiv1.Interface) (*apiv1.ResourceInstance, error) {
    44  	r, err := ri.AsInstance()
    45  	return r, err
    46  }
    47  
    48  func (m mockArdMigClient) CreateOrUpdateResource(data apiv1.Interface) (*apiv1.ResourceInstance, error) {
    49  	return nil, nil
    50  }
    51  
    52  func (m mockArdMigClient) CreateSubResource(rm apiv1.ResourceMeta, subs map[string]interface{}) error {
    53  	return nil
    54  }
    55  
    56  func (m mockArdMigClient) DeleteResourceInstance(ri apiv1.Interface) error {
    57  	return nil
    58  }
    59  
    60  func (m mockArdMigClient) GetResource(url string) (*apiv1.ResourceInstance, error) {
    61  	return nil, nil
    62  }