-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
kind_user_test.go
45 lines (37 loc) · 1.19 KB
/
kind_user_test.go
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
package backstage
import (
"context"
"encoding/json"
"fmt"
"net/url"
"os"
"testing"
"github.com/h2non/gock"
"github.com/stretchr/testify/assert"
)
// TestKindUserGet tests functionality of getting a user.
func TestKindUserGet(t *testing.T) {
const dataFile = "testdata/user.json"
const user = "guest"
expected := UserEntityV1alpha1{}
expectedData, _ := os.ReadFile(dataFile)
err := json.Unmarshal(expectedData, &expected)
assert.FileExists(t, dataFile, "Test data file should exist")
assert.NoError(t, err, "Unmarshal should not return an error")
baseURL, _ := url.Parse("https://foo:1234/api")
defer gock.Off()
gock.New(baseURL.String()).
MatchHeader("Accept", "application/json").
Get(fmt.Sprintf("/catalog/entities/by-name/user/default/%s", user)).
Reply(200).
File(dataFile)
c, _ := NewClient(baseURL.String(), "", nil)
s := newUserService(&entityService{
client: c,
apiPath: "/catalog/entities",
})
actual, resp, err := s.Get(context.Background(), user, "")
assert.NoError(t, err, "Get should not return an error")
assert.NotEmpty(t, resp, "Response should not be empty")
assert.EqualValues(t, &expected, actual, "Response body should match the one from the server")
}