File: account_betas_test.go

package info (click to toggle)
golang-github-linode-linodego 1.55.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,112 kB
  • sloc: makefile: 96; sh: 52; python: 24
file content (75 lines) | stat: -rw-r--r-- 2,922 bytes parent folder | download | duplicates (2)
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 unit

import (
	"context"
	"fmt"
	"testing"

	"github.com/jarcoal/httpmock"
	"github.com/linode/linodego"
	"github.com/stretchr/testify/assert"
)

func TestAccountBetaProgram_List(t *testing.T) {
	fixtureData, err := fixtures.GetFixture("account_beta_list")
	assert.NoError(t, err)

	var base ClientBaseCase
	base.SetUp(t)
	defer base.TearDown(t)

	base.MockGet("account/betas", fixtureData)

	betaPrograms, err := base.Client.ListAccountBetaPrograms(context.Background(), &linodego.ListOptions{})
	assert.NoError(t, err)
	assert.Len(t, betaPrograms, 1, "Expected exactly 1 beta program")

	betaProgram := betaPrograms[0]

	assert.Equal(t, "example_open", betaProgram.ID, "Expected beta program ID to be 'example_open'")
	assert.Equal(t, "Example Open Beta", betaProgram.Label, "Expected beta program label to be 'Example Open Beta'")
	assert.Equal(t, "This is an open public beta for an example feature.", betaProgram.Description, "Beta program description does not match")
	assert.Equal(t, "2023-07-11 00:00:00 +0000 UTC", betaProgram.Started.String(), "Expected beta program started date to be '2023-07-11T00:00:00'")
	assert.Equal(t, "2023-09-11 00:00:00 +0000 UTC", betaProgram.Enrolled.String(), "Expected beta program enrolled date to be '2023-09-11T00:00:00'")
	assert.Nil(t, betaProgram.Ended, "Expected beta program ended date to be nil")
}

func TestAccountBetaProgram_Get(t *testing.T) {
	fixtureData, err := fixtures.GetFixture("account_beta_get")
	assert.NoError(t, err)

	var base ClientBaseCase
	base.SetUp(t)
	defer base.TearDown(t)

	betaId := "example_open"

	base.MockGet(fmt.Sprintf("account/betas/%s", betaId), fixtureData)

	betaProgram, err := base.Client.GetAccountBetaProgram(context.Background(), betaId)
	assert.NoError(t, err)

	assert.Equal(t, "example_open", betaProgram.ID, "Expected beta program ID to be 'example_open'")
	assert.Equal(t, "Example Open Beta", betaProgram.Label, "Expected beta program label to be 'Example Open Beta'.")
	assert.Equal(t, "This is an open public beta for an example feature.", betaProgram.Description, "Beta program description does not match")
	assert.Equal(t, "2023-07-11 00:00:00 +0000 UTC", betaProgram.Started.String(), "Expected beta program started date to be '2023-07-11T00:00:00'")
	assert.Equal(t, "2023-09-11 00:00:00 +0000 UTC", betaProgram.Enrolled.String(), "Expected beta program enrolled date to be '2023-09-11T00:00:00'")
	assert.Nil(t, betaProgram.Ended, "Expected beta program ended date to be nil")
}

func TestAccountBetaProgram_Join(t *testing.T) {
	client := createMockClient(t)

	betaId := "global_load_balancer_beta"

	requestData := linodego.AccountBetaProgramCreateOpts{
		ID: betaId,
	}

	httpmock.RegisterRegexpResponder("POST", mockRequestURL(t, "account/betas"),
		mockRequestBodyValidate(t, requestData, nil))

	if _, err := client.JoinBetaProgram(context.Background(), requestData); err != nil {
		t.Fatal(err)
	}
}