Skip to content

Commit

Permalink
test: increase test coverage (#712)
Browse files Browse the repository at this point in the history
This PR adds tests for utility methods.

---------

Co-authored-by: pauhull <[email protected]>
  • Loading branch information
phm07 and phm07 authored Apr 3, 2024
1 parent 3b896fe commit e7bb8e5
Show file tree
Hide file tree
Showing 3 changed files with 343 additions and 123 deletions.
70 changes: 70 additions & 0 deletions internal/cmd/util/deprecation_test.go
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)
})
}
}
123 changes: 0 additions & 123 deletions internal/cmd/util/util_internal_test.go

This file was deleted.

Loading

0 comments on commit e7bb8e5

Please sign in to comment.