File: client_test.go

package info (click to toggle)
golang-github-akamai-akamaiopen-edgegrid-golang 1.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,408 kB
  • sloc: sh: 532; makefile: 3
file content (87 lines) | stat: -rw-r--r-- 2,408 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
76
77
78
79
80
81
82
83
84
85
86
87
package client

import (
	"net/http"
	"strings"
	"testing"

	"github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid"
	"github.com/stretchr/testify/assert"
)

func TestNewRequest(t *testing.T) {
	t.Skip("DM-Skipped")
	config := edgegrid.Config{
		Host:         "https://httpbin.org",
		AccessToken:  "local-config",
		ClientSecret: "local-config",
		ClientToken:  "local-config",
	}

	req, err := NewRequest(config, "GET", "/headers", nil)
	assert.NotNil(t, req)
	assert.NoError(t, err)
	assert.Equal(t, "https://httpbin.org/headers", req.URL.String())
	verifyResponseConfig(t, config, req)
}

func TestNewRequestWithSwitchedAccount(t *testing.T) {
	t.Skip("DM-Skipped")
	config := edgegrid.Config{
		Host:         "https://httpbin.org",
		AccessToken:  "local-config",
		ClientSecret: "local-config",
		ClientToken:  "local-config",
		AccountKey:   "ABC-DEF",
	}

	req, err := NewRequest(config, "GET", "/headers", nil)
	assert.NotNil(t, req)
	assert.NoError(t, err)
	assert.Equal(t, "https://httpbin.org/headers?accountSwitchKey=ABC-DEF", req.URL.String())
	verifyResponseConfig(t, config, req)
}

func TestNewJSONRequest(t *testing.T) {
	t.Skip("DM-Skipped")
	config := edgegrid.Config{
		Host:         "https://httpbin.org",
		AccessToken:  "local-config",
		ClientSecret: "local-config",
		ClientToken:  "local-config",
	}

	req, err := NewJSONRequest(config, "GET", "/headers", config)
	assert.NotNil(t, req)
	assert.NoError(t, err)
	assert.Equal(t, "https://httpbin.org/headers", req.URL.String())
	verifyResponseConfig(t, config, req)
}

func TestNewJSONRequestWithSwitchedAccount(t *testing.T) {
	t.Skip("DM-Skipped")
	config := edgegrid.Config{
		Host:         "https://httpbin.org",
		AccessToken:  "local-config",
		ClientSecret: "local-config",
		ClientToken:  "local-config",
		AccountKey:   "ABC-DEF",
	}

	req, err := NewJSONRequest(config, "GET", "/headers", config)
	assert.NotNil(t, req)
	assert.NoError(t, err)
	assert.Equal(t, "https://httpbin.org/headers?accountSwitchKey=ABC-DEF", req.URL.String())
	verifyResponseConfig(t, config, req)
}

func verifyResponseConfig(t *testing.T, config edgegrid.Config, req *http.Request) {
	resp, err := Do(config, req)
	assert.NotNil(t, resp)
	assert.NoError(t, err)

	json := make(map[string]interface{})
	BodyJSON(resp, &json)

	assert.True(t, strings.Contains(json["headers"].(map[string]interface{})["Authorization"].(string), "local-config"))
}