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

     1  package apic
     2  
     3  import (
     4  	"net/http"
     5  	"sync"
     6  	"time"
     7  
     8  	cache2 "github.com/Axway/agent-sdk/pkg/agent/cache"
     9  	"github.com/Axway/agent-sdk/pkg/util/log"
    10  
    11  	"github.com/Axway/agent-sdk/pkg/api"
    12  	"github.com/Axway/agent-sdk/pkg/cache"
    13  	corecfg "github.com/Axway/agent-sdk/pkg/config"
    14  )
    15  
    16  // GetTestServiceClient - return a true ServiceClient, but with mocks for tokengetter and the HTTPClient and dummy values
    17  // for various configurations. Has enough other configuration to make the client usable. This function also returns the
    18  // MockHTTPClient so the caller can use it directly if needed, as it is not available directly from ServiceClient in other packages
    19  func GetTestServiceClient() (*ServiceClient, *api.MockHTTPClient) {
    20  	webhook := &corecfg.WebhookConfiguration{
    21  		URL:     "http://foo.bar",
    22  		Headers: "Header=contentType,Value=application/json",
    23  		Secret:  "",
    24  	}
    25  
    26  	cfg := &corecfg.CentralConfiguration{
    27  		TeamName:     "testteam",
    28  		TenantID:     "112456",
    29  		Environment:  "testenvironment",
    30  		PollInterval: 1 * time.Second,
    31  		PageSize:     100,
    32  		Auth: &corecfg.AuthConfiguration{
    33  			URL:      "http://localhost:8888",
    34  			Realm:    "Broker",
    35  			ClientID: "dummy",
    36  		},
    37  		CredentialConfig: &corecfg.CredentialConfiguration{},
    38  	}
    39  
    40  	apiClient := &api.MockHTTPClient{ResponseCode: http.StatusOK}
    41  	svcClient := &ServiceClient{
    42  		cfg:                                cfg,
    43  		tokenRequester:                     MockTokenGetter,
    44  		subscriptionSchemaCache:            cache.New(),
    45  		caches:                             cache2.NewAgentCacheManager(cfg, false),
    46  		apiClient:                          apiClient,
    47  		DefaultSubscriptionApprovalWebhook: webhook,
    48  		logger:                             log.NewFieldLogger(),
    49  		pageSizes:                          map[string]int{},
    50  		pageSizeMutex:                      &sync.Mutex{},
    51  	}
    52  
    53  	return svcClient, apiClient
    54  }
    55  
    56  // GetTestServiceClientCentralConfiguration - cast and return the CentralConfiguration
    57  func GetTestServiceClientCentralConfiguration(client *ServiceClient) *corecfg.CentralConfiguration {
    58  	return client.cfg.(*corecfg.CentralConfiguration)
    59  }