Skip to content
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
42 changes: 23 additions & 19 deletions lib/services/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ limitations under the License.
package services

import (
"testing"

"github.com/gravitational/teleport/api/types"
check "gopkg.in/check.v1"
)

type GithubSuite struct{}
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/require"
)

var _ = check.Suite(&GithubSuite{})
func TestUnmarshal(t *testing.T) {
t.Parallel()

func (g *GithubSuite) TestUnmarshal(c *check.C) {
data := []byte(`{"kind": "github",
"version": "v3",
"metadata": {
Expand All @@ -43,7 +45,7 @@ func (g *GithubSuite) TestUnmarshal(c *check.C) {
}]
}}`)
connector, err := UnmarshalGithubConnector(data)
c.Assert(err, check.IsNil)
require.NoError(t, err)
expected, err := types.NewGithubConnector("github", types.GithubConnectorSpecV3{
ClientID: "aaa",
ClientSecret: "bbb",
Expand All @@ -57,11 +59,13 @@ func (g *GithubSuite) TestUnmarshal(c *check.C) {
},
},
})
c.Assert(err, check.IsNil)
c.Assert(expected, check.DeepEquals, connector)
require.NoError(t, err)
require.Empty(t, cmp.Diff(expected, connector))
}

func (g *GithubSuite) TestMapClaims(c *check.C) {
func TestMapClaims(t *testing.T) {
t.Parallel()

connector, err := types.NewGithubConnector("github", types.GithubConnectorSpecV3{
ClientID: "aaa",
ClientSecret: "bbb",
Expand Down Expand Up @@ -90,33 +94,33 @@ func (g *GithubSuite) TestMapClaims(c *check.C) {
},
},
})
c.Assert(err, check.IsNil)
require.NoError(t, err)

roles, kubeGroups, kubeUsers := connector.MapClaims(types.GithubClaims{
OrganizationToTeams: map[string][]string{
"gravitational": {"admins"},
},
})
c.Assert(roles, check.DeepEquals, []string{"admin", "dev", "system"})
c.Assert(kubeGroups, check.DeepEquals, []string{"system:masters", "kube-devs"})
c.Assert(kubeUsers, check.DeepEquals, []string{"alice@example.com"})
require.Empty(t, cmp.Diff(roles, []string{"admin", "dev", "system"}))
require.Empty(t, cmp.Diff(kubeGroups, []string{"system:masters", "kube-devs"}))
require.Empty(t, cmp.Diff(kubeUsers, []string{"alice@example.com"}))

roles, kubeGroups, kubeUsers = connector.MapClaims(types.GithubClaims{
OrganizationToTeams: map[string][]string{
"gravitational": {"devs"},
},
})

c.Assert(roles, check.DeepEquals, []string{"dev", "test"})
c.Assert(kubeGroups, check.DeepEquals, []string{"kube-devs"})
c.Assert(kubeUsers, check.DeepEquals, []string(nil))
require.Empty(t, cmp.Diff(roles, []string{"dev", "test"}))
require.Empty(t, cmp.Diff(kubeGroups, []string{"kube-devs"}))
require.Empty(t, cmp.Diff(kubeUsers, []string(nil)))

roles, kubeGroups, kubeUsers = connector.MapClaims(types.GithubClaims{
OrganizationToTeams: map[string][]string{
"gravitational": {"admins", "devs"},
},
})
c.Assert(roles, check.DeepEquals, []string{"admin", "dev", "test", "system"})
c.Assert(kubeGroups, check.DeepEquals, []string{"system:masters", "kube-devs"})
c.Assert(kubeUsers, check.DeepEquals, []string{"alice@example.com"})
require.Empty(t, cmp.Diff(roles, []string{"admin", "dev", "test", "system"}))
require.Empty(t, cmp.Diff(kubeGroups, []string{"system:masters", "kube-devs"}))
require.Empty(t, cmp.Diff(kubeUsers, []string{"alice@example.com"}))
}
30 changes: 15 additions & 15 deletions lib/services/license_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ limitations under the License.
package services

import (
"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/lib/fixtures"
"fmt"
"testing"

"gopkg.in/check.v1"
"github.com/gravitational/teleport/api/types"

"github.com/gravitational/trace"
)

type LicenseSuite struct {
}
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/require"
)

var _ = check.Suite(&LicenseSuite{})
func TestLicenseUnmarshal(t *testing.T) {
t.Parallel()

func (l *LicenseSuite) TestUnmarshal(c *check.C) {
type testCase struct {
description string
input string
Expand Down Expand Up @@ -103,18 +103,18 @@ func (l *LicenseSuite) TestUnmarshal(c *check.C) {
},
}
for _, tc := range testCases {
comment := check.Commentf("test case %q", tc.description)
comment := fmt.Sprintf("test case %q", tc.description)
out, err := UnmarshalLicense([]byte(tc.input))
if tc.err == nil {
c.Assert(err, check.IsNil, comment)
fixtures.DeepCompare(c, tc.expected, out)
require.NoError(t, err, comment)
require.Empty(t, cmp.Diff(tc.expected, out))
data, err := MarshalLicense(out)
c.Assert(err, check.IsNil, comment)
require.NoError(t, err, comment)
out2, err := UnmarshalLicense(data)
c.Assert(err, check.IsNil, comment)
fixtures.DeepCompare(c, tc.expected, out2)
require.NoError(t, err, comment)
require.Empty(t, cmp.Diff(tc.expected, out2))
} else {
c.Assert(err, check.FitsTypeOf, tc.err, comment)
require.IsType(t, err, tc.err, comment)
}
}
}
Expand Down
22 changes: 13 additions & 9 deletions lib/services/local/desktops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,25 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/lib/backend"
"github.com/gravitational/teleport/lib/backend/lite"
"github.com/gravitational/teleport/lib/backend/memory"

"github.com/jonboulle/clockwork"
"github.com/stretchr/testify/require"
)

func TestListWindowsDesktops(t *testing.T) {
t.Parallel()

ctx := context.Background()
clock := clockwork.NewFakeClock()

liteBackend, err := lite.NewWithConfig(ctx, lite.Config{
Path: t.TempDir(),
Clock: clockwork.NewFakeClock(),
bk, err := memory.New(memory.Config{
Context: ctx,
Clock: clock,
})
require.NoError(t, err)

service := NewWindowsDesktopService(liteBackend)
service := NewWindowsDesktopService(bk)

// Initially we expect no desktops.
out, err := service.ListWindowsDesktops(ctx, types.ListWindowsDesktopsRequest{
Expand Down Expand Up @@ -111,15 +113,17 @@ func TestListWindowsDesktops(t *testing.T) {

func TestListWindowsDesktops_Filters(t *testing.T) {
t.Parallel()

ctx := context.Background()
clock := clockwork.NewFakeClock()

liteBackend, err := lite.NewWithConfig(ctx, lite.Config{
Path: t.TempDir(),
Clock: clockwork.NewFakeClock(),
bk, err := memory.New(memory.Config{
Context: ctx,
Clock: clock,
})
require.NoError(t, err)

service := NewWindowsDesktopService(liteBackend)
service := NewWindowsDesktopService(bk)

// Upsert some windows desktops.

Expand Down
Loading