本文整理匯總了Golang中github.com/github/git-lfs/config.NewFrom函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewFrom函數的具體用法?Golang NewFrom怎麽用?Golang NewFrom使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewFrom函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestCertVerifyDisabledGlobalEnv
func TestCertVerifyDisabledGlobalEnv(t *testing.T) {
empty := config.NewFrom(config.Values{})
assert.False(t, isCertVerificationDisabledForHost(empty, "anyhost.com"))
cfg := config.NewFrom(config.Values{
Os: map[string]string{
"GIT_SSL_NO_VERIFY": "1",
},
})
assert.True(t, isCertVerificationDisabledForHost(cfg, "anyhost.com"))
}
示例2: TestCommandEnabledFromEnvironmentVariables
func TestCommandEnabledFromEnvironmentVariables(t *testing.T) {
cfg := config.NewFrom(config.Values{
Os: map[string]string{"GITLFSLOCKSENABLED": "1"},
})
assert.True(t, isCommandEnabled(cfg, "locks"))
}
示例3: TestCustomTransferUploadConfig
func TestCustomTransferUploadConfig(t *testing.T) {
path := "/path/to/binary"
args := "-c 1 --whatever"
cfg := config.NewFrom(config.Values{
Git: map[string]string{
"lfs.customtransfer.testupload.path": path,
"lfs.customtransfer.testupload.args": args,
"lfs.customtransfer.testupload.concurrent": "false",
"lfs.customtransfer.testupload.direction": "upload",
},
})
m := ConfigureManifest(NewManifest(), cfg)
d := m.NewDownloadAdapter("testupload")
assert.NotNil(t, d, "Download adapter should always be created")
cd, _ := d.(*customAdapter)
assert.Nil(t, cd, "Download adapter should NOT be custom (default to basic)")
u := m.NewUploadAdapter("testupload")
assert.NotNil(t, u, "Upload adapter should be present")
cu, _ := u.(*customAdapter)
assert.NotNil(t, cu, "Upload adapter should be customAdapter")
assert.Equal(t, cu.path, path, "Path should be correct")
assert.Equal(t, cu.args, args, "args should be correct")
assert.Equal(t, cu.concurrent, false, "concurrent should be set")
}
示例4: TestCustomTransferBothConfig
func TestCustomTransferBothConfig(t *testing.T) {
path := "/path/to/binary"
args := "-c 1 --whatever --yeah"
cfg := config.NewFrom(config.Values{
Git: map[string]string{
"lfs.customtransfer.testboth.path": path,
"lfs.customtransfer.testboth.args": args,
"lfs.customtransfer.testboth.concurrent": "yes",
"lfs.customtransfer.testboth.direction": "both",
},
})
m := ConfigureManifest(NewManifest(), cfg)
d := m.NewDownloadAdapter("testboth")
assert.NotNil(t, d, "Download adapter should be present")
cd, _ := d.(*customAdapter)
assert.NotNil(t, cd, "Download adapter should be customAdapter")
assert.Equal(t, cd.path, path, "Path should be correct")
assert.Equal(t, cd.args, args, "args should be correct")
assert.Equal(t, cd.concurrent, true, "concurrent should be set")
u := m.NewUploadAdapter("testboth")
assert.NotNil(t, u, "Upload adapter should be present")
cu, _ := u.(*customAdapter)
assert.NotNil(t, cu, "Upload adapter should be customAdapter")
assert.Equal(t, cu.path, path, "Path should be correct")
assert.Equal(t, cu.args, args, "args should be correct")
assert.Equal(t, cu.concurrent, true, "concurrent should be set")
}
示例5: TestUploadApiError
func TestUploadApiError(t *testing.T) {
SetupTestCredentialsFunc()
repo := test.NewRepo(t)
repo.Pushd()
defer func() {
repo.Popd()
repo.Cleanup()
RestoreCredentialsFunc()
}()
mux := http.NewServeMux()
server := httptest.NewServer(mux)
tmp := tempdir(t)
defer server.Close()
defer os.RemoveAll(tmp)
postCalled := false
mux.HandleFunc("/media/objects", func(w http.ResponseWriter, r *http.Request) {
postCalled = true
w.WriteHeader(404)
})
cfg := config.NewFrom(config.Values{
Git: map[string]string{
"lfs.url": server.URL + "/media",
},
})
oidPath, _ := lfs.LocalMediaPath("988881adc9fc3655077dc2d4d757d480b5ea0e11")
if err := ioutil.WriteFile(oidPath, []byte("test"), 0744); err != nil {
t.Fatal(err)
}
oid := filepath.Base(oidPath)
stat, _ := os.Stat(oidPath)
_, _, err := api.BatchOrLegacySingle(cfg, &api.ObjectResource{Oid: oid, Size: stat.Size()}, "upload", []string{"basic"})
if err == nil {
t.Fatal(err)
}
if errors.IsFatalError(err) {
t.Fatal("should not panic")
}
if isDockerConnectionError(err) {
return
}
expected := "LFS: " + fmt.Sprintf(httputil.GetDefaultError(404), server.URL+"/media/objects")
if err.Error() != expected {
t.Fatalf("Expected: %s\nGot: %s", expected, err.Error())
}
if !postCalled {
t.Errorf("POST not called")
}
}
示例6: TestCertVerifyDisabledGlobalConfig
func TestCertVerifyDisabledGlobalConfig(t *testing.T) {
def := config.New()
assert.False(t, isCertVerificationDisabledForHost(def, "anyhost.com"))
cfg := config.NewFrom(config.Values{
Git: map[string]string{"http.sslverify": "false"},
})
assert.True(t, isCertVerificationDisabledForHost(cfg, "anyhost.com"))
}
示例7: TestCertFromSSLCAInfoConfig
func TestCertFromSSLCAInfoConfig(t *testing.T) {
tempfile, err := ioutil.TempFile("", "testcert")
assert.Nil(t, err, "Error creating temp cert file")
defer os.Remove(tempfile.Name())
_, err = tempfile.WriteString(testCert)
assert.Nil(t, err, "Error writing temp cert file")
tempfile.Close()
// Test http.<url>.sslcainfo
for _, hostName := range sslCAInfoConfigHostNames {
hostKey := fmt.Sprintf("http.https://%v.sslcainfo", hostName)
cfg := config.NewFrom(config.Values{
Git: map[string]string{hostKey: tempfile.Name()},
})
for _, matchedHostTest := range sslCAInfoMatchedHostTests {
pool := getRootCAsForHost(cfg, matchedHostTest.hostName)
var shouldOrShouldnt string
if matchedHostTest.shouldMatch {
shouldOrShouldnt = "should"
} else {
shouldOrShouldnt = "should not"
}
assert.Equal(t, matchedHostTest.shouldMatch, pool != nil,
"Cert lookup for \"%v\" %v have succeeded with \"%v\"",
matchedHostTest.hostName, shouldOrShouldnt, hostKey)
}
}
// Test http.sslcainfo
cfg := config.NewFrom(config.Values{
Git: map[string]string{"http.sslcainfo": tempfile.Name()},
})
// Should match any host at all
for _, matchedHostTest := range sslCAInfoMatchedHostTests {
pool := getRootCAsForHost(cfg, matchedHostTest.hostName)
assert.NotNil(t, pool)
}
}
示例8: TestCertVerifyDisabledHostConfig
func TestCertVerifyDisabledHostConfig(t *testing.T) {
def := config.New()
assert.False(t, isCertVerificationDisabledForHost(def, "specifichost.com"))
assert.False(t, isCertVerificationDisabledForHost(def, "otherhost.com"))
cfg := config.NewFrom(config.Values{
Git: map[string]string{
"http.https://specifichost.com/.sslverify": "false",
},
})
assert.True(t, isCertVerificationDisabledForHost(cfg, "specifichost.com"))
assert.False(t, isCertVerificationDisabledForHost(cfg, "otherhost.com"))
}
示例9: TestSSHGetExeAndArgsSshCommandArgs
func TestSSHGetExeAndArgsSshCommandArgs(t *testing.T) {
cfg := config.NewFrom(config.Values{
Os: map[string]string{
"GIT_SSH_COMMAND": "sshcmd --args 1",
},
})
endpoint := cfg.Endpoint("download")
endpoint.SshUserAndHost = "[email protected]"
exe, args := sshGetExeAndArgs(cfg, endpoint)
assert.Equal(t, "sshcmd", exe)
assert.Equal(t, []string{"--args", "1", "[email protected]"}, args)
}
示例10: TestSSHGetExeAndArgsSshCustomPort
func TestSSHGetExeAndArgsSshCustomPort(t *testing.T) {
cfg := config.NewFrom(config.Values{
Os: map[string]string{
"GIT_SSH_COMMAND": "",
"GIT_SSH": "",
},
})
endpoint := cfg.Endpoint("download")
endpoint.SshUserAndHost = "[email protected]"
endpoint.SshPort = "8888"
exe, args := sshGetExeAndArgs(cfg, endpoint)
assert.Equal(t, "ssh", exe)
assert.Equal(t, []string{"-p", "8888", "[email protected]"}, args)
}
示例11: TestSSHGetExeAndArgsTortoisePlinkCommand
func TestSSHGetExeAndArgsTortoisePlinkCommand(t *testing.T) {
plink := filepath.Join("Users", "joebloggs", "bin", "tortoiseplink.exe")
cfg := config.NewFrom(config.Values{
Os: map[string]string{
"GIT_SSH_COMMAND": plink,
},
})
endpoint := cfg.Endpoint("download")
endpoint.SshUserAndHost = "[email protected]"
exe, args := sshGetExeAndArgs(cfg, endpoint)
assert.Equal(t, plink, exe)
assert.Equal(t, []string{"-batch", "[email protected]"}, args)
}
示例12: TestProxyFromEnvironment
func TestProxyFromEnvironment(t *testing.T) {
cfg := config.NewFrom(config.Values{
Os: map[string]string{
"HTTPS_PROXY": "https://proxy-from-env:8080",
},
})
req, err := http.NewRequest("GET", "https://some-host.com:123/foo/bar", nil)
if err != nil {
t.Fatal(err)
}
proxyURL, err := ProxyFromGitConfigOrEnvironment(cfg)(req)
assert.Equal(t, "proxy-from-env:8080", proxyURL.Host)
assert.Nil(t, err)
}
示例13: TestSSHGetExeAndArgsPlinkCustomPort
func TestSSHGetExeAndArgsPlinkCustomPort(t *testing.T) {
plink := filepath.Join("Users", "joebloggs", "bin", "plink")
cfg := config.NewFrom(config.Values{
Os: map[string]string{
"GIT_SSH_COMMAND": "",
"GIT_SSH": plink,
},
})
endpoint := cfg.Endpoint("download")
endpoint.SshUserAndHost = "[email protected]"
endpoint.SshPort = "8888"
exe, args := sshGetExeAndArgs(cfg, endpoint)
assert.Equal(t, plink, exe)
assert.Equal(t, []string{"-P", "8888", "[email protected]"}, args)
}
示例14: TestDownloadAPIError
func TestDownloadAPIError(t *testing.T) {
SetupTestCredentialsFunc()
defer func() {
RestoreCredentialsFunc()
}()
mux := http.NewServeMux()
server := httptest.NewServer(mux)
defer server.Close()
tmp := tempdir(t)
defer os.RemoveAll(tmp)
mux.HandleFunc("/media/objects/oid", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(404)
})
cfg := config.NewFrom(config.Values{
Git: map[string]string{
"lfs.batch": "false",
"lfs.url": server.URL + "/media",
},
})
_, _, err := api.BatchOrLegacySingle(cfg, &api.ObjectResource{Oid: "oid"}, "download", []string{"basic"})
if err == nil {
t.Fatal("no error?")
}
if errors.IsFatalError(err) {
t.Fatal("should not panic")
}
if isDockerConnectionError(err) {
return
}
expected := fmt.Sprintf(httputil.GetDefaultError(404), server.URL+"/media/objects/oid")
if err.Error() != expected {
t.Fatalf("Expected: %s\nGot: %s", expected, err.Error())
}
}
示例15: TestCertFromSSLCAPathConfig
func TestCertFromSSLCAPathConfig(t *testing.T) {
tempdir, err := ioutil.TempDir("", "testcertdir")
assert.Nil(t, err, "Error creating temp cert dir")
defer os.RemoveAll(tempdir)
err = ioutil.WriteFile(filepath.Join(tempdir, "cert1.pem"), []byte(testCert), 0644)
assert.Nil(t, err, "Error creating cert file")
cfg := config.NewFrom(config.Values{
Git: map[string]string{"http.sslcapath": tempdir},
})
// Should match any host at all
for _, matchedHostTest := range sslCAInfoMatchedHostTests {
pool := getRootCAsForHost(cfg, matchedHostTest.hostName)
assert.NotNil(t, pool)
}
}