-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathcodespaces_machines_test.go
More file actions
149 lines (132 loc) · 3.89 KB
/
codespaces_machines_test.go
File metadata and controls
149 lines (132 loc) · 3.89 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Copyright 2025 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package github
import (
"fmt"
"net/http"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestCodespacesService_ListRepositoryMachineTypes(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
mux.HandleFunc("/repos/owner/repo/codespaces/machines", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{
"ref": "main",
"location": "WestUs2",
"client_ip": "1.2.3.4",
})
fmt.Fprint(w, `{
"total_count": 1,
"machines": [
{
"name": "standardLinux",
"display_name": "4 cores, 8 GB RAM, 64 GB storage",
"operating_system": "linux",
"storage_in_bytes": 68719476736,
"memory_in_bytes": 17179869184,
"cpus": 4,
"prebuild_availability": "ready"
}
]
}`)
})
ctx := t.Context()
opts := &ListRepoMachineTypesOptions{
Ref: Ptr("main"),
Location: Ptr("WestUs2"),
ClientIP: Ptr("1.2.3.4"),
}
got, _, err := client.Codespaces.ListRepositoryMachineTypes(
ctx,
"owner",
"repo",
opts,
)
if err != nil {
t.Fatalf("Codespaces.ListRepositoryMachineTypes returned error: %v", err)
}
want := &CodespacesMachines{
TotalCount: 1,
Machines: []*CodespacesMachine{
{
Name: Ptr("standardLinux"),
DisplayName: Ptr("4 cores, 8 GB RAM, 64 GB storage"),
OperatingSystem: Ptr("linux"),
StorageInBytes: Ptr(int64(68719476736)),
MemoryInBytes: Ptr(int64(17179869184)),
CPUs: Ptr(4),
PrebuildAvailability: Ptr("ready"),
},
},
}
if !cmp.Equal(got, want) {
t.Errorf("Codespaces.ListRepositoryMachineTypes returned %+v, want %+v", got, want)
}
const methodName = "ListRepositoryMachineTypes"
testBadOptions(t, methodName, func() error {
_, _, err := client.Codespaces.ListRepositoryMachineTypes(ctx, "\n", "/n", opts)
return err
})
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Codespaces.ListRepositoryMachineTypes(ctx, "/n", "/n", opts)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}
func TestCodespacesService_ListCodespaceMachineTypes(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
mux.HandleFunc("/user/codespaces/codespace_1/machines", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{
"total_count": 1,
"machines": [
{
"name": "standardLinux",
"display_name": "4 cores, 8 GB RAM, 64 GB storage",
"operating_system": "linux",
"storage_in_bytes": 68719476736,
"memory_in_bytes": 17179869184,
"cpus": 4,
"prebuild_availability": "ready"
}
]
}`)
})
ctx := t.Context()
got, _, err := client.Codespaces.ListCodespaceMachineTypes(ctx, "codespace_1")
if err != nil {
t.Fatalf("Codespaces.ListCodespaceMachineTypes returned error: %v", err)
}
want := &CodespacesMachines{
TotalCount: 1,
Machines: []*CodespacesMachine{
{
Name: Ptr("standardLinux"),
DisplayName: Ptr("4 cores, 8 GB RAM, 64 GB storage"),
OperatingSystem: Ptr("linux"),
StorageInBytes: Ptr(int64(68719476736)),
MemoryInBytes: Ptr(int64(17179869184)),
CPUs: Ptr(4),
PrebuildAvailability: Ptr("ready"),
},
},
}
if !cmp.Equal(got, want) {
t.Errorf("Codespaces.ListCodespaceMachineTypes returned %+v, want %+v", got, want)
}
const methodName = "ListCodespaceMachineTypes"
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Codespaces.ListCodespaceMachineTypes(ctx, "/n")
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}