-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR adds tests for utility methods. --------- Co-authored-by: pauhull <[email protected]>
- Loading branch information
Showing
3 changed files
with
343 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package util_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
"github.com/dustin/go-humanize" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/hetznercloud/cli/internal/cmd/util" | ||
"github.com/hetznercloud/hcloud-go/v2/hcloud" | ||
) | ||
|
||
type testDeprecatable struct { | ||
isDeprecated bool | ||
unavailableAfter time.Time | ||
deprecationAnnounced time.Time | ||
} | ||
|
||
func (t testDeprecatable) IsDeprecated() bool { | ||
return t.isDeprecated | ||
} | ||
|
||
func (t testDeprecatable) UnavailableAfter() time.Time { | ||
return t.unavailableAfter | ||
} | ||
|
||
func (t testDeprecatable) DeprecationAnnounced() time.Time { | ||
return t.deprecationAnnounced | ||
} | ||
|
||
func TestDescribeDeprecation(t *testing.T) { | ||
|
||
time.Local = time.UTC | ||
|
||
type testCase struct { | ||
deprecatable hcloud.Deprecatable | ||
expected string | ||
} | ||
|
||
dep := testDeprecatable{ | ||
isDeprecated: true, | ||
unavailableAfter: time.Date(2021, 12, 31, 23, 59, 59, 0, time.UTC), | ||
deprecationAnnounced: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC), | ||
} | ||
|
||
tests := map[string]testCase{ | ||
"not deprecated": { | ||
deprecatable: testDeprecatable{ | ||
isDeprecated: false, | ||
}, | ||
expected: "", | ||
}, | ||
"deprecated": { | ||
deprecatable: dep, | ||
expected: fmt.Sprintf( | ||
"Deprecation:\n Announced:\t\tFri Jan 1 00:00:00 UTC 2021 (%s)\n Unavailable After:\tFri Dec 31 23:59:59 UTC 2021 (%s)\n", | ||
humanize.Time(dep.DeprecationAnnounced()), humanize.Time(dep.UnavailableAfter()), | ||
), | ||
}, | ||
} | ||
|
||
for name, test := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
info := util.DescribeDeprecation(test.deprecatable) | ||
assert.Equal(t, test.expected, info) | ||
}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.