Skip to content

Commit

Permalink
Address CRs
Browse files Browse the repository at this point in the history
  • Loading branch information
kimlisa committed Mar 14, 2022
1 parent 2916d66 commit bfd192a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
19 changes: 8 additions & 11 deletions lib/web/apiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ func (s *WebSuite) TestSAMLSuccess(c *C) {

err = s.server.Auth().CreateSAMLConnector(connector)
c.Assert(err, IsNil)
s.server.Auth().SetClock(clockwork.NewFakeClockAt(time.Date(2017, 0o5, 10, 18, 53, 0, 0, time.UTC)))
s.server.Auth().SetClock(clockwork.NewFakeClockAt(time.Date(2017, 5, 10, 18, 53, 0, 0, time.UTC)))
clt := s.clientNoRedirects()

csrfToken := "2ebcb768d0090ea4368e42880c970b61865c326172a4a2343b645cf5d7f20992"
Expand Down Expand Up @@ -772,7 +772,7 @@ func TestClusterNodesGet(t *testing.T) {
nodes := clusterNodesGetResponse{}
require.NoError(t, json.Unmarshal(re.Bytes(), &nodes))
require.Len(t, nodes.Items, 1)
require.Equal(t, nodes.TotalCount, 1)
require.Equal(t, 1, nodes.TotalCount)

// Get nodes using shortcut.
re, err = pack.clt.Get(context.Background(), pack.clt.Endpoint("webapi", "sites", currentSiteShortcut, "nodes"), url.Values{})
Expand Down Expand Up @@ -2003,7 +2003,7 @@ func TestClusterDatabasesGet(t *testing.T) {
resp = testResponse{}
require.NoError(t, json.Unmarshal(re.Bytes(), &resp))
require.Len(t, resp.Items, 1)
require.Equal(t, resp.TotalCount, 1)
require.Equal(t, 1, resp.TotalCount)
require.EqualValues(t, ui.Database{
Name: "test-db-name",
Desc: "test-description",
Expand Down Expand Up @@ -2060,7 +2060,7 @@ func TestClusterKubesGet(t *testing.T) {
resp = testResponse{}
require.NoError(t, json.Unmarshal(re.Bytes(), &resp))
require.Len(t, resp.Items, 1)
require.Equal(t, resp.TotalCount, 1)
require.Equal(t, 1, resp.TotalCount)
require.EqualValues(t, ui.KubeCluster{
Name: "test-kube-name",
Labels: []ui.Label{{Name: "test-field", Value: "test-value"}},
Expand All @@ -2073,10 +2073,6 @@ func TestClusterAppsGet(t *testing.T) {
proxy := env.proxies[0]
pack := proxy.authPack(t, "[email protected]")

endpoint := pack.clt.Endpoint("webapi", "sites", env.server.ClusterName(), "apps")
re, err := pack.clt.Get(context.Background(), endpoint, url.Values{})
require.NoError(t, err)

type testResponse struct {
Items []ui.App `json:"items"`
TotalCount int `json:"totalCount"`
Expand All @@ -2103,18 +2099,19 @@ func TestClusterAppsGet(t *testing.T) {
}

// Register a app service.
_, err = env.server.Auth().UpsertApplicationServer(context.Background(), resource)
_, err := env.server.Auth().UpsertApplicationServer(context.Background(), resource)
require.NoError(t, err)

// Make the call.
re, err = pack.clt.Get(context.Background(), endpoint, url.Values{})
endpoint := pack.clt.Endpoint("webapi", "sites", env.server.ClusterName(), "apps")
re, err := pack.clt.Get(context.Background(), endpoint, url.Values{})
require.NoError(t, err)

// Test correct response.
resp := testResponse{}
require.NoError(t, json.Unmarshal(re.Bytes(), &resp))
require.Len(t, resp.Items, 1)
require.Equal(t, resp.TotalCount, 1)
require.Equal(t, 1, resp.TotalCount)
require.EqualValues(t, ui.App{
Name: resource.Spec.App.GetName(),
Description: resource.Spec.App.GetDescription(),
Expand Down
2 changes: 1 addition & 1 deletion lib/web/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func listResources(clt resourcesAPIGetter, r *http.Request, resourceKind string)
// Sort is expected in format `<fieldName>:<asc|desc>` where
// index 0 is fieldName and index 1 is direction.
// If a direction is not set, or is not recognized, it defaults to ASC.
sortBy := types.SortBy{}
var sortBy types.SortBy
sortParam := values.Get("sort")
if sortParam != "" {
vals := strings.Split(sortParam, ":")
Expand Down
5 changes: 2 additions & 3 deletions lib/web/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,9 @@ func TestListResources(t *testing.T) {
}

_, err = listResources(m, httpReq, types.KindNode)
switch tc.wantBadParamErr {
case true:
if tc.wantBadParamErr {
require.True(t, trace.IsBadParameter(err))
default:
} else {
require.NoError(t, err)
}
})
Expand Down
8 changes: 5 additions & 3 deletions lib/web/ui/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,18 @@ type KubeCluster struct {
func MakeKubeClusters(clusters []types.KubeCluster) []KubeCluster {
uiKubeClusters := make([]KubeCluster, 0, len(clusters))
for _, cluster := range clusters {
uiLabels := []Label{}
staticLabels := cluster.GetStaticLabels()
dynamicLabels := cluster.GetDynamicLabels()
uiLabels := make([]Label, 0, len(staticLabels)+len(dynamicLabels))

for name, value := range cluster.GetStaticLabels() {
for name, value := range staticLabels {
uiLabels = append(uiLabels, Label{
Name: name,
Value: value,
})
}

for name, cmd := range cluster.GetDynamicLabels() {
for name, cmd := range dynamicLabels {
uiLabels = append(uiLabels, Label{
Name: name,
Value: cmd.GetResult(),
Expand Down

0 comments on commit bfd192a

Please sign in to comment.