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


Golang utils.MakeFileURL函数代码示例

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


在下文中一共展示了MakeFileURL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: SetUpTest

func (s *SimpleStreamsToolsSuite) SetUpTest(c *gc.C) {
	s.ToolsFixture.DefaultBaseURL = utils.MakeFileURL(s.publicToolsDir)
	s.BaseSuite.SetUpTest(c)
	s.ToolsFixture.SetUpTest(c)
	s.origCurrentVersion = version.Current
	s.reset(c, nil)
}
开发者ID:snailwalker,项目名称:juju,代码行数:7,代码来源:tools_test.go

示例2: TestURL

func (s *filestorageSuite) TestURL(c *gc.C) {
	expectedpath, _ := s.createFile(c, "test-file")
	_, file := filepath.Split(expectedpath)
	url, err := s.reader.URL(file)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(url, gc.Equals, utils.MakeFileURL(expectedpath))
}
开发者ID:howbazaar,项目名称:juju,代码行数:7,代码来源:filestorage_test.go

示例3: TestMajorVersionMatch

func (s *ValidateSuite) TestMajorVersionMatch(c *gc.C) {
	s.makeLocalMetadata(c, "released", "1.11.2", "raring")
	params := &ToolsMetadataLookupParams{
		Major: 1,
		Minor: -1,
		MetadataLookupParams: simplestreams.MetadataLookupParams{
			Region:        "region-2",
			Series:        "raring",
			Architectures: []string{"amd64"},
			Endpoint:      "some-auth-url",
			Stream:        "released",
			Sources: []simplestreams.DataSource{
				simplestreams.NewURLDataSource("test", s.toolsURL(), utils.VerifySSLHostnames)},
		},
	}
	versions, resolveInfo, err := ValidateToolsMetadata(params)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(versions, gc.DeepEquals, []string{"1.11.2-raring-amd64"})
	c.Check(resolveInfo, gc.DeepEquals, &simplestreams.ResolveInfo{
		Source:    "test",
		Signed:    false,
		IndexURL:  utils.MakeFileURL(path.Join(s.metadataDir, "tools/streams/v1/index2.json")),
		MirrorURL: "",
	})
}
开发者ID:Pankov404,项目名称:juju,代码行数:25,代码来源:validation_test.go

示例4: setupFakeTools

func (suite *baseProviderSuite) setupFakeTools(c *gc.C) {
	suite.PatchValue(&keys.JujuPublicKey, sstesting.SignedMetadataPublicKey)
	storageDir := c.MkDir()
	toolsDir := filepath.Join(storageDir, "tools")
	suite.PatchValue(&envtools.DefaultBaseURL, utils.MakeFileURL(toolsDir))
	suite.UploadFakeToolsToDirectory(c, storageDir, "released", "released")
}
开发者ID:bac,项目名称:juju,代码行数:7,代码来源:maas_test.go

示例5: TestSyncToolsCommandDeprecatedDestination

func (s *syncToolsSuite) TestSyncToolsCommandDeprecatedDestination(c *gc.C) {
	called := false
	dir := c.MkDir()
	syncTools = func(sctx *sync.SyncContext) error {
		c.Assert(sctx.AllVersions, jc.IsFalse)
		c.Assert(sctx.DryRun, jc.IsFalse)
		c.Assert(sctx.Stream, gc.Equals, "released")
		c.Assert(sctx.Source, gc.Equals, "")
		c.Assert(sctx.TargetToolsUploader, gc.FitsTypeOf, sync.StorageToolsUploader{})
		uploader := sctx.TargetToolsUploader.(sync.StorageToolsUploader)
		url, err := uploader.Storage.URL("")
		c.Assert(err, jc.ErrorIsNil)
		c.Assert(url, gc.Equals, utils.MakeFileURL(dir))
		called = true
		return nil
	}
	// Register writer.
	var tw loggo.TestWriter
	c.Assert(loggo.RegisterWriter("deprecated-tester", &tw, loggo.DEBUG), gc.IsNil)
	defer loggo.RemoveWriter("deprecated-tester")
	// Add deprecated message to be checked.
	messages := []jc.SimpleMessage{
		{loggo.WARNING, "Use of the --destination flag is deprecated in 1.18. Please use --local-dir instead."},
	}
	// Run sync-tools command with --destination flag.
	ctx, err := runSyncToolsCommand(c, "-m", "test-target", "--destination", dir, "--stream", "released")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(ctx, gc.NotNil)
	c.Assert(called, jc.IsTrue)
	// Check deprecated message was logged.
	c.Check(tw.Log(), jc.LogMatches, messages)
}
开发者ID:pmatulis,项目名称:juju,代码行数:32,代码来源:synctools_test.go

