Skip to content

Commit

Permalink
Fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
gmgigi96 committed Sep 30, 2021
1 parent 0b82e9b commit 014e172
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 34 deletions.
8 changes: 4 additions & 4 deletions internal/http/services/archiver/archiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ const (
ErrEmptyList = errtypes.BadRequest("list of files to archive empty")
)

// ArchiverConfig is the config for the Archiver
type ArchiverConfig struct {
// Config is the config for the Archiver
type Config struct {
MaxNumFiles int64 `mapstructure:"max_num_files"`
MaxSize int64 `mapstructure:"max_size"`
}
Expand All @@ -54,11 +54,11 @@ type Archiver struct {
dir string
walker walker.Walker
downloader downloader.Downloader
config ArchiverConfig
config Config
}

// NewArchiver creates a new archiver able to create an archive containing the files in the list
func NewArchiver(files []string, w walker.Walker, d downloader.Downloader, config ArchiverConfig) (*Archiver, error) {
func NewArchiver(files []string, w walker.Walker, d downloader.Downloader, config Config) (*Archiver, error) {
if len(files) == 0 {
return nil, ErrEmptyList
}
Expand Down
48 changes: 24 additions & 24 deletions internal/http/services/archiver/archiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func TestCreateTar(t *testing.T) {
tests := []struct {
name string
src test.Dir
config ArchiverConfig
config Config
files []string
expected test.Dir
err error
Expand All @@ -163,7 +163,7 @@ func TestCreateTar(t *testing.T) {
Content: "foo",
},
},
config: ArchiverConfig{
config: Config{
MaxSize: 3,
MaxNumFiles: 1,
},
Expand All @@ -182,7 +182,7 @@ func TestCreateTar(t *testing.T) {
Content: strings.Repeat("a", 1024*1024*1024),
},
},
config: ArchiverConfig{
config: Config{
MaxSize: 1024 * 1024 * 1024 * 2,
MaxNumFiles: 1000,
},
Expand All @@ -201,7 +201,7 @@ func TestCreateTar(t *testing.T) {
Content: "foo",
},
},
config: ArchiverConfig{
config: Config{
MaxSize: 3,
MaxNumFiles: 0,
},
Expand All @@ -216,7 +216,7 @@ func TestCreateTar(t *testing.T) {
Content: "foo",
},
},
config: ArchiverConfig{
config: Config{
MaxSize: 0,
MaxNumFiles: 1,
},
Expand All @@ -229,7 +229,7 @@ func TestCreateTar(t *testing.T) {
src: test.Dir{
"foo": test.Dir{},
},
config: ArchiverConfig{
config: Config{
MaxSize: 1000,
MaxNumFiles: 1,
},
Expand All @@ -244,7 +244,7 @@ func TestCreateTar(t *testing.T) {
src: test.Dir{
"foo": test.Dir{},
},
config: ArchiverConfig{
config: Config{
MaxSize: 1000,
MaxNumFiles: 0,
},
Expand All @@ -261,7 +261,7 @@ func TestCreateTar(t *testing.T) {
},
},
},
config: ArchiverConfig{
config: Config{
MaxSize: 1000,
MaxNumFiles: 1000,
},
Expand Down Expand Up @@ -300,7 +300,7 @@ func TestCreateTar(t *testing.T) {
},
},
},
config: ArchiverConfig{
config: Config{
MaxSize: 100000,
MaxNumFiles: 1000,
},
Expand Down Expand Up @@ -355,7 +355,7 @@ func TestCreateTar(t *testing.T) {
},
},
},
config: ArchiverConfig{
config: Config{
MaxSize: 100000,
MaxNumFiles: 1000,
},
Expand Down Expand Up @@ -397,7 +397,7 @@ func TestCreateTar(t *testing.T) {
},
},
},
config: ArchiverConfig{
config: Config{
MaxSize: 100000,
MaxNumFiles: 1000,
},
Expand Down Expand Up @@ -441,7 +441,7 @@ func TestCreateTar(t *testing.T) {
},
},
},
config: ArchiverConfig{
config: Config{
MaxSize: 100000,
MaxNumFiles: 1000,
},
Expand Down Expand Up @@ -599,7 +599,7 @@ func TestCreateZip(t *testing.T) {
tests := []struct {
name string
src test.Dir
config ArchiverConfig
config Config
files []string
expected test.Dir
err error
Expand All @@ -611,7 +611,7 @@ func TestCreateZip(t *testing.T) {
Content: "foo",
},
},
config: ArchiverConfig{
config: Config{
MaxSize: 3,
MaxNumFiles: 1,
},
Expand All @@ -630,7 +630,7 @@ func TestCreateZip(t *testing.T) {
Content: strings.Repeat("a", 1024*1024*1024),
},
},
config: ArchiverConfig{
config: Config{
MaxSize: 1024 * 1024 * 1024 * 2,
MaxNumFiles: 1000,
},
Expand All @@ -649,7 +649,7 @@ func TestCreateZip(t *testing.T) {
Content: "foo",
},
},
config: ArchiverConfig{
config: Config{
MaxSize: 3,
MaxNumFiles: 0,
},
Expand All @@ -664,7 +664,7 @@ func TestCreateZip(t *testing.T) {
Content: "foo",
},
},
config: ArchiverConfig{
config: Config{
MaxSize: 0,
MaxNumFiles: 1,
},
Expand All @@ -677,7 +677,7 @@ func TestCreateZip(t *testing.T) {
src: test.Dir{
"foo": test.Dir{},
},
config: ArchiverConfig{
config: Config{
MaxSize: 1000,
MaxNumFiles: 1,
},
Expand All @@ -692,7 +692,7 @@ func TestCreateZip(t *testing.T) {
src: test.Dir{
"foo": test.Dir{},
},
config: ArchiverConfig{
config: Config{
MaxSize: 1000,
MaxNumFiles: 0,
},
Expand All @@ -709,7 +709,7 @@ func TestCreateZip(t *testing.T) {
},
},
},
config: ArchiverConfig{
config: Config{
MaxSize: 1000,
MaxNumFiles: 1000,
},
Expand Down Expand Up @@ -748,7 +748,7 @@ func TestCreateZip(t *testing.T) {
},
},
},
config: ArchiverConfig{
config: Config{
MaxSize: 100000,
MaxNumFiles: 1000,
},
Expand Down Expand Up @@ -803,7 +803,7 @@ func TestCreateZip(t *testing.T) {
},
},
},
config: ArchiverConfig{
config: Config{
MaxSize: 100000,
MaxNumFiles: 1000,
},
Expand Down Expand Up @@ -845,7 +845,7 @@ func TestCreateZip(t *testing.T) {
},
},
},
config: ArchiverConfig{
config: Config{
MaxSize: 100000,
MaxNumFiles: 1000,
},
Expand Down Expand Up @@ -889,7 +889,7 @@ func TestCreateZip(t *testing.T) {
},
},
},
config: ArchiverConfig{
config: Config{
MaxSize: 100000,
MaxNumFiles: 1000,
},
Expand Down
4 changes: 2 additions & 2 deletions internal/http/services/archiver/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type Config struct {
Timeout int64 `mapstructure:"timeout"`
Insecure bool `mapstructure:"insecure"`
Name string `mapstructure:"name"`
archiver.ArchiverConfig
archiver.Config
}

func init() {
Expand Down Expand Up @@ -166,7 +166,7 @@ func (s *svc) Handler() http.Handler {
return
}

arch, err := archiver.NewArchiver(files, s.walker, s.downloader, s.config.ArchiverConfig)
arch, err := archiver.NewArchiver(files, s.walker, s.downloader, s.config.Config)
if err != nil {
s.log.Error().Msg(err.Error())
rw.WriteHeader(http.StatusInternalServerError)
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/utils/walker/mock/walker_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func convertFileInfoToResourceInfo(path string, f fs.FileInfo) *provider.Resourc
if f == nil {
return nil
}
// resource type convertion
// resource type conversion
t := provider.ResourceType_RESOURCE_TYPE_FILE
if f.IsDir() {
t = provider.ResourceType_RESOURCE_TYPE_CONTAINER
Expand Down
7 changes: 4 additions & 3 deletions pkg/test/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,16 @@ func DirEquals(dir1, dir2 string) bool {

path1, path2 := path.Join(dir1, r1.Name()), path.Join(dir2, r2.Name())

if r1.Type().IsDir() && r2.Type().IsDir() {
switch {
case r1.Type().IsDir() && r2.Type().IsDir(): // both are dirs
if !DirEquals(path1, path2) {
return false
}
} else if r1.Type().IsRegular() && r2.Type().IsRegular() {
case r1.Type().IsRegular() && r2.Type().IsRegular(): // both are files
if !fileEquals(path1, path2) {
return false
}
} else {
default: // different resource type
return false
}

Expand Down

0 comments on commit 014e172

Please sign in to comment.