当前位置: 首页>>代码示例>>Golang>>正文


Golang config.NewFrom函数代码示例

本文整理汇总了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"))
}
开发者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


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