示例6: reset

func (s *SimpleStreamsToolsSuite) reset(c *gc.C, attrs map[string]interface{}) {
	final := map[string]interface{}{
		"agent-metadata-url": utils.MakeFileURL(s.customToolsDir),
		"agent-stream":       "proposed",
	}
	for k, v := range attrs {
		final[k] = v
	}
	s.resetEnv(c, final)
}
开发者ID:snailwalker,项目名称:juju,代码行数:10,代码来源:tools_test.go

示例7: TestPathRelativeToHome

func (s *filestorageSuite) TestPathRelativeToHome(c *gc.C) {
	homeDir := utils.Home()
	tempDir, err := ioutil.TempDir(homeDir, "")
	c.Assert(err, jc.ErrorIsNil)
	defer os.RemoveAll(tempDir)
	dirName := strings.Replace(tempDir, homeDir, "", -1)
	reader, err := filestorage.NewFileStorageReader(filepath.Join(utils.Home(), dirName))
	c.Assert(err, jc.ErrorIsNil)
	url, err := reader.URL("")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(url, gc.Equals, utils.MakeFileURL(filepath.Join(homeDir, dirName)))
}
开发者ID:howbazaar,项目名称:juju,代码行数:12,代码来源:filestorage_test.go

示例8: assertMatch

func (s *ValidateSuite) assertMatch(c *gc.C, stream string) {
	s.makeLocalMetadata(c, "1234", "region-2", "raring", "some-auth-url", stream)
	metadataPath := filepath.Join(s.metadataDir, "images")
	params := &simplestreams.MetadataLookupParams{
		Region:        "region-2",
		Series:        "raring",
		Architectures: []string{"amd64"},
		Endpoint:      "some-auth-url",
		Stream:        stream,
		Sources: []simplestreams.DataSource{
			simplestreams.NewURLDataSource("test", utils.MakeFileURL(metadataPath), utils.VerifySSLHostnames, simplestreams.DEFAULT_CLOUD_DATA, false)},
	}
	imageIds, resolveInfo, err := imagemetadata.ValidateImageMetadata(params)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(imageIds, gc.DeepEquals, []string{"1234"})
	c.Check(resolveInfo, gc.DeepEquals, &simplestreams.ResolveInfo{
		Source:    "test",
		Signed:    false,
		IndexURL:  utils.MakeFileURL(path.Join(metadataPath, "streams/v1/index.json")),
		MirrorURL: "",
	})
}
开发者ID:howbazaar,项目名称:juju,代码行数:22,代码来源:validation_test.go

示例9: TestRelativePath

func (s *filestorageSuite) TestRelativePath(c *gc.C) {
	dir := c.MkDir()
	err := os.MkdirAll(filepath.Join(dir, "a", "b", "c"), os.ModePerm)
	c.Assert(err, jc.ErrorIsNil)
	cwd, err := os.Getwd()
	c.Assert(err, jc.ErrorIsNil)
	err = os.Chdir(filepath.Join(dir, "a", "b", "c"))
	c.Assert(err, jc.ErrorIsNil)
	defer os.Chdir(cwd)
	reader, err := filestorage.NewFileStorageReader("../..")
	c.Assert(err, jc.ErrorIsNil)
	url, err := reader.URL("")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(url, gc.Equals, utils.MakeFileURL(dir)+"/a")
}
开发者ID:howbazaar,项目名称:juju,代码行数:15,代码来源:filestorage_test.go

示例10: UploadToDirectory

// UploadToDirectory uploads tools and metadata for the specified versions to dir.
func UploadToDirectory(c *gc.C, stream, dir string, versions ...version.Binary) map[version.Binary]string {
	uploaded := map[version.Binary]string{}
	if len(versions) == 0 {
		return uploaded
	}
	for _, vers := range versions {
		basePath := fmt.Sprintf("%s/tools-%s.tar.gz", stream, vers.String())
		uploaded[vers] = utils.MakeFileURL(fmt.Sprintf("%s/%s", dir, basePath))
	}
	objects := generateMetadata(c, stream, versions...)
	for _, object := range objects {
		path := filepath.Join(dir, object.path)
		dir := filepath.Dir(path)
		if err := os.MkdirAll(dir, 0755); err != nil && !os.IsExist(err) {
			c.Assert(err, jc.ErrorIsNil)
		}
		err := ioutil.WriteFile(path, object.data, 0644)
		c.Assert(err, jc.ErrorIsNil)
	}
	return uploaded
}
开发者ID:kakamessi99,项目名称:juju,代码行数:22,代码来源:testing.go

示例11: Fetch

