mirror of
https://github.com/gomods/athens
synced 2026-02-03 09:50:31 +00:00
* switch proxy to config file pull in single flight changes * changes for single-flight * intermediate stage. All tests passing. pkg still has env refs * remove all env references * delete config/env entirely * fix failing tests * create the config.toml file as part of dev setup * create config file only if it doesn't exist * update Dockerfiles to use config file * move composing elements to the top * verbose parameter naming * newline * add flag for config file path * update docs with config file flag * remove unnecessary nil check * use filepath.join * rename redis port to address * fix path.join * fix issues after merge * add vendor dir
57 lines
1.4 KiB
Go
57 lines
1.4 KiB
Go
package module
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"errors"
|
|
"io"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/gobuffalo/envy"
|
|
"github.com/stretchr/testify/suite"
|
|
)
|
|
|
|
type UploadTests struct {
|
|
suite.Suite
|
|
}
|
|
|
|
func TestUpload(t *testing.T) {
|
|
suite.Run(t, new(UploadTests))
|
|
}
|
|
|
|
func (u *UploadTests) SetupTest() {
|
|
envy.Set("ATHENS_TIMEOUT", "1")
|
|
}
|
|
|
|
func (u *UploadTests) TearDownTest() {
|
|
envy.Set("ATHENS_TIMEOUT", "300")
|
|
}
|
|
|
|
func (u *UploadTests) TestUploadTimeout() {
|
|
r := u.Require()
|
|
rd := bytes.NewReader([]byte("123"))
|
|
err := Upload(context.Background(), "mx", "1.1.1", rd, rd, rd, uplWithTimeout, time.Second)
|
|
r.Error(err, "deleter returned at least one error")
|
|
r.Contains(err.Error(), "uploading mx.1.1.1.info failed: context deadline exceeded")
|
|
r.Contains(err.Error(), "uploading mx.1.1.1.zip failed: context deadline exceeded")
|
|
r.Contains(err.Error(), "uploading mx.1.1.1.mod failed: context deadline exceeded")
|
|
}
|
|
|
|
func (u *UploadTests) TestUploadError() {
|
|
r := u.Require()
|
|
rd := bytes.NewReader([]byte("123"))
|
|
err := Upload(context.Background(), "mx", "1.1.1", rd, rd, rd, uplWithErr, time.Second)
|
|
r.Error(err, "deleter returned at least one error")
|
|
r.Contains(err.Error(), "some err")
|
|
}
|
|
|
|
func uplWithTimeout(ctx context.Context, path, contentType string, stream io.Reader) error {
|
|
time.Sleep(2 * time.Second)
|
|
return nil
|
|
}
|
|
|
|
func uplWithErr(ctx context.Context, path, contentType string, stream io.Reader) error {
|
|
return errors.New("some err")
|
|
}
|