Skip to content

Commit

Permalink
Update mocks for regional-ga
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerhance authored and bowei committed Jan 8, 2020
1 parent d2b208a commit 97aee3f
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions pkg/cloud/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,21 @@ func UpdateBetaRegionHealthCheckHook(ctx context.Context, key *meta.Key, obj *be
return nil
}

// UpdateRegionHealthCheckHook defines the hook for updating a HealthCheck. It
// replaces the object with the same key in the mock with the updated object.
func UpdateRegionHealthCheckHook(ctx context.Context, key *meta.Key, obj *ga.HealthCheck, m *cloud.MockRegionHealthChecks) error {
if _, err := m.Get(ctx, key); err != nil {
return err
}

obj.Name = key.Name
projectID := m.ProjectRouter.ProjectID(ctx, "ga", "healthChecks")
obj.SelfLink = cloud.SelfLink(meta.VersionGA, projectID, "healthChecks", key)

m.Objects[*key] = &cloud.MockRegionHealthChecksObj{Obj: obj}
return nil
}

// UpdateRegionBackendServiceHook defines the hook for updating a Region
// BackendsService. It replaces the object with the same key in the mock with
// the updated object.
Expand Down Expand Up @@ -655,6 +670,22 @@ func UpdateBetaRegionURLMapHook(ctx context.Context, key *meta.Key, obj *alpha.U
return nil
}

// UpdateRegionURLMapHook defines the hook for updating a GA Regional UrlMap.
// It replaces the object with the same key in the mock with the updated object.
func UpdateRegionURLMapHook(ctx context.Context, key *meta.Key, obj *ga.UrlMap, m *cloud.MockRegionUrlMaps) error {
_, err := m.Get(ctx, key)
if err != nil {
return err
}

obj.Name = key.Name
projectID := m.ProjectRouter.ProjectID(ctx, "ga", "urlMaps")
obj.SelfLink = cloud.SelfLink(meta.VersionGA, projectID, "urlMaps", key)

m.Objects[*key] = &cloud.MockRegionUrlMapsObj{Obj: obj}
return nil
}

// SetTargetGlobalForwardingRuleHook defines the hook for setting the target proxy for a GlobalForwardingRule.
func SetTargetGlobalForwardingRuleHook(ctx context.Context, key *meta.Key, obj *ga.TargetReference, m *cloud.MockGlobalForwardingRules) error {
fw, err := m.Get(ctx, key)
Expand Down Expand Up @@ -754,6 +785,17 @@ func SetURLMapBetaRegionTargetHTTPSProxyHook(ctx context.Context, key *meta.Key,
return nil
}

// SetURLMapRegionTargetHTTPProxyHook defines the hook for setting the url map for a TargetHttpProxy.
func SetURLMapRegionTargetHTTPSProxyHook(ctx context.Context, key *meta.Key, ref *ga.UrlMapReference, m *cloud.MockRegionTargetHttpsProxies) error {
tp, err := m.Get(ctx, key)
if err != nil {
return err
}

tp.UrlMap = ref.UrlMap
return nil
}

// SetURLMapAlphaTargetHTTPProxyHook defines the hook for setting the url map for a TargetHttpProxy.
func SetURLMapAlphaTargetHTTPProxyHook(ctx context.Context, key *meta.Key, ref *alpha.UrlMapReference, m *cloud.MockAlphaTargetHttpProxies) error {
tp, err := m.Get(ctx, key)
Expand Down Expand Up @@ -787,6 +829,17 @@ func SetURLMapBetaRegionTargetHTTPProxyHook(ctx context.Context, key *meta.Key,
return nil
}

// SetURLMapRegionTargetHTTPProxyHook defines the hook for setting the url map for a TargetHttpProxy.
func SetURLMapRegionTargetHTTPProxyHook(ctx context.Context, key *meta.Key, ref *ga.UrlMapReference, m *cloud.MockRegionTargetHttpProxies) error {
tp, err := m.Get(ctx, key)
if err != nil {
return err
}

tp.UrlMap = ref.UrlMap
return nil
}

// SetSslCertificateTargetHTTPSProxyHook defines the hook for setting ssl certificates on a TargetHttpsProxy.
func SetSslCertificateTargetHTTPSProxyHook(ctx context.Context, key *meta.Key, req *ga.TargetHttpsProxiesSetSslCertificatesRequest, m *cloud.MockTargetHttpsProxies) error {
tp, err := m.Get(ctx, key)
Expand Down Expand Up @@ -830,6 +883,18 @@ func SetSslCertificateBetaRegionTargetHTTPSProxyHook(ctx context.Context, key *m
return nil
}

// SetSslCertificateRegionTargetHTTPSProxyHook defines the hook for setting ssl certificates on a TargetHttpsProxy.
func SetSslCertificateRegionTargetHTTPSProxyHook(ctx context.Context, key *meta.Key, req *ga.TargetHttpsProxiesSetSslCertificatesRequest, m *cloud.MockRegionTargetHttpsProxies) error {
tp, err := m.Get(ctx, key)
if err != nil {
return err
}

tp.SslCertificates = req.SslCertificates
return nil
}


// InsertFirewallsUnauthorizedErrHook mocks firewall insertion. A forbidden error will be thrown as return.
func InsertFirewallsUnauthorizedErrHook(ctx context.Context, key *meta.Key, obj *ga.Firewall, m *cloud.MockFirewalls) (bool, error) {
return true, &googleapi.Error{Code: http.StatusForbidden}
Expand Down

0 comments on commit 97aee3f

Please sign in to comment.