-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
kind_api_test.go
45 lines (37 loc) · 1.19 KB
/
kind_api_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"
)
// TestKindApiGet tests functionality of getting an API.
func TestKindApiGet(t *testing.T) {
const dataFile = "testdata/api.json"
const api = "example-grpc-api"
expected := ApiEntityV1alpha1{}
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/api/default/%s", api)).
Reply(200).
File(dataFile)
c, _ := NewClient(baseURL.String(), "", nil)
s := newApiService(&entityService{
client: c,
apiPath: "/catalog/entities",
})
actual, resp, err := s.Get(context.Background(), api, "")
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")
}