Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teleterm: Define / Set AssumeStartTime fields #38480

Closed
wants to merge 7 commits into from
Closed
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
22 changes: 22 additions & 0 deletions api/types/access_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ package types

import (
"testing"
"time"

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

Expand All @@ -27,3 +30,22 @@ func TestAssertAccessRequestImplementsResourceWithLabels(t *testing.T) {
require.NoError(t, err)
require.Implements(t, (*ResourceWithLabels)(nil), ar)
}

func TestValidateAssumeStartTime(t *testing.T) {
clock := clockwork.NewFakeClock()

// Too far in the future.
invalidStartTime := clock.Now().UTC().Add(1000000 * time.Hour)
err := ValidateAssumeStartTime(invalidStartTime)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know where this function comes from, but shouldn't it accept the clock as an argument? In Go we cannot (shouldn't?) mock the system clock like in Jest. Most of the code that I saw that uses the clockwork package accepts the clock from outside so that tests can pass a fake clock. See lib/utils.VerifyCertificateExpiry for an example.

require.True(t, trace.IsBadParameter(err), "expected bad parameter, got %v", err)

// Valid Zero time.
validTime := time.Time{}
err = ValidateAssumeStartTime(validTime)
require.Empty(t, err)

// Valid time.
validTime = clock.Now().UTC().Add(1 * time.Hour)
err = ValidateAssumeStartTime(validTime)
require.Empty(t, err)
}
89 changes: 60 additions & 29 deletions gen/proto/go/teleport/lib/teleterm/v1/access_request.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading