Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add GetCRTConfiguration #418

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ require (
github.com/shopspring/decimal v1.2.0 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.2 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.21.0 // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
Expand Down
15 changes: 15 additions & 0 deletions pkg/configuration/memberoperatorconfig/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
commonconfig "github.com/codeready-toolchain/toolchain-common/pkg/configuration"

"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/log"
)
Expand Down Expand Up @@ -268,3 +269,17 @@
func (a WebConsolePluginConfig) PendoHost() string {
return commonconfig.GetString(a.w.PendoHost, "cdn.pendo.io")
}

// GetCRTConfiguration creates the client used for configuration and
// returns the loaded CRT configuration
func GetCRTConfiguration(config *rest.Config, scheme *runtime.Scheme) (Configuration, error) {
// create client that will be used for retrieving the member operator config maps
cl, err := client.New(config, client.Options{
Scheme: scheme,
})
if err != nil {
return Configuration{}, err
}

return GetConfiguration(cl)

Check warning on line 284 in pkg/configuration/memberoperatorconfig/configuration.go

View check run for this annotation

Codecov / codecov/patch

pkg/configuration/memberoperatorconfig/configuration.go#L284

Added line #L284 was not covered by tests
}
24 changes: 24 additions & 0 deletions pkg/configuration/memberoperatorconfig/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ import (

commonconfig "github.com/codeready-toolchain/toolchain-common/pkg/configuration"
testconfig "github.com/codeready-toolchain/toolchain-common/pkg/test/config"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"

toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)

func TestAuth(t *testing.T) {
Expand Down Expand Up @@ -300,3 +305,22 @@ func TestWebConsolePlugin(t *testing.T) {
assert.Equal(t, "abc.pendo.io", memberOperatorCfg.WebConsolePlugin().PendoHost())
})
}

func TestGetCRTConfiguration(t *testing.T) {
scheme := runtime.NewScheme()
mockGetter := new(MockConfigGetter)
mockGetter.On("GetCRTConfiguration", mock.Anything, mock.Anything).Return(Configuration{cfg: &toolchainv1alpha1.MemberOperatorConfigSpec{}}, nil)

t.Run("succeeds", func(t *testing.T) {
crtConfig, err := mockGetter.GetCRTConfiguration(&rest.Config{}, scheme)
require.NoError(t, err)
assert.NotEmpty(t, crtConfig)
})

t.Run("fails", func(t *testing.T) {
crtConfig, err := GetCRTConfiguration(&rest.Config{}, scheme)
require.Error(t, err)
assert.Empty(t, crtConfig)
})

}
16 changes: 16 additions & 0 deletions pkg/configuration/memberoperatorconfig/mock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package memberoperatorconfig

import (
"github.com/stretchr/testify/mock"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
)

type MockConfigGetter struct {
mock.Mock
}

func (m *MockConfigGetter) GetCRTConfiguration(config *rest.Config, scheme *runtime.Scheme) (Configuration, error) {
args := m.Called(config, scheme)
return args.Get(0).(Configuration), args.Error(1)
}
Loading