diff options
| author | jannfis <jann@mistrust.net> | 2021-10-26 22:43:34 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-26 22:43:34 +0200 |
| commit | a03f31915d71ae39f1c9ac5d7d4d1501d11d158b (patch) | |
| tree | c9a87b7da7d4505e18b7bdc2344ef011e8fc037c /ext/git/git_test.go | |
| parent | b4f28e8f48d38559b23453e1e913f6bb3361fc25 (diff) | |
chore: Update and refactor Git client (#283)
Signed-off-by: jannfis <jann@mistrust.net>
Diffstat (limited to 'ext/git/git_test.go')
| -rw-r--r-- | ext/git/git_test.go | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/ext/git/git_test.go b/ext/git/git_test.go index 68bdbd2..8738b75 100644 --- a/ext/git/git_test.go +++ b/ext/git/git_test.go @@ -129,11 +129,11 @@ func TestSameURL(t *testing.T) { } func TestCustomHTTPClient(t *testing.T) { - certFile, err := filepath.Abs("testdata/certs/argocd-test-client.crt") + certFile, err := filepath.Abs("../../test/fixture/certs/argocd-test-client.crt") assert.NoError(t, err) assert.NotEqual(t, "", certFile) - keyFile, err := filepath.Abs("testdata/certs/argocd-test-client.key") + keyFile, err := filepath.Abs("../../test/fixture/certs/argocd-test-client.key") assert.NoError(t, err) assert.NotEqual(t, "", keyFile) @@ -146,8 +146,8 @@ func TestCustomHTTPClient(t *testing.T) { assert.NotEqual(t, "", string(keyData)) // Get HTTPSCreds with client cert creds specified, and insecure connection - creds := NewHTTPSCreds("test", "test", string(certData), string(keyData), false) - client := GetRepoHTTPClient("https://localhost:9443/foo/bar", false, creds) + creds := NewHTTPSCreds("test", "test", string(certData), string(keyData), false, "http://proxy:5000") + client := GetRepoHTTPClient("https://localhost:9443/foo/bar", false, creds, "http://proxy:5000") assert.NotNil(t, client) assert.NotNil(t, client.Transport) if client.Transport != nil { @@ -166,11 +166,19 @@ func TestCustomHTTPClient(t *testing.T) { assert.NotNil(t, cert.PrivateKey) } } + proxy, err := httpClient.Proxy(nil) + assert.Nil(t, err) + assert.Equal(t, "http://proxy:5000", proxy.String()) } + os.Setenv("http_proxy", "http://proxy-from-env:7878") + defer func() { + assert.Nil(t, os.Unsetenv("http_proxy")) + }() + // Get HTTPSCreds without client cert creds, but insecure connection - creds = NewHTTPSCreds("test", "test", "", "", true) - client = GetRepoHTTPClient("https://localhost:9443/foo/bar", true, creds) + creds = NewHTTPSCreds("test", "test", "", "", true, "") + client = GetRepoHTTPClient("https://localhost:9443/foo/bar", true, creds, "") assert.NotNil(t, client) assert.NotNil(t, client.Transport) if client.Transport != nil { @@ -189,11 +197,16 @@ func TestCustomHTTPClient(t *testing.T) { assert.Nil(t, cert.PrivateKey) } } + req, err := http.NewRequest("GET", "http://proxy-from-env:7878", nil) + assert.Nil(t, err) + proxy, err := httpClient.Proxy(req) + assert.Nil(t, err) + assert.Equal(t, "http://proxy-from-env:7878", proxy.String()) } } func TestLsRemote(t *testing.T) { - clnt, err := NewClientExt("https://github.com/argoproj/argo-cd.git", "/tmp", NopCreds{}, false, false) + clnt, err := NewClientExt("https://github.com/argoproj/argo-cd.git", "/tmp", NopCreds{}, false, false, "") assert.NoError(t, err) xpass := []string{ "HEAD", @@ -238,7 +251,7 @@ func TestLFSClient(t *testing.T) { defer func() { _ = os.RemoveAll(tempDir) }() } - client, err := NewClientExt("https://github.com/argoproj-labs/argocd-testrepo-lfs", tempDir, NopCreds{}, false, true) + client, err := NewClientExt("https://github.com/argoproj-labs/argocd-testrepo-lfs", tempDir, NopCreds{}, false, true, "") assert.NoError(t, err) commitSHA, err := client.LsRemote("HEAD") @@ -248,7 +261,7 @@ func TestLFSClient(t *testing.T) { err = client.Init() assert.NoError(t, err) - err = client.Fetch() + err = client.Fetch("") assert.NoError(t, err) err = client.Checkout(commitSHA) @@ -271,22 +284,19 @@ func TestLFSClient(t *testing.T) { } func TestVerifyCommitSignature(t *testing.T) { - if os.Getenv("GNUPG_DISABLED") == "true" { - t.Skip() - } p, err := ioutil.TempDir("", "test-verify-commit-sig") if err != nil { panic(err.Error()) } defer os.RemoveAll(p) - client, err := NewClientExt("https://github.com/argoproj/argo-cd.git", p, NopCreds{}, false, false) + client, err := NewClientExt("https://github.com/argoproj/argo-cd.git", p, NopCreds{}, false, false, "") assert.NoError(t, err) err = client.Init() assert.NoError(t, err) - err = client.Fetch() + err = client.Fetch("") assert.NoError(t, err) commitSHA, err := client.LsRemote("HEAD") @@ -317,7 +327,6 @@ func TestNewFactory(t *testing.T) { defer addBinDirToPath.Close() closer := log.Debug() defer closer() - type args struct { url string insecureIgnoreHostKey bool @@ -326,8 +335,7 @@ func TestNewFactory(t *testing.T) { name string args args }{ - {"Github", args{url: "https://github.com/argoproj/argocd-example-apps"}}, - {"Azure", args{url: "https://jsuen0437@dev.azure.com/jsuen0437/jsuen/_git/jsuen"}}, + {"GitHub", args{url: "https://github.com/argoproj/argocd-example-apps"}}, } for _, tt := range tests { @@ -339,7 +347,7 @@ func TestNewFactory(t *testing.T) { assert.NoError(t, err) defer func() { _ = os.RemoveAll(dirName) }() - client, err := NewClientExt(tt.args.url, dirName, NopCreds{}, tt.args.insecureIgnoreHostKey, false) + client, err := NewClientExt(tt.args.url, dirName, NopCreds{}, tt.args.insecureIgnoreHostKey, false, "") assert.NoError(t, err) commitSHA, err := client.LsRemote("HEAD") assert.NoError(t, err) @@ -347,11 +355,11 @@ func TestNewFactory(t *testing.T) { err = client.Init() assert.NoError(t, err) - err = client.Fetch() + err = client.Fetch("") assert.NoError(t, err) // Do a second fetch to make sure we can treat `already up-to-date` error as not an error - err = client.Fetch() + err = client.Fetch("") assert.NoError(t, err) err = client.Checkout(commitSHA) @@ -380,7 +388,7 @@ func TestListRevisions(t *testing.T) { defer os.RemoveAll(dir) repoURL := "https://github.com/argoproj/argo-cd.git" - client, err := NewClientExt(repoURL, dir, NopCreds{}, false, false) + client, err := NewClientExt(repoURL, dir, NopCreds{}, false, false, "") assert.NoError(t, err) lsResult, err := client.LsRefs() |
