File: profile_apps_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 (60 lines) | stat: -rw-r--r-- 1,467 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
package unit

import (
	"context"
	"testing"

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

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

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

	base.MockGet("profile/apps/123", fixtureData)

	app, err := base.Client.GetProfileApp(context.Background(), 123)
	assert.NoError(t, err)

	assert.Equal(t, 123, app.ID)
	assert.Equal(t, "example-app", app.Label)
	assert.Equal(t, "linodes:read_only", app.Scopes)
	assert.Equal(t, "example.org", app.Website)
}

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

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

	base.MockGet("profile/apps", fixtureData)

	apps, err := base.Client.ListProfileApps(context.Background(), nil)
	assert.NoError(t, err)

	assert.Equal(t, 1, len(apps))
	app := apps[0]

	assert.Equal(t, 123, app.ID)
	assert.Equal(t, "example-app", app.Label)
	assert.Equal(t, "linodes:read_only", app.Scopes)
	assert.Equal(t, "example.org", app.Website)
}

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

	httpmock.RegisterRegexpResponder("DELETE", mockRequestURL(t, "profile/apps/123"), httpmock.NewStringResponder(200, "{}"))

	if err := client.DeleteProfileApp(context.Background(), 123); err != nil {
		t.Fatal(err)
	}
}