-
Notifications
You must be signed in to change notification settings - Fork 57
/
api.go
102 lines (91 loc) · 2.7 KB
/
api.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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package testutil
import (
"encoding/json"
"errors"
"net/http"
"net/http/httptest"
"github.com/fastly/go-fastly/v8/fastly"
"github.com/fastly/cli/pkg/commands/whoami"
)
// Err represents a generic error.
var Err = errors.New("test error")
// ListVersions returns a list of service versions in different states.
//
// The first element is active, the second is locked, the third is editable.
//
// NOTE: consult the entire test suite before adding any new entries to the
// returned type as the tests currently use testutil.CloneVersionResult() as a
// way of making the test output and expectations as accurate as possible.
func ListVersions(i *fastly.ListVersionsInput) ([]*fastly.Version, error) {
return []*fastly.Version{
{
ServiceID: i.ServiceID,
Number: 1,
Active: true,
UpdatedAt: MustParseTimeRFC3339("2000-01-01T01:00:00Z"),
},
{
ServiceID: i.ServiceID,
Number: 2,
Active: false,
Locked: true,
UpdatedAt: MustParseTimeRFC3339("2000-01-02T01:00:00Z"),
},
{
ServiceID: i.ServiceID,
Number: 3,
Active: false,
UpdatedAt: MustParseTimeRFC3339("2000-01-03T01:00:00Z"),
},
}, nil
}
// ListVersionsError returns a generic error message when attempting to list
// service versions.
func ListVersionsError(_ *fastly.ListVersionsInput) ([]*fastly.Version, error) {
return nil, Err
}
// CloneVersionResult returns a function which returns a specific cloned version.
func CloneVersionResult(version int) func(i *fastly.CloneVersionInput) (*fastly.Version, error) {
return func(i *fastly.CloneVersionInput) (*fastly.Version, error) {
return &fastly.Version{
ServiceID: i.ServiceID,
Number: version,
}, nil
}
}
// CloneVersionError returns a generic error message when attempting to clone a
// service version.
func CloneVersionError(_ *fastly.CloneVersionInput) (*fastly.Version, error) {
return nil, Err
}
// WhoamiVerifyClient is used by `whoami` and `sso` tests.
type WhoamiVerifyClient whoami.VerifyResponse
// Do executes the HTTP request.
func (c WhoamiVerifyClient) Do(*http.Request) (*http.Response, error) {
rec := httptest.NewRecorder()
_ = json.NewEncoder(rec).Encode(whoami.VerifyResponse(c))
return rec.Result(), nil
}
// WhoamiBasicResponse is used by `whoami` and `sso` tests.
var WhoamiBasicResponse = whoami.VerifyResponse{
Customer: whoami.Customer{
ID: "abc",
Name: "Computer Company",
},
User: whoami.User{
ID: "123",
Name: "Alice Programmer",
Login: "alice@example.com",
},
Services: map[string]string{
"1xxaa": "First service",
"2baba": "Second service",
},
Token: whoami.Token{
ID: "abcdefg",
Name: "Token name",
CreatedAt: "2019-01-01T12:00:00Z",
// no ExpiresAt
Scope: "global",
},
}