Skip to content
This repository has been archived by the owner on Mar 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #74 from magneticio/feature/restclient-interface
Browse files Browse the repository at this point in the history
Feature/restclient interface
  • Loading branch information
avalcepina authored Nov 11, 2019
2 parents 32dbb76 + ab561eb commit 2ba6d9a
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
23 changes: 23 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,29 @@ var resourceMap map[string]string = map[string]string{
"experiments": "experiment",
}

type IRestClient interface {
Login(username string, password string) (refreshToken string, accessToken string, err error)
RefreshTokens() (refreshToken string, accessToken string, err error)
Create(resourceName string, name string, source string, sourceType string, values map[string]string) (bool, error)
Update(resourceName string, name string, source string, sourceType string, values map[string]string) (bool, error)
PushMetricValueInternal(name string, source string, sourceType string, values map[string]string) (bool, error)
PushMetricValue(name string, metricValue *models.MetricValue, values map[string]string) (bool, error)
Apply(resourceName string, name string, source string, sourceType string, values map[string]string, update bool) (bool, error)
Delete(resourceName string, name string, values map[string]string) (bool, error)
UpdatePassword(userName string, password string, values map[string]string) error
GetSpec(resourceName string, name string, outputFormat string, values map[string]string) (string, error)
Get(resourceName string, name string, outputFormat string, values map[string]string) (string, error)
List(resourceName string, outputFormat string, values map[string]string, simple bool) (string, error)
UpdateUserPermission(username string, permission string, values map[string]string) (bool, error)
RemovePermissionFromUser(username string, values map[string]string) (bool, error)
AddRoleToUser(username string, rolename string, values map[string]string) (bool, error)
RemoveRoleFromUser(username string, rolename string, values map[string]string) (bool, error)
Ping() (bool, error)
ReadNotifications(notifications chan<- models.Notification) error
SendExperimentMetric(experimentName string, metricName string, experimentMetric *models.ExperimentMetric, values map[string]string) error
GetSubsetMap(values map[string]string) (*models.DestinationsSubsetsMap, error)
}

type RestClient struct {
URL string
Version string
Expand Down
105 changes: 105 additions & 0 deletions client/mock_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package client

import (
"github.com/magneticio/vampkubistcli/models"
"github.com/stretchr/testify/mock"
)

type RestClientMock struct {
mock.Mock
}

func (m *RestClientMock) Login(username string, password string) (refreshToken string, accessToken string, err error) {
args := m.Called(username, password)
return args.Get(0).(string), args.Get(1).(string), args.Error(2)
}

func (m *RestClientMock) RefreshTokens() (refreshToken string, accessToken string, err error) {
args := m.Called()
return args.Get(0).(string), args.Get(1).(string), args.Error(2)
}

func (m *RestClientMock) Create(resourceName string, name string, source string, sourceType string, values map[string]string) (bool, error) {
args := m.Called(resourceName, name, source, sourceType, values)
return args.Get(0).(bool), args.Error(2)
}

func (m *RestClientMock) Update(resourceName string, name string, source string, sourceType string, values map[string]string) (bool, error) {
args := m.Called(resourceName, name, source, sourceType, values)
return args.Get(0).(bool), args.Error(1)
}

func (m *RestClientMock) PushMetricValueInternal(name string, source string, sourceType string, values map[string]string) (bool, error) {
args := m.Called(name, source, sourceType, values)
return args.Get(0).(bool), args.Error(1)
}

func (m *RestClientMock) PushMetricValue(name string, metricValue *models.MetricValue, values map[string]string) (bool, error) {
args := m.Called(name, metricValue, values)
return args.Get(0).(bool), args.Error(1)
}

func (m *RestClientMock) Delete(resourceName string, name string, values map[string]string) (bool, error) {
args := m.Called(resourceName, name, values)
return args.Get(0).(bool), args.Error(1)
}

func (m *RestClientMock) UpdatePassword(userName string, password string, values map[string]string) error {
args := m.Called(userName, password, values)
return args.Error(0)
}

func (m *RestClientMock) GetSpec(resourceName string, name string, outputFormat string, values map[string]string) (string, error) {
args := m.Called(resourceName, name, outputFormat, values)
return args.Get(0).(string), args.Error(1)
}

func (m *RestClientMock) Get(resourceName string, name string, outputFormat string, values map[string]string) (string, error) {
args := m.Called(resourceName, name, outputFormat, values)
return args.Get(0).(string), args.Error(1)
}

func (m *RestClientMock) List(resourceName string, outputFormat string, values map[string]string, simple bool) (string, error) {
args := m.Called(resourceName, outputFormat, values, simple)
return args.Get(0).(string), args.Error(1)
}

func (m *RestClientMock) UpdateUserPermission(username string, permission string, values map[string]string) (bool, error) {
args := m.Called(username, permission, values)
return args.Get(0).(bool), args.Error(1)
}

func (m *RestClientMock) RemovePermissionFromUser(username string, values map[string]string) (bool, error) {
args := m.Called(username, values)
return args.Get(0).(bool), args.Error(1)
}

func (m *RestClientMock) AddRoleToUser(username string, rolename string, values map[string]string) (bool, error) {
args := m.Called(username, rolename, values)
return args.Get(0).(bool), args.Error(1)
}

func (m *RestClientMock) RemoveRoleFromUser(username string, rolename string, values map[string]string) (bool, error) {
args := m.Called(username, rolename, values)
return args.Get(0).(bool), args.Error(1)
}

func (m *RestClientMock) Ping() (bool, error) {
args := m.Called()
return args.Get(0).(bool), args.Error(1)
}

func (m *RestClientMock) ReadNotifications(notifications chan<- models.Notification) error {
args := m.Called()
return args.Error(0)
}

func (m *RestClientMock) SendExperimentMetric(experimentName string, metricName string, experimentMetric *models.ExperimentMetric, values map[string]string) error {
args := m.Called(experimentName, metricName, experimentMetric, values)
return args.Error(0)
}

func (m *RestClientMock) GetSubsetMap(values map[string]string) (*models.DestinationsSubsetsMap, error) {
args := m.Called(values)
return args.Get(0).(*models.DestinationsSubsetsMap), args.Error(1)
}

0 comments on commit 2ba6d9a

Please sign in to comment.