diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2024-01-18 21:08:43 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2024-01-18 21:08:43 +0300 |
commit | 055b4c04d5cef7029625c08619df4f3bcdccc6c2 (patch) | |
tree | 4a363915e4878c17f5a6ffef6010a4bf0e3b8b76 /workhorse | |
parent | 85f1126ea6f09296e4e5106d7d8319e93aeedf3c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'workhorse')
-rw-r--r-- | workhorse/cmd/gitlab-zip-metadata/main.go | 4 | ||||
-rw-r--r-- | workhorse/internal/config/config.go | 8 | ||||
-rw-r--r-- | workhorse/internal/config/config_test.go | 6 | ||||
-rw-r--r-- | workhorse/main.go | 3 | ||||
-rw-r--r-- | workhorse/main_test.go | 12 |
5 files changed, 23 insertions, 10 deletions
diff --git a/workhorse/cmd/gitlab-zip-metadata/main.go b/workhorse/cmd/gitlab-zip-metadata/main.go index 14fa2066997..a53c301333f 100644 --- a/workhorse/cmd/gitlab-zip-metadata/main.go +++ b/workhorse/cmd/gitlab-zip-metadata/main.go @@ -26,7 +26,7 @@ func main() { os.Exit(0) } - if len(os.Args) != 2 { + if len(flag.Args()) != 1 { fmt.Fprintf(os.Stderr, "Usage: %s FILE.ZIP\n", progName) os.Exit(1) } @@ -44,7 +44,7 @@ func main() { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - archive, err := zipartifacts.OpenArchiveWithReaderFunc(ctx, os.Args[1], readerFunc) + archive, err := zipartifacts.OpenArchiveWithReaderFunc(ctx, flag.Args()[0], readerFunc) if err != nil { fatalError(err) } diff --git a/workhorse/internal/config/config.go b/workhorse/internal/config/config.go index d84bab16541..562ea05bfd0 100644 --- a/workhorse/internal/config/config.go +++ b/workhorse/internal/config/config.go @@ -156,8 +156,14 @@ var DefaultImageResizerConfig = ImageResizerConfig{ MaxFilesize: 250 * 1000, // 250kB, } +func NewDefaultConfig() *Config { + return &Config{ + ImageResizerConfig: DefaultImageResizerConfig, + } +} + func LoadConfig(data string) (*Config, error) { - cfg := &Config{ImageResizerConfig: DefaultImageResizerConfig} + cfg := NewDefaultConfig() if _, err := toml.Decode(data, cfg); err != nil { return nil, err diff --git a/workhorse/internal/config/config_test.go b/workhorse/internal/config/config_test.go index 03cad69d335..d3f00021725 100644 --- a/workhorse/internal/config/config_test.go +++ b/workhorse/internal/config/config_test.go @@ -190,3 +190,9 @@ alt_document_root = "/path/to/documents" require.Equal(t, "/path/to/documents", cfg.AltDocumentRoot) } + +func TestDefaultConfig(t *testing.T) { + cfg := NewDefaultConfig() + + require.Equal(t, uint64(250000), cfg.ImageResizerConfig.MaxFilesize) +} diff --git a/workhorse/main.go b/workhorse/main.go index 5743355594f..0c470d36e3e 100644 --- a/workhorse/main.go +++ b/workhorse/main.go @@ -72,7 +72,8 @@ type alreadyPrintedError struct{ error } // of type alreadyPrintedError it has already been printed. func buildConfig(arg0 string, args []string) (*bootConfig, *config.Config, error) { boot := &bootConfig{} - cfg := &config.Config{Version: Version} + cfg := config.NewDefaultConfig() + cfg.Version = Version fset := flag.NewFlagSet(arg0, flag.ContinueOnError) fset.Usage = func() { fmt.Fprintf(fset.Output(), "Usage of %s:\n", arg0) diff --git a/workhorse/main_test.go b/workhorse/main_test.go index 39eaa3ee30b..fb36c6b2c3a 100644 --- a/workhorse/main_test.go +++ b/workhorse/main_test.go @@ -772,12 +772,12 @@ func testAuthServer(t *testing.T, url *regexp.Regexp, params url.Values, code in } func newUpstreamConfig(authBackend string) *config.Config { - return &config.Config{ - Version: "123", - DocumentRoot: testDocumentRoot, - Backend: helper.URLMustParse(authBackend), - ImageResizerConfig: config.DefaultImageResizerConfig, - } + defaultConfig := config.NewDefaultConfig() + defaultConfig.Version = "123" + defaultConfig.DocumentRoot = testDocumentRoot + defaultConfig.Backend = helper.URLMustParse(authBackend) + + return defaultConfig } func startWorkhorseServer(authBackend string) *httptest.Server { |