Skip to content

Commit

Permalink
fixup: Move testing of expiration dates to TestValidSubscription
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardGomezEscandell committed Nov 16, 2023
1 parent a0a349e commit 7f07bf2
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions windows-agent/internal/contracts/contracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ func TestProToken(t *testing.T) {
}

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

type subscriptionStatus int
const (
subscribed subscriptionStatus = iota
Expand All @@ -96,30 +98,29 @@ func TestValidSubscription(t *testing.T) {
status subscriptionStatus
expirationErr bool

want bool
wantErr bool
}{
"Succcess when the current subscription is active": {status: subscribed},
"Succcess when the current subscription is expired": {status: expired},
"Success when there is no subscription": {status: unsubscribed},
"Succcess when the current subscription is active": {status: subscribed, want: true},
"Succcess when the current subscription is expired": {status: expired, want: false},
"Success when there is no subscription": {status: unsubscribed, want: false},

"Error when subscription validity cannot be ascertained": {status: subscribed, expirationErr: true, wantErr: true},
}

for name, tc := range testCases {
tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel()

var store mockMSStore
var want bool

switch tc.status {
case subscribed:
want = true
store.expirationDate = time.Now().Add(time.Hour * 24 * 365) // Next year
case expired:
want = false
store.expirationDate = time.Now().Add(-time.Hour * 24 * 365) // Last year
case unsubscribed:
want = false
store.notSubscribed = true
}

Expand All @@ -134,7 +135,7 @@ func TestValidSubscription(t *testing.T) {
}

require.NoError(t, err, "contracts.ValidSubscription should have returned no error")
require.Equal(t, want, got, "Unexpected return from ValidSubscription")
require.Equal(t, tc.want, got, "Unexpected return from ValidSubscription")
})
}
}
Expand Down

0 comments on commit 7f07bf2

Please sign in to comment.