File: deprecation_test.go

package info (click to toggle)
golang-github-hetznercloud-hcloud-go 2.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,072 kB
  • sloc: sh: 5; makefile: 2
file content (75 lines) | stat: -rw-r--r-- 2,417 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package hcloud

import (
	"testing"
	"time"

	"github.com/stretchr/testify/assert"
)

type TestDeprecatableResource struct {
	DeprecatableResource
}

// Interface is implemented.
var _ Deprecatable = TestDeprecatableResource{}

func TestDeprecatableResource_IsDeprecated(t *testing.T) {
	tests := []struct {
		name     string
		resource TestDeprecatableResource
		want     bool
	}{
		{name: "nil returns false", resource: TestDeprecatableResource{DeprecatableResource: DeprecatableResource{Deprecation: nil}}, want: false},
		{name: "struct returns true", resource: TestDeprecatableResource{DeprecatableResource: DeprecatableResource{Deprecation: &DeprecationInfo{}}}, want: true},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			assert.Equalf(t, tt.want, tt.resource.IsDeprecated(), "IsDeprecated()")
		})
	}
}

func TestDeprecatableResource_DeprecationAnnounced(t *testing.T) {
	tests := []struct {
		name     string
		resource TestDeprecatableResource
		want     time.Time
	}{
		{
			name:     "nil returns default time",
			resource: TestDeprecatableResource{DeprecatableResource: DeprecatableResource{Deprecation: nil}},
			want:     time.Unix(0, 0)},
		{
			name:     "actual value is returned",
			resource: TestDeprecatableResource{DeprecatableResource: DeprecatableResource{Deprecation: &DeprecationInfo{Announced: mustParseTime(t, "2023-06-01T00:00:00+00:00")}}},
			want:     mustParseTime(t, "2023-06-01T00:00:00+00:00")},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			assert.Equalf(t, tt.want, tt.resource.DeprecationAnnounced(), "DeprecationAnnounced()")
		})
	}
}

func TestDeprecatableResource_UnavailableAfter(t *testing.T) {
	tests := []struct {
		name     string
		resource TestDeprecatableResource
		want     time.Time
	}{
		{
			name:     "nil returns default time",
			resource: TestDeprecatableResource{DeprecatableResource: DeprecatableResource{Deprecation: nil}},
			want:     time.Unix(0, 0)},
		{
			name:     "actual value is returned",
			resource: TestDeprecatableResource{DeprecatableResource: DeprecatableResource{Deprecation: &DeprecationInfo{UnavailableAfter: mustParseTime(t, "2023-06-01T00:00:00+00:00")}}},
			want:     mustParseTime(t, "2023-06-01T00:00:00+00:00")},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			assert.Equalf(t, tt.want, tt.resource.UnavailableAfter(), "UnavailableAfter()")
		})
	}
}