• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang config.NewFrom函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/github/git-lfs/config.NewFrom函数的典型用法代码示例。如果您正苦于以下问题:Golang NewFrom函数的具体用法?Golang NewFrom怎么用?Golang NewFrom使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewFrom函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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"))
}
开发者ID:zhaohaiyi,项目名称:git-lfs,代码行数:11,代码来源:certs_test.go


示例2: TestCommandEnabledFromEnvironmentVariables

func TestCommandEnabledFromEnvironmentVariables(t *testing.T) {
	cfg := config.NewFrom(config.Values{
		Os: map[string]string{"GITLFSLOCKSENABLED": "1"},
	})

	assert.True(t, isCommandEnabled(cfg, "locks"))
}
开发者ID:zhaohaiyi,项目名称:git-lfs,代码行数:7,代码来源:commands_test.go


示例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")
}
开发者ID:zhaohaiyi,项目名称:git-lfs,代码行数:27,代码来源:custom_test.go


示例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")
}
开发者ID:zhaohaiyi,项目名称:git-lfs,代码行数:30,代码来源:custom_test.go


示例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")
	}
}
开发者ID:zhaohaiyi,项目名称:git-lfs,代码行数:58,代码来源:upload_test.go


示例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"))
}
开发者ID:zhaohaiyi,项目名称:git-lfs,代码行数:9,代码来源:certs_test.go


示例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)
	}

}
开发者ID:zhaohaiyi,项目名称:git-lfs,代码行数:44,代码来源:certs_test.go


示例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"))
}
开发者ID:zhaohaiyi,项目名称:git-lfs,代码行数:13,代码来源:certs_test.go


示例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)
}
开发者ID:zhaohaiyi,项目名称:git-lfs,代码行数:14,代码来源:ssh_test.go


示例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)
}
开发者ID:zhaohaiyi,项目名称:git-lfs,代码行数:16,代码来源:ssh_test.go


示例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)
}
开发者ID:zhaohaiyi,项目名称:git-lfs,代码行数:16,代码来源:ssh_test.go


示例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)
}
开发者ID:zhaohaiyi,项目名称:git-lfs,代码行数:17,代码来源:proxy_test.go


示例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)
}
开发者ID:zhaohaiyi,项目名称:git-lfs,代码行数:18,代码来源:ssh_test.go


示例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())
	}

}
开发者ID:zhaohaiyi,项目名称:git-lfs,代码行数:43,代码来源:download_test.go


示例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)
	}

}
开发者ID:zhaohaiyi,项目名称:git-lfs,代码行数:19,代码来源:certs_test.go


示例16: TestProxyNoProxy

func TestProxyNoProxy(t *testing.T) {
	cfg := config.NewFrom(config.Values{
		Git: map[string]string{
			"http.proxy": "https://proxy-from-git-config:8080",
		},
		Os: map[string]string{
			"NO_PROXY": "some-host",
		},
	})

	req, err := http.NewRequest("GET", "https://some-host:8080", nil)
	if err != nil {
		t.Fatal(err)
	}

	proxyUrl, err := ProxyFromGitConfigOrEnvironment(cfg)(req)

	assert.Nil(t, proxyUrl)
	assert.Nil(t, err)
}
开发者ID:zhaohaiyi,项目名称:git-lfs,代码行数:20,代码来源:proxy_test.go


示例17: testAdapterRegButBasicOnly

func testAdapterRegButBasicOnly(t *testing.T) {
	cfg := config.NewFrom(config.Values{
		Git: map[string]string{"lfs.basictransfersonly": "yes"},
	})
	m := ConfigureManifest(NewManifest(), cfg)

	assert := assert.New(t)

	m.RegisterNewTransferAdapterFunc("test", Upload, newTestAdapter)
	m.RegisterNewTransferAdapterFunc("test", Download, newTestAdapter)
	// Will still be created if we ask for them
	assert.NotNil(m.NewUploadAdapter("test"))
	assert.NotNil(m.NewDownloadAdapter("test"))

	// But list will exclude
	ld := m.GetDownloadAdapterNames()
	assert.Equal([]string{BasicAdapterName}, ld)
	lu := m.GetUploadAdapterNames()
	assert.Equal([]string{BasicAdapterName}, lu)
}
开发者ID:zhaohaiyi,项目名称:git-lfs,代码行数:20,代码来源:transfer_test.go


示例18: TestCertFromSSLCAInfoEnv

