Skip to content

Commit

Permalink
Merge pull request #442 from dmage/proxy-errs
Browse files Browse the repository at this point in the history
Check for errors in defer
  • Loading branch information
openshift-merge-robot committed Jan 17, 2020
2 parents a77cb8e + c8a0682 commit 22c5ef8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
6 changes: 3 additions & 3 deletions test/e2e/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func TestOperatorProxyConfiguration(t *testing.T) {
client := framework.MustNewClientset(t, nil)

defer framework.MustRemoveImageRegistry(t, client)
defer framework.ResetClusterProxyConfig(client)
defer framework.MustResetClusterProxyConfig(t, client)

framework.MustDeployImageRegistry(t, client, nil)
framework.MustEnsureImageRegistryIsAvailable(t, client)
Expand Down Expand Up @@ -306,8 +306,8 @@ func TestOperandProxyConfiguration(t *testing.T) {
client := framework.MustNewClientset(t, nil)

defer framework.MustRemoveImageRegistry(t, client)
defer framework.ResetClusterProxyConfig(client)
defer framework.ResetResourceProxyConfig(client)
defer framework.MustResetClusterProxyConfig(t, client)
defer framework.MustResetResourceProxyConfig(t, client)

resourceProxyConfig := imageregistryapiv1.ImageRegistryConfigProxy{
NoProxy: "resourcenoproxy.example.com",
Expand Down
2 changes: 0 additions & 2 deletions test/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ var (
// AsyncOperationTimeout is how long we want to wait for asynchronous
// operations to complete. ForeverTestTimeout is not long enough to create
// several replicas and get them available on a slow machine.
// Setting this to 5 minutes:w

AsyncOperationTimeout = 5 * time.Minute
)

Expand Down
18 changes: 17 additions & 1 deletion test/framework/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package framework

import (
"fmt"
"testing"

"github.com/openshift/cluster-image-registry-operator/defaults"

Expand All @@ -21,10 +22,17 @@ func SetResourceProxyConfig(proxyConfig imageregistryapiv1.ImageRegistryConfigPr
// ResetResourceProxyConfig patches the image registry resource to contain an empty proxy configuration
func ResetResourceProxyConfig(client *Clientset) error {
_, err := client.Configs().Patch(defaults.ImageRegistryResourceName, types.MergePatchType, []byte(`{"spec": {"proxy": {"http": "", "https": "", "noProxy": ""}}}`))

return err
}

// MustResetResourceProxyConfig is like ResetResourceProxyConfig but calls
// t.Fatal if it returns a non-nil error.
func MustResetResourceProxyConfig(t *testing.T, client *Clientset) {
if err := ResetResourceProxyConfig(client); err != nil {
t.Fatal(err)
}
}

// SetClusterProxyConfig patches the cluster proxy resource to contain the provided proxy configuration
func SetClusterProxyConfig(proxyConfig openshiftapiv1.ProxySpec, client *Clientset) error {
_, err := client.Proxies().Patch(defaults.ClusterProxyResourceName, types.MergePatchType, []byte(fmt.Sprintf(`{"spec": {"httpProxy": "%s", "httpsProxy": "%s", "noProxy": "%s"}}`, proxyConfig.HTTPProxy, proxyConfig.HTTPSProxy, proxyConfig.NoProxy)))
Expand All @@ -37,6 +45,14 @@ func ResetClusterProxyConfig(client *Clientset) error {
return err
}

// MustResetClusterProxyConfig is like ResetClusterProxyConfig but calls
// t.Fatal if it returns a non-nil error.
func MustResetClusterProxyConfig(t *testing.T, client *Clientset) {
if err := ResetClusterProxyConfig(client); err != nil {
t.Fatal(err)
}
}

// DumpClusterProxyResource prints out the cluster proxy configuration
func DumpClusterProxyResource(logger Logger, client *Clientset) {
cr, err := client.Proxies().Get(defaults.ClusterProxyResourceName, metav1.GetOptions{})
Expand Down

0 comments on commit 22c5ef8

Please sign in to comment.