Skip to content

Commit

Permalink
rename for better readability
Browse files Browse the repository at this point in the history
  • Loading branch information
korotkov-aerospike committed Apr 1, 2024
1 parent 6382a53 commit 4919d6b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
28 changes: 14 additions & 14 deletions pkg/service/configuration_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ type ConfigurationManager interface {
WriteConfiguration(config *model.Config) error
}

type Downloader interface {
Download(string) ([]byte, error)
type Reader interface {
read(string) ([]byte, error)
}

type HTTPDownloader struct{}
type HTTPReader struct{}

func (h HTTPDownloader) Download(url string) ([]byte, error) {
func (h HTTPReader) read(url string) ([]byte, error) {
resp, err := http.Get(url)
if err != nil {
return nil, err
Expand All @@ -38,19 +38,19 @@ func (h HTTPDownloader) Download(url string) ([]byte, error) {

type FileReader struct{}

func (f FileReader) Download(url string) ([]byte, error) {
func (f FileReader) read(url string) ([]byte, error) {
return os.ReadFile(url)
}

type ConfigManagerBuilder struct {
http Downloader
file Downloader
http Reader
file Reader
s3Builder S3ManagerBuilder
}

func NewConfigManagerBuilder() *ConfigManagerBuilder {
return &ConfigManagerBuilder{
http: HTTPDownloader{},
http: HTTPReader{},
file: FileReader{},
s3Builder: S3ManagerBuilderImpl{},
}
Expand All @@ -73,7 +73,7 @@ func (b *ConfigManagerBuilder) NewConfigManager(configFile string, remote bool)
}

func newLocalConfigurationManager(configStorage *model.Storage) (ConfigurationManager, error) {
isHttp, err := isDownload(*configStorage.Path)
isHttp, err := isHttpPath(*configStorage.Path)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -110,19 +110,19 @@ func (b *ConfigManagerBuilder) makeConfigStorage(configUri string, remote bool)
}

func (b *ConfigManagerBuilder) loadFileContent(configFile string) ([]byte, error) {
isDownload, err := isDownload(configFile)
isDownload, err := isHttpPath(configFile)
if err != nil {
return nil, err
}
if isDownload {
return b.http.Download(configFile)
return b.http.read(configFile)
} else {
return b.file.Download(configFile)
return b.file.read(configFile)
}
}

func isDownload(configFile string) (bool, error) {
uri, err := url.Parse(configFile)
func isHttpPath(path string) (bool, error) {
uri, err := url.Parse(path)
if err != nil {
return false, err
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/service/configuration_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type MockDownloader struct {
mock.Mock
}

func (m *MockDownloader) Download(configFile string) ([]byte, error) {
func (m *MockDownloader) read(configFile string) ([]byte, error) {
args := m.Called(configFile)
return args.Get(0).([]byte), args.Error(1)
}
Expand Down Expand Up @@ -65,7 +65,7 @@ func TestConfigManagerBuilder_NewConfigManager(t *testing.T) {
remote: true,
setMock: func() {
mockLocal.
On("Download", "/path/to/remote.yaml").
On("read", "/path/to/remote.yaml").
Return([]byte("path: config.yaml"), nil)
},
expectError: false,
Expand All @@ -77,7 +77,7 @@ func TestConfigManagerBuilder_NewConfigManager(t *testing.T) {
remote: true,
setMock: func() {
mockLocal.
On("Download", "/path/to/remote.yaml").
On("read", "/path/to/remote.yaml").
Return([]byte("path: https://example.com/config.yaml"), nil)
},
expectError: false,
Expand All @@ -89,7 +89,7 @@ func TestConfigManagerBuilder_NewConfigManager(t *testing.T) {
remote: true,
setMock: func() {
mockHttp.
On("Download", "https://example.com/config.yaml").
On("read", "https://example.com/config.yaml").
Return([]byte("path: config.yaml"), nil)
},
expectError: false,
Expand All @@ -101,7 +101,7 @@ func TestConfigManagerBuilder_NewConfigManager(t *testing.T) {
remote: true,
setMock: func() {
mockHttp.
On("Download", "http://path/to/remote.yaml").
On("read", "http://path/to/remote.yaml").
Return([]byte("path: https://example.com/config.yaml"), nil)
},
expectError: false,
Expand All @@ -114,7 +114,7 @@ func TestConfigManagerBuilder_NewConfigManager(t *testing.T) {
remote: true,
setMock: func() {
mockLocal.
On("Download", "config.yaml").
On("read", "config.yaml").
Return([]byte("type: 1\npath: s3://bucket/config.yaml\ns3-region: europe"), nil)
},
expectError: false,
Expand All @@ -126,7 +126,7 @@ func TestConfigManagerBuilder_NewConfigManager(t *testing.T) {
remote: true,
setMock: func() {
mockHttp.
On("Download", "https://example.com/config.yaml").
On("read", "https://example.com/config.yaml").
Return([]byte("type: 1\npath: s3://bucket/config.yaml\ns3-region: europe"), nil)
},
expectError: false,
Expand Down

0 comments on commit 4919d6b

Please sign in to comment.