Skip to content

Commit 9cfde65

Browse files
authored
test(sidekick): test only with Compute (#2255)
This is the only service we are interested in, and we can make some simplifications if we use it.
1 parent 4a33949 commit 9cfde65

File tree

4 files changed

+44
-245
lines changed

4 files changed

+44
-245
lines changed

internal/sidekick/internal/parser/discovery/discovery_test.go

Lines changed: 24 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,7 @@ import (
2727
)
2828

2929
func TestInfo(t *testing.T) {
30-
got, err := PublicCaDisco(t, nil)
31-
if err != nil {
32-
t.Fatal(err)
33-
}
34-
wantName := "publicca"
35-
wantTitle := "Public Certificate Authority API"
36-
wantDescription := "The Public Certificate Authority API may be used to create and manage ACME external account binding keys associated with Google Trust Services' publicly trusted certificate authority. "
37-
if got.Name != wantName {
38-
t.Errorf("want = %q; got = %q", wantName, got.Name)
39-
}
40-
if got.Title != wantTitle {
41-
t.Errorf("want = %q; got = %q", wantTitle, got.Title)
42-
}
43-
if diff := cmp.Diff(wantDescription, got.Description); diff != "" {
44-
t.Errorf("mismatch (-want +got):\n%s", diff)
45-
}
46-
if got.PackageName != "" {
47-
t.Errorf("expected empty package name")
48-
}
49-
}
50-
51-
func TestComputeParses(t *testing.T) {
52-
contents, err := os.ReadFile("../../../testdata/disco/compute.v1.json")
53-
if err != nil {
54-
t.Fatal(err)
55-
}
56-
got, err := NewAPI(nil, contents)
30+
got, err := ComputeDisco(t, nil)
5731
if err != nil {
5832
t.Fatal(err)
5933
}
@@ -80,7 +54,7 @@ func TestServiceConfigOverridesInfo(t *testing.T) {
8054
sc.Documentation.Summary = "Change the description for testing"
8155
sc.Name = "not-secretmanager"
8256

83-
got, err := PublicCaDisco(t, sc)
57+
got, err := ComputeDisco(t, sc)
8458
if err != nil {
8559
t.Fatal(err)
8660
}
@@ -136,41 +110,42 @@ func TestBadParse(t *testing.T) {
136110
}
137111

138112
func TestMessage(t *testing.T) {
139-
model, err := PublicCaDisco(t, nil)
113+
model, err := ComputeDisco(t, nil)
140114
if err != nil {
141115
t.Fatal(err)
142116
}
143-
id := "..ExternalAccountKey"
117+
id := "..WeightedBackendService"
144118
got, ok := model.State.MessageByID[id]
145119
if !ok {
146120
t.Fatalf("expected message %s in the API model", id)
147121
}
148122
want := &api.Message{
149-
Name: "ExternalAccountKey",
123+
Name: "WeightedBackendService",
150124
ID: id,
151125
Package: "",
152-
Documentation: "A representation of an ExternalAccountKey used for [external account binding](https://tools.ietf.org/html/rfc8555#section-7.3.4) within ACME.",
126+
Documentation: "In contrast to a single BackendService in HttpRouteAction to which all matching traffic is directed to, WeightedBackendService allows traffic to be split across multiple backend services. The volume of traffic for each backend service is proportional to the weight specified in each WeightedBackendService",
153127
Fields: []*api.Field{
154128
{
155-
Name: "b64MacKey",
156-
JSONName: "b64MacKey",
157-
Documentation: "Output only. Base64-URL-encoded HS256 key. It is generated by the PublicCertificateAuthorityService when the ExternalAccountKey is created",
158-
Typez: api.BYTES_TYPE,
159-
TypezID: "bytes",
160-
},
161-
{
162-
Name: "keyId",
163-
JSONName: "keyId",
164-
Documentation: "Output only. Key ID. It is generated by the PublicCertificateAuthorityService when the ExternalAccountKey is created",
129+
Name: "backendService",
130+
JSONName: "backendService",
131+
Documentation: "The full or partial URL to the default BackendService resource. Before forwarding the request to backendService, the load balancer applies any relevant headerActions specified as part of this backendServiceWeight.",
165132
Typez: api.STRING_TYPE,
166133
TypezID: "string",
167134
},
135+
// TODO(#1850) - parse object fields.
136+
// {
137+
// Name: "headerAction",
138+
// JSONName: "headerAction",
139+
// Documentation: "Specifies changes to request and response headers that need to take effect for the selected backendService. headerAction specified here take effect before headerAction in the enclosing HttpRouteRule, PathMatcher and UrlMap. headerAction is not supported for load balancers that have their loadBalancingScheme set to EXTERNAL. Not supported when the URL map is bound to a target gRPC proxy that has validateForProxyless field set to true.",
140+
// Typez: api.MESSAGE_TYPE,
141+
// TypezID: "..HttpHeaderAction",
142+
// },
168143
{
169-
Name: "name",
170-
JSONName: "name",
171-
Documentation: "Output only. Resource name. projects/{project}/locations/{location}/externalAccountKeys/{key_id}",
172-
Typez: api.STRING_TYPE,
173-
TypezID: "string",
144+
Name: "weight",
145+
JSONName: "weight",
146+
Documentation: "Specifies the fraction of traffic sent to a backend service, computed as weight / (sum of all weightedBackendService weights in routeAction) . The selection of a backend service is determined only for new traffic. Once a user's request has been directed to a backend service, subsequent requests are sent to the same backend service as determined by the backend service's session affinity policy. Don't configure session affinity if you're using weighted traffic splitting. If you do, the weighted traffic splitting configuration takes precedence. The value must be from 0 to 1000.",
147+
Typez: api.UINT32_TYPE,
148+
TypezID: "uint32",
174149
},
175150
},
176151
}
@@ -205,9 +180,9 @@ func TestServiceErrors(t *testing.T) {
205180
}
206181
}
207182

208-
func PublicCaDisco(t *testing.T, sc *serviceconfig.Service) (*api.API, error) {
183+
func ComputeDisco(t *testing.T, sc *serviceconfig.Service) (*api.API, error) {
209184
t.Helper()
210-
contents, err := os.ReadFile("../../../testdata/disco/publicca.v1.json")
185+
contents, err := os.ReadFile("../../../testdata/disco/compute.v1.json")
211186
if err != nil {
212187
return nil, err
213188
}

internal/sidekick/internal/parser/discovery/methods_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package discovery
1717
import "testing"
1818

1919
func TestMakeServiceMethodsError(t *testing.T) {
20-
model, err := PublicCaDisco(t, nil)
20+
model, err := ComputeDisco(t, nil)
2121
if err != nil {
2222
t.Fatal(err)
2323
}
@@ -36,7 +36,7 @@ func TestMakeServiceMethodsError(t *testing.T) {
3636
}
3737

3838
func TestMakeMethodError(t *testing.T) {
39-
model, err := PublicCaDisco(t, nil)
39+
model, err := ComputeDisco(t, nil)
4040
if err != nil {
4141
t.Fatal(err)
4242
}

internal/sidekick/internal/parser/discovery/services_test.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,43 @@ import (
2222
)
2323

2424
func TestService(t *testing.T) {
25-
model, err := PublicCaDisco(t, nil)
25+
model, err := ComputeDisco(t, nil)
2626
if err != nil {
2727
t.Fatal(err)
2828
}
29-
if _, ok := model.State.ServiceByID["..projects"]; ok {
30-
t.Errorf("expected no service for `projects` resource as it has no methods")
31-
}
3229

33-
id := "..externalAccountKeys"
30+
id := "..zones"
3431
got, ok := model.State.ServiceByID[id]
3532
if !ok {
3633
t.Fatalf("expected service %s in the API model", id)
3734
}
3835
want := &api.Service{
39-
Name: "externalAccountKeys",
36+
Name: "zones",
4037
ID: id,
4138
Package: "",
42-
Documentation: "Service for the `externalAccountKeys` resource.",
39+
Documentation: "Service for the `zones` resource.",
4340
Methods: []*api.Method{
4441
{
45-
ID: "..externalAccountKeys.create",
46-
Name: "create",
47-
Documentation: "Creates a new ExternalAccountKey bound to the project.",
48-
InputTypeID: "..ExternalAccountKey",
49-
OutputTypeID: "..ExternalAccountKey",
42+
ID: "..zones.get",
43+
Name: "get",
44+
Documentation: "Returns the specified Zone resource.",
45+
InputTypeID: ".google.protobuf.Empty",
46+
OutputTypeID: "..Zone",
47+
},
48+
{
49+
ID: "..zones.list",
50+
Name: "list",
51+
Documentation: "Retrieves the list of Zone resources available to the specified project.",
52+
InputTypeID: ".google.protobuf.Empty",
53+
OutputTypeID: "..ZoneList",
5054
},
5155
},
5256
}
5357
apitest.CheckService(t, got, want)
5458
}
5559

5660
func TestServiceTopLevelMethodErrors(t *testing.T) {
57-
model, err := PublicCaDisco(t, nil)
61+
model, err := ComputeDisco(t, nil)
5862
if err != nil {
5963
t.Fatal(err)
6064
}
@@ -69,7 +73,7 @@ func TestServiceTopLevelMethodErrors(t *testing.T) {
6973
}
7074

7175
func TestServiceChildMethodErrors(t *testing.T) {
72-
model, err := PublicCaDisco(t, nil)
76+
model, err := ComputeDisco(t, nil)
7377
if err != nil {
7478
t.Fatal(err)
7579
}

internal/sidekick/testdata/disco/publicca.v1.json

Lines changed: 0 additions & 180 deletions
This file was deleted.

0 commit comments

Comments
 (0)