Skip to content
This repository was archived by the owner on Jun 21, 2022. It is now read-only.
Merged
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
3 changes: 3 additions & 0 deletions services/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ func (svc *Service) addQanAgent(ctx context.Context, tx *reform.TX, service *mod
}

func (svc *Service) Add(ctx context.Context, name, address string, port uint32, username, password string) (int32, error) {
address = strings.TrimSpace(address)
username = strings.TrimSpace(username)
name = strings.TrimSpace(name)
if address == "" {
return 0, status.Error(codes.InvalidArgument, "MySQL instance host is not given.")
}
Expand Down
3 changes: 3 additions & 0 deletions services/mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ func TestAddListRemove(t *testing.T) {
_, err = svc.Add(ctx, "", "", 0, "username", "password")
tests.AssertGRPCError(t, status.New(codes.InvalidArgument, `MySQL instance host is not given.`), err)

_, err = svc.Add(ctx, "", " ", 0, "username", "password")
tests.AssertGRPCError(t, status.New(codes.InvalidArgument, `MySQL instance host is not given.`), err)

supervisor.On("Start", mock.Anything, mock.Anything).Return(nil)
supervisor.On("Status", mock.Anything, mock.Anything).Return(fmt.Errorf("not running"))
supervisor.On("Stop", mock.Anything, mock.Anything).Return(nil)
Expand Down
4 changes: 4 additions & 0 deletions services/postgresql/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"os/exec"
"regexp"
"sort"
"strings"
"time"

"github.com/AlekSi/pointer"
Expand Down Expand Up @@ -208,6 +209,9 @@ func (svc *Service) List(ctx context.Context) ([]Instance, error) {

// Add new postgreSQL service and start postgres_exporter
func (svc *Service) Add(ctx context.Context, name, address string, port uint32, username, password string) (int32, error) {
address = strings.TrimSpace(address)
username = strings.TrimSpace(username)
name = strings.TrimSpace(name)
if address == "" {
return 0, status.Error(codes.InvalidArgument, "PostgreSQL instance host is not given.")
}
Expand Down
3 changes: 3 additions & 0 deletions services/postgresql/postgresql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ func TestAddListRemove(t *testing.T) {
_, err = svc.Add(ctx, "", "", 0, "username", "password")
tests.AssertGRPCError(t, status.New(codes.InvalidArgument, `PostgreSQL instance host is not given.`), err)

_, err = svc.Add(ctx, "", " ", 0, "username", "password")
tests.AssertGRPCError(t, status.New(codes.InvalidArgument, `PostgreSQL instance host is not given.`), err)

supervisor.On("Start", mock.Anything, mock.Anything).Return(nil)
supervisor.On("Stop", mock.Anything, mock.Anything).Return(nil)
id, err := svc.Add(ctx, "", "localhost", 0, "username", "password")
Expand Down