func TestCertFromSSLCAInfoEnv(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()

	cfg := config.NewFrom(config.Values{
		Os: map[string]string{
			"GIT_SSL_CAINFO": tempfile.Name(),
		},
	})

	// Should match any host at all
	for _, matchedHostTest := range sslCAInfoMatchedHostTests {
		pool := getRootCAsForHost(cfg, matchedHostTest.hostName)
		assert.NotNil(t, pool)
	}

}
开发者ID:zhaohaiyi,项目名称:git-lfs,代码行数:22,代码来源:certs_test.go


示例19: TestCustomTransferBasicConfig

func TestCustomTransferBasicConfig(t *testing.T) {
	path := "/path/to/binary"
	cfg := config.NewFrom(config.Values{
		Git: map[string]string{"lfs.customtransfer.testsimple.path": path},
	})

	m := ConfigureManifest(NewManifest(), cfg)

	u := m.NewUploadAdapter("testsimple")
	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 should be blank")
	assert.Equal(t, cu.concurrent, true, "concurrent should be defaulted")

	d := m.NewDownloadAdapter("testsimple")
	assert.NotNil(t, d, "Download adapter should be present")
	cd, _ := u.(*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 should be blank")
	assert.Equal(t, cd.concurrent, true, "concurrent should be defaulted")
}
开发者ID:zhaohaiyi,项目名称:git-lfs,代码行数:24,代码来源:custom_test.go


示例20: checkGetCredentials

func checkGetCredentials(t *testing.T, getCredsFunc func(*config.Configuration, *http.Request) (Creds, error), checks []*getCredentialCheck) {
	for _, check := range checks {
		t.Logf("Checking %q", check.Desc)
		cfg := config.NewFrom(config.Values{
			Git: check.Config,
		})
		cfg.CurrentRemote = check.CurrentRemote

		req, err := http.NewRequest(check.Method, check.Href, nil)
		if err != nil {
			t.Errorf("[%s] %s", check.Desc, err)
			continue
		}

		for key, value := range check.Header {
			req.Header.Set(key, value)
		}

		creds, err := getCredsFunc(cfg, req)
		if err != nil {
			t.Errorf("[%s] %s", check.Desc, err)
			continue
		}

		if check.ExpectCreds() {
			if creds == nil {
				t.Errorf("[%s], no credentials returned", check.Desc)
				continue
			}

			if value := creds["protocol"]; len(check.Protocol) > 0 && value != check.Protocol {
				t.Errorf("[%s] bad protocol: %q, expected: %q", check.Desc, value, check.Protocol)
			}

			if value := creds["host"]; len(check.Host) > 0 && value != check.Host {
				t.Errorf("[%s] bad host: %q, expected: %q", check.Desc, value, check.Host)
			}

			if value := creds["username"]; len(check.Username) > 0 && value != check.Username {
				t.Errorf("[%s] bad username: %q, expected: %q", check.Desc, value, check.Username)
			}

			if value := creds["password"]; len(check.Password) > 0 && value != check.Password {
				t.Errorf("[%s] bad password: %q, expected: %q", check.Desc, value, check.Password)
			}

			if value := creds["path"]; len(check.Path) > 0 && value != check.Path {
				t.Errorf("[%s] bad path: %q, expected: %q", check.Desc, value, check.Path)
			}
		} else {
			if creds != nil {
				t.Errorf("[%s], unexpected credentials: %v // %v", check.Desc, creds, check)
				continue
			}
		}

		reqAuth := req.Header.Get("Authorization")
		if check.SkipAuth {
		} else if len(check.Authorization) > 0 {
			if reqAuth != check.Authorization {
				t.Errorf("[%s] Unexpected Authorization header: %s", check.Desc, reqAuth)
			}
		} else {
			rawtoken := fmt.Sprintf("%s:%s", check.Username, check.Password)
			expected := "Basic " + strings.TrimSpace(base64.StdEncoding.EncodeToString([]byte(rawtoken)))
			if reqAuth != expected {
				t.Errorf("[%s] Bad Authorization. Expected '%s', got '%s'", check.Desc, expected, reqAuth)
			}
		}
	}
}
开发者ID:zhaohaiyi,项目名称:git-lfs,代码行数:71,代码来源:credentials_test.go



注:本文中的github.com/github/git-lfs/config.NewFrom函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang config.Configuration类代码示例发布时间:2022-05-23
下一篇:
Golang types.EmptyHash函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap