コード例 #1
0
ファイル: uploader.go プロジェクト: jszwedko/artifacts
func newUploader(opts *Options, log *logrus.Logger) *uploader {
	var provider uploadProvider

	if opts.CacheControl == "" {
		opts.CacheControl = defaultPublicCacheControl
	}

	if opts.Provider == "" {
		opts.Provider = "s3"
	}

	switch opts.Provider {
	case "artifacts":
		provider = newArtifactsProvider(opts, log)
	case "s3":
		provider = newS3Provider(opts, log)
	case "null":
		provider = newNullProvider([]string{})
	default:
		log.WithFields(logrus.Fields{
			"provider": opts.Provider,
		}).Warn("unrecognized provider, using s3 instead")
		provider = newS3Provider(opts, log)
	}

	u := &uploader{
		Opts:     opts,
		Paths:    path.NewPathSet(),
		Provider: provider,

		log: log,
	}

	for _, s := range opts.Paths {
		parts := strings.SplitN(s, ":", 2)
		if len(parts) < 2 {
			parts = append(parts, "")
		}

		p := path.New(opts.WorkingDir, parts[0], parts[1])
		log.WithFields(logrus.Fields{"path": p}).Debug("adding path")
		u.Paths.Add(p)
	}

	return u
}
コード例 #2
0
ファイル: artifact_test.go プロジェクト: jszwedko/artifacts
func TestArtifactContentType(t *testing.T) {
	for filepath, expectedCtype := range testArtifactPaths {
		p := path.New("whatever", filepath, "somewhere")
		a := New(p, "bucket", "linux/foo", &Options{
			Perm:     s3.PublicRead,
			RepoSlug: "owner/foo",
		})
		if a == nil {
			t.Errorf("new artifact is nil")
		}

		actualCtype := a.ContentType()
		if expectedCtype != actualCtype {
			t.Errorf("%v != %v", expectedCtype, actualCtype)
		}
	}
}
コード例 #3
0
ファイル: artifact_test.go プロジェクト: jszwedko/artifacts
func TestArtifactReader(t *testing.T) {
	for filepath := range testArtifactPaths {
		p := path.New("whatever", filepath, "somewhere")
		a := New(p, "bucket", "linux/foo", &Options{
			Perm:     s3.PublicRead,
			RepoSlug: "owner/foo",
		})
		if a == nil {
			t.Errorf("new artifact is nil")
		}

		reader, err := a.Reader()
		if err != nil {
			t.Error(err)
		}

		_, err = ioutil.ReadAll(reader)
		if err != nil {
			t.Error(err)
		}
	}
}
コード例 #4
0
ファイル: artifact_test.go プロジェクト: jszwedko/artifacts
func TestNewArtifact(t *testing.T) {
	p := path.New("/", "foo", "bar")
	a := New(p, "bucket", "linux/foo", &Options{
		Perm:     s3.PublicRead,
		RepoSlug: "owner/foo",
	})
	if a == nil {
		t.Errorf("new artifact is nil")
	}

	if a.Path != p {
		t.Errorf("path not set correctly: %v", a.Path)
	}

	if a.Prefix != "bucket" {
		t.Errorf("prefix not set correctly: %v", a.Prefix)
	}

	if a.Destination != "linux/foo" {
		t.Errorf("destination not set correctly: %v", a.Destination)
	}

	if a.Perm != s3.PublicRead {
		t.Errorf("s3 perm not set correctly: %v", a.Perm)
	}

	if a.UploadResult == nil {
		t.Errorf("result not initialized")
	}

	if a.UploadResult.OK {
		t.Errorf("result initialized with OK as true")
	}

	if a.UploadResult.Err != nil {
		t.Errorf("result initialized with non-nil Err")
	}
}