Skip to content

Commit

Permalink
Merge pull request #30 from mesosphere/mh/fix-tenants-no-cluster-temp…
Browse files Browse the repository at this point in the history
…lates

fix: show no clusters message on workspace handler
  • Loading branch information
mhrabovcin authored Jan 18, 2024
2 parents aed3ec1 + 6415238 commit 94966fc
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
6 changes: 6 additions & 0 deletions templates/index-multitenant.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@
<div class="theme-panel">
<h2 class="theme-heading">Generate Kubernetes Token</h2>
<div>
{{ if .Clusters }}
<p>
Select which cluster you require a token for:
</p>
{{ else }}
<p>
There are no clusters attached to the workspace.
</p>
{{ end }}

{{ range $cluster := .Clusters }}

Expand Down
42 changes: 41 additions & 1 deletion tenancy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -51,6 +52,41 @@ func TestTenancyHandler(t *testing.T) {
assert.Contains(t, rr.Body.String(), "/login/cluster-2?tenant-id=test-tenant")
}

func TestTenancyHandler_NoClusters(t *testing.T) {
m := &tenantsMock{
existsCall: struct {
exists bool
err error
}{
exists: true,
},
filterClusterNamesCall: struct {
names []string
err error
}{
names: []string{},
},
}
rr := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/test-tenant", nil)
c := &Config{
Clusters: []Cluster{
{Name: "cluster-1"},
{Name: "cluster-2"},
},
Web_Path_Prefix: "/",
}

h := NewTenancyHandler(m, c, getTenancyTemplate("index-multitenant.html"))
r := mux.NewRouter()
r.HandleFunc("/{tenantId}", h)
r.ServeHTTP(rr, req)

assert.Equal(t, http.StatusOK, rr.Code, "respbody: %s", rr.Body.String())
assert.NotContains(t, rr.Body.String(), "Select which cluster you require a token for:")
assert.Contains(t, rr.Body.String(), "There are no clusters attached to the workspace.")
}

func TestLandingHandler(t *testing.T) {
m := &tenantsMock{
existsCall: struct {
Expand Down Expand Up @@ -82,7 +118,7 @@ func TestLandingHandler(t *testing.T) {

assert.Equal(t, http.StatusOK, rr.Code, "respbody: %s", rr.Body.String())
assert.Contains(t, rr.Body.String(), "/workspace/test-tenant")
assert.Contains(t, rr.Body.String(), "/dkp/kommander/dashboard?tenant-id=test-tenant")
assert.Contains(t, rr.Body.String(), "/dkp/kommander/dashboard/?tenant-id=test-tenant")
assert.Contains(t, rr.Body.String(), "Test Tenant name")
}

Expand Down Expand Up @@ -116,3 +152,7 @@ func (t *tenantsMock) Get(ctx context.Context, tenantId tenancy.TenantId) (*tena
func (t *tenantsMock) FilterClusterNames(ctx context.Context, tenantId tenancy.TenantId, names []string) ([]string, error) {
return t.filterClusterNamesCall.names, t.filterClusterNamesCall.err
}

func (t *tenantsMock) GetTenantsByCluster(ctx context.Context) (map[string]*tenancy.Tenant, error) {
return nil, fmt.Errorf("not implemented")
}

0 comments on commit 94966fc

Please sign in to comment.