// Fetch is defined in simplestreams.DataSource.
func (h *urlDataSource) Fetch(path string) (io.ReadCloser, string, error) {
	dataURL := urlJoin(h.baseURL, path)
	client := utils.GetHTTPClient(h.hostnameVerification)
	// dataURL can be http:// or file://
	// MakeFileURL will only modify the URL if it's a file URL
	dataURL = utils.MakeFileURL(dataURL)
	resp, err := client.Get(dataURL)
	if err != nil {
		logger.Tracef("Got error requesting %q: %v", dataURL, err)
		return nil, dataURL, errors.NotFoundf("invalid URL %q", dataURL)
	}
	if resp.StatusCode == http.StatusNotFound {
		return nil, dataURL, errors.NotFoundf("cannot find URL %q", dataURL)
	}
	if resp.StatusCode == http.StatusUnauthorized {
		return nil, dataURL, errors.Unauthorizedf("unauthorised access to URL %q", dataURL)
	}
	if resp.StatusCode != http.StatusOK {
		return nil, dataURL, fmt.Errorf("cannot access URL %q, %q", dataURL, resp.Status)
	}
	return resp.Body, dataURL, nil
}
开发者ID:Pankov404,项目名称:juju,代码行数:23,代码来源:datasource.go

示例12: TestSyncToolsCommandTargetDirectory

func (s *syncToolsSuite) TestSyncToolsCommandTargetDirectory(c *gc.C) {
	called := false
	dir := c.MkDir()
	syncTools = func(sctx *sync.SyncContext) error {
		c.Assert(sctx.AllVersions, jc.IsFalse)
		c.Assert(sctx.DryRun, jc.IsFalse)
		c.Assert(sctx.Stream, gc.Equals, "proposed")
		c.Assert(sctx.Source, gc.Equals, "")
		c.Assert(sctx.TargetToolsUploader, gc.FitsTypeOf, sync.StorageToolsUploader{})
		uploader := sctx.TargetToolsUploader.(sync.StorageToolsUploader)
		c.Assert(uploader.WriteMirrors, gc.Equals, envtools.DoNotWriteMirrors)
		url, err := uploader.Storage.URL("")
		c.Assert(err, jc.ErrorIsNil)
		c.Assert(url, gc.Equals, utils.MakeFileURL(dir))
		called = true
		return nil
	}
	ctx, err := runSyncToolsCommand(c, "-m", "test-target", "--local-dir", dir, "--stream", "proposed")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(ctx, gc.NotNil)
	c.Assert(called, jc.IsTrue)
}
开发者ID:pmatulis,项目名称:juju,代码行数:22,代码来源:synctools_test.go

示例13: TestMakeFileURL

func (s *windowsFileSuite) TestMakeFileURL(c *gc.C) {
	var makeFileURLTests = []struct {
		in       string
		expected string
	}{{
		in:       "file://C:\\foo\\baz",
		expected: "file://\\\\localhost\\C$/foo/baz",
	}, {
		in:       "C:\\foo\\baz",
		expected: "file://\\\\localhost\\C$/foo/baz",
	}, {
		in:       "http://foo/baz",
		expected: "http://foo/baz",
	}, {
		in:       "file://\\\\localhost\\C$/foo/baz",
		expected: "file://\\\\localhost\\C$/foo/baz",
	}}

	for i, t := range makeFileURLTests {
		c.Logf("Test %d", i)
		c.Assert(utils.MakeFileURL(t.in), gc.Equals, t.expected)
	}
}
开发者ID:tych0,项目名称:juju-utils,代码行数:23,代码来源:file_windows_test.go

示例14: GetURL

func GetURL(source, basePath string) (string, error) {
	// If source is a raw directory, we need to append the file:// prefix
	// so it can be used as a URL.
	defaultURL := source
	u, err := url.Parse(source)
	if err != nil {
		return "", fmt.Errorf("invalid default %s URL %s: %v", basePath, defaultURL, err)
	}

	switch u.Scheme {
	case "http", "https", "file", "test":
		return source, nil
	}

	if filepath.IsAbs(defaultURL) {
		defaultURL = utils.MakeFileURL(defaultURL)
		if !strings.HasSuffix(defaultURL, "/"+basePath) {
			defaultURL = fmt.Sprintf("%s/%s", defaultURL, basePath)
		}
	} else {
		return "", fmt.Errorf("%s is not an absolute path", source)
	}
	return defaultURL, nil
}
开发者ID:howbazaar,项目名称:juju,代码行数:24,代码来源:urls.go

示例15: toolsURL

func (s *ValidateSuite) toolsURL() string {
	return utils.MakeFileURL(path.Join(s.metadataDir, "tools"))
}
开发者ID:Pankov404,项目名称:juju,代码行数:3,代码来源:validation_test.go


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