Skip to content

Commit

Permalink
suggestions from review
Browse files Browse the repository at this point in the history
  • Loading branch information
aaperis committed Jan 24, 2025
1 parent cb8bd2f commit b3e2c67
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,26 +398,26 @@ func CheckTokenExpiration(accessToken string) error {
}

switch untilExp := time.Until(expiration); {
case untilExp < 0:
case untilExp <= 0:
return fmt.Errorf("the provided access token has expired, please renew it")
case untilExp >= 0 && untilExp < 2*time.Hour:
case untilExp > 0 && untilExp < 2*time.Hour:
fmt.Fprintf(
os.Stderr,
"WARNING! The provided access token expires in only %d hours and %d minutes.\n",
"WARNING! The provided access token expires in only %d hour and %d minutes.\n",
int(untilExp.Hours()), int(untilExp.Minutes())-(int(untilExp.Hours())*60),
)
fmt.Fprintln(os.Stderr, "Consider renewing the token.")
case untilExp >= 2*time.Hour && untilExp < 24*time.Hour:
fmt.Fprintf(
os.Stderr,
"The provided access token expires in %d hours and %d minutes (at %d:%d).\n",
int(untilExp.Hours()), int(untilExp.Minutes())-(int(untilExp.Hours())*60), expiration.Hour(), expiration.Minute(),
"The provided access token expires in %d hours and %d minutes.\n",
int(untilExp.Hours()), int(untilExp.Minutes())-(int(untilExp.Hours())*60),
)
fmt.Fprintln(os.Stderr, "Consider renewing the token.")
default:
fmt.Fprintf(
os.Stderr,
"The provided access token expires on %s.\n", expiration.Format("2006-01-02"),
"The provided access token expires on %s.\n", expiration.Format(time.RFC1123),
)
}

Expand Down
4 changes: 2 additions & 2 deletions helpers/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func (suite *HelperTests) TestTokenExpiration() {
out, _ := io.ReadAll(r)
os.Stderr = storeStderr

msg := "WARNING! The provided access token expires in only 0 hours and 59 minutes."
msg := "WARNING! The provided access token expires in only 0 hour and 59 minutes."
assert.Contains(suite.T(), string(out), msg)

// Token with valid expiration, more than a day
Expand All @@ -359,7 +359,7 @@ func (suite *HelperTests) TestTokenExpiration() {
out, _ = io.ReadAll(r)
os.Stderr = storeStderr

msg = "The provided access token expires on " + exp.Format("2006-01-02")
msg = "The provided access token expires on " + exp.Format(time.RFC1123)
assert.Contains(suite.T(), string(out), msg)
}

Expand Down

0 comments on commit b3e2c67

Please sign in to comment.