diff --git a/internal/dinosaur/pkg/environments/development.go b/internal/dinosaur/pkg/environments/development.go index 805917d328..24ee1d63d6 100644 --- a/internal/dinosaur/pkg/environments/development.go +++ b/internal/dinosaur/pkg/environments/development.go @@ -10,7 +10,7 @@ func NewDevelopmentEnvLoader() environments.EnvLoader { "ocm-debug": "false", "ams-base-url": "https://api.stage.openshift.com", "ocm-base-url": "https://api.stage.openshift.com", - "enable-ocm-mock": "false", + "enable-ocm-mock": "true", "enable-https": "false", "enable-metrics-https": "false", "enable-terms-acceptance": "false", diff --git a/pkg/client/ocm/client.go b/pkg/client/ocm/client.go index 8d79472604..fa2222629d 100644 --- a/pkg/client/ocm/client.go +++ b/pkg/client/ocm/client.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" + "github.com/pkg/errors" pkgerrors "github.com/pkg/errors" "github.com/golang/glog" @@ -115,6 +116,19 @@ func NewClient(connection *sdkClient.Connection) Client { return &client{connection: connection} } +// NewMockClient returns a new OCM client with stubbed responses. +func NewMockClient() Client { + return &ClientMock{ + GetOrganisationFromExternalIDFunc: func(externalID string) (*amsv1.Organization, error) { + org, err := amsv1.NewOrganization(). + ID("12345678"). + Name("stubbed-name"). + Build() + return org, errors.Wrap(err, "failed to build organisation") + }, + } +} + // Connection ... func (c *client) Connection() *sdkClient.Connection { return c.connection diff --git a/pkg/client/ocm/config.go b/pkg/client/ocm/config.go index eec7aba686..7e93ded571 100644 --- a/pkg/client/ocm/config.go +++ b/pkg/client/ocm/config.go @@ -68,6 +68,10 @@ func (c *OCMConfig) AddFlags(fs *pflag.FlagSet) { // ReadFiles ... func (c *OCMConfig) ReadFiles() error { + if c.EnableMock { + return nil + } + err := shared.ReadFileValueString(c.ClientIDFile, &c.ClientID) if err != nil { return fmt.Errorf("reading client ID file: %w", err) diff --git a/pkg/providers/core.go b/pkg/providers/core.go index 9a6252bc92..16dbcf3445 100644 --- a/pkg/providers/core.go +++ b/pkg/providers/core.go @@ -69,6 +69,10 @@ func ServiceProviders() di.Option { di.Provide(observatorium.NewObservatoriumClient), di.Provide(func(config *ocm.OCMConfig) ocm.ClusterManagementClient { + if config.EnableMock { + return ocm.NewMockClient() + } + conn, _, err := ocm.NewOCMConnection(config, config.BaseURL) if err != nil { logger.Logger.Error(err) @@ -77,6 +81,10 @@ func ServiceProviders() di.Option { }), di.Provide(func(config *ocm.OCMConfig) ocm.AMSClient { + if config.EnableMock { + return ocm.NewMockClient() + } + conn, _, err := ocm.NewOCMConnection(config, config.AmsURL) if err != nil { logger.Logger.Error(err) diff --git a/test/helper.go b/test/helper.go index 4dd3187791..ff54a3b65a 100644 --- a/test/helper.go +++ b/test/helper.go @@ -125,6 +125,9 @@ func NewHelperWithHooks(t *testing.T, httpServer *httptest.Server, configuration h.JWTCA = authHelper.JWTCA h.AuthHelper = authHelper + // Integration tests require a valid OCM client. This requires OCM service account credentials to be set. + ocmConfig.EnableMock = false + // Set server if provided if httpServer != nil && ocmConfig.MockMode == ocm.MockModeEmulateServer { workers.RepeatInterval = 1 * time.Second