Skip to content

Commit

Permalink
removed superfluous error response
Browse files Browse the repository at this point in the history
  • Loading branch information
thorstenkramm committed Aug 10, 2022
1 parent 5f7ebcb commit 000feff
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 28 deletions.
4 changes: 1 addition & 3 deletions internal/pkg/api/clients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ func TestClientsList(t *testing.T) {
},
})

filter, err := NewFilters("name", "abc")
require.NoError(t, err)
clientsResp, err := cl.Clients(context.Background(), NewPaginationWithLimit(ClientsLimitMax), filter)
clientsResp, err := cl.Clients(context.Background(), NewPaginationWithLimit(ClientsLimitMax), NewFilters("name", "abc"))
require.NoError(t, err)

assert.Equal(t, clientsStub, clientsResp.Data)
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/api/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
type Filters map[string]string

// NewFilters constructs filters from key value pairs. Keys with empty values are ignored.
func NewFilters(keyValues ...string) (Filters, error) {
func NewFilters(keyValues ...string) Filters {
f := make(map[string]string)
for i := 0; 2*i+1 < len(keyValues); i++ {
f[keyValues[2*i]] = keyValues[2*i+1]
}
return f, nil
return f
}

// NewFilterFromCombinedSearchString takes a list of key value filters separated by ampersand,
Expand Down
3 changes: 1 addition & 2 deletions internal/pkg/api/filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ import (
)

func TestFilters(t *testing.T) {
filters, err := NewFilters(
filters := NewFilters(
"name", "johny",
"id", "",
"*", "*abc*",
)
require.NoError(t, err)

q := url.Values{}
filters.Apply(q)
Expand Down
6 changes: 1 addition & 5 deletions internal/pkg/controllers/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ func (cc *ClientController) Client(ctx context.Context, params *options.Paramete
return cc.ClientRenderer.RenderClient(client, renderDetails)
}

filter, err := api.NewFilters("name", name)
if err != nil {
return err
}
clients, err := cc.Rport.Clients(ctx, api.NewPaginationWithLimit(2), filter)
clients, err := cc.Rport.Clients(ctx, api.NewPaginationWithLimit(2), api.NewFilters("name", name))
if err != nil {
return err
}
Expand Down
17 changes: 4 additions & 13 deletions internal/pkg/controllers/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,11 @@ type TunnelController struct {
}

func (tc *TunnelController) Tunnels(ctx context.Context, params *options.ParameterBag) error {
filter, err := api.NewFilters(
filter := api.NewFilters(
"id", params.ReadString(config.ClientID, ""),
"name", params.ReadString(config.ClientNameFlag, ""),
"*", params.ReadString(config.ClientSearchFlag, ""),
)
if err != nil {
return err
}
clResp, err := tc.Rport.Clients(
ctx,
api.NewPaginationFromParams(params),
Expand Down Expand Up @@ -111,19 +108,14 @@ func (tc *TunnelController) getClientIDAndClientName(
if clientID != "" {
return
}

clients, err := tc.Rport.Clients(ctx, api.NewPaginationWithLimit(25), api.NewFilters("name", clientName))
filter, err := api.NewFilters("name", clientName)
maxClientsForSelection := 25
clients, err := tc.Rport.Clients(ctx, api.NewPaginationWithLimit(maxClientsForSelection), api.NewFilters("name", clientName))
if err != nil {
return "", "", err
}
clients, err := tc.Rport.Clients(ctx, api.NewPaginationWithLimit(2), filter)
if err != nil {
return
}
var client *models.Client
numClients := len(clients.Data)
maxClientsForSelection := 15

switch {
case numClients == 1:
client = clients.Data[0]
Expand All @@ -145,7 +137,6 @@ func (tc *TunnelController) getClientIDAndClientName(
)
}

client := clients.Data[0]
return client.ID, client.Name, nil
}

Expand Down
3 changes: 0 additions & 3 deletions internal/pkg/controllers/tunnel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,6 @@ func TestTunnelCreateWithPortDiscovery(t *testing.T) {
IPProvider: IPProviderMock{
IP: "3.4.5.9",
},
SSHFunc: func(sshParams []string) error {
return nil
},
}

params := map[string]string{
Expand Down

0 comments on commit 000feff

Please sign in to comment.