-
-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add tests for proxy use and fix tss.go to use the default transports proxy Image Auto will respect proxy settings now
- Loading branch information
1 parent
5403671
commit 27ad5e0
Showing
9 changed files
with
204 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ package ios_test | |
|
||
import ( | ||
"flag" | ||
"net/http" | ||
"net/url" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
@@ -24,6 +26,81 @@ type SampleData struct { | |
FloatValue float64 | ||
} | ||
|
||
func TestUseHttpProxy(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
proxyUrl string | ||
envProxy string | ||
envHttps string | ||
expectErr bool | ||
}{ | ||
{ | ||
name: "Valid proxy URL", | ||
proxyUrl: "http://test:[email protected]:8080", | ||
expectErr: false, | ||
}, | ||
{ | ||
name: "Invalid proxy URL", | ||
proxyUrl: "http://proxy:invalid", | ||
expectErr: true, | ||
}, | ||
{ | ||
name: "Empty proxy URL with valid HTTP_PROXY env", | ||
proxyUrl: "", | ||
envProxy: "http://proxy.example.com:8080", | ||
expectErr: false, | ||
}, | ||
{ | ||
name: "Empty proxy URL with valid HTTPS_PROXY env", | ||
proxyUrl: "", | ||
envHttps: "http://proxy.example.com:8080", | ||
expectErr: false, | ||
}, | ||
{ | ||
name: "Empty proxy URL with invalid HTTP_PROXY env", | ||
proxyUrl: "", | ||
envProxy: "http://proxy:invalid", | ||
expectErr: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
// Set environment variables | ||
if tt.envProxy != "" { | ||
os.Setenv("HTTP_PROXY", tt.envProxy) | ||
defer os.Unsetenv("HTTP_PROXY") | ||
} | ||
if tt.envHttps != "" { | ||
os.Setenv("HTTPS_PROXY", tt.envHttps) | ||
defer os.Unsetenv("HTTPS_PROXY") | ||
} | ||
|
||
err := ios.UseHttpProxy(tt.proxyUrl) | ||
if (err != nil) != tt.expectErr { | ||
t.Errorf("UseHttpProxy() error = %v, expectErr %v", err, tt.expectErr) | ||
} | ||
|
||
if !tt.expectErr { | ||
parsedUrl, _ := url.Parse(tt.proxyUrl) | ||
if tt.proxyUrl == "" { | ||
if tt.envHttps != "" { | ||
parsedUrl, _ = url.Parse(tt.envHttps) | ||
} else if tt.envProxy != "" { | ||
parsedUrl, _ = url.Parse(tt.envProxy) | ||
} | ||
} | ||
proxyFunc := http.DefaultTransport.(*http.Transport).Proxy | ||
req, _ := http.NewRequest("GET", "http://example.com", nil) | ||
proxyUrl, err := proxyFunc(req) | ||
if err != nil || proxyUrl.String() != parsedUrl.String() { | ||
t.Errorf("Expected proxy URL %v, got %v", parsedUrl, proxyUrl) | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestGenericSliceToType(t *testing.T) { | ||
slice := []interface{}{5, 3, 2} | ||
v, err := ios.GenericSliceToType[int](slice) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters