diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 6bc15fbb..7f9e6b5c 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -45,6 +45,7 @@ jobs: # When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version. # When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit. version: v1.64.5 + args: --timeout=10m # Optional: working directory, useful for monorepos # working-directory: somedir diff --git a/jfrog/public.go b/jfrog/public.go index 71866058..f478ee30 100644 --- a/jfrog/public.go +++ b/jfrog/public.go @@ -21,7 +21,6 @@ type PublishedStorage struct { repository string prefix string plusWorkaround bool - pathCache map[string]string } // Check interface @@ -138,16 +137,14 @@ func (storage *PublishedStorage) Filelist(prefix string) ([]string, error) { defer reader.Close() var paths []string - var md5s []string - + for element := new(utils.ResultItem); reader.NextRecord(element) == nil; element = new(utils.ResultItem) { path := element.Path + "/" + element.Name - relPath := strings.TrimPrefix(path, storage.repository + "/" + storage.prefix + "/") + relPath := strings.TrimPrefix(path, storage.repository+"/"+storage.prefix+"/") if storage.plusWorkaround { - relPath = strings.Replace(relPath, "%2B", "+", -1) + relPath = strings.Replace(relPath, "%2B", "+", -1) } paths = append(paths, relPath) - md5s = append(md5s, element.Actual_Md5) } return paths, nil diff --git a/utils/config_test.go b/utils/config_test.go index e571528c..29143ef9 100644 --- a/utils/config_test.go +++ b/utils/config_test.go @@ -197,6 +197,127 @@ func (s *ConfigSuite) TestSaveConfig(c *C) { }`) } +func (s *ConfigSuite) TestLoadYAMLConfig(c *C) { + configname := filepath.Join(c.MkDir(), "aptly.yaml1") + f, _ := os.Create(configname) + _, _ = f.WriteString(configFileYAML) + _ = f.Close() + + // start with empty config + s.config = ConfigStructure{} + + err := LoadConfig(configname, &s.config) + c.Assert(err, IsNil) + c.Check(s.config.GetRootDir(), Equals, "/opt/aptly/") + c.Check(s.config.DownloadConcurrency, Equals, 40) + c.Check(s.config.DatabaseOpenAttempts, Equals, 10) +} + +func (s *ConfigSuite) TestLoadYAMLErrorConfig(c *C) { + configname := filepath.Join(c.MkDir(), "aptly.yaml2") + f, _ := os.Create(configname) + _, _ = f.WriteString(configFileYAMLError) + _ = f.Close() + + // start with empty config + s.config = ConfigStructure{} + + err := LoadConfig(configname, &s.config) + c.Assert(err.Error(), Equals, "invalid yaml (unknown pool storage type: invalid) or json (invalid character 'p' looking for beginning of value)") +} + +func (s *ConfigSuite) TestSaveYAMLConfig(c *C) { + configname := filepath.Join(c.MkDir(), "aptly.yaml3") + f, _ := os.Create(configname) + _, _ = f.WriteString(configFileYAML) + _ = f.Close() + + // start with empty config + s.config = ConfigStructure{} + + err := LoadConfig(configname, &s.config) + c.Assert(err, IsNil) + + err = SaveConfigYAML(configname, &s.config) + c.Assert(err, IsNil) + + f, _ = os.Open(configname) + defer func() { + _ = f.Close() + }() + + st, _ := f.Stat() + buf := make([]byte, st.Size()) + _, _ = f.Read(buf) + + c.Check(string(buf), Equals, configFileYAML) +} + +func (s *ConfigSuite) TestSaveYAML2Config(c *C) { + // start with empty config + s.config = ConfigStructure{} + + s.config.PackagePoolStorage.Local = &LocalPoolStorage{"/tmp/aptly-pool"} + s.config.PackagePoolStorage.Azure = nil + + configname := filepath.Join(c.MkDir(), "aptly.yaml4") + err := SaveConfigYAML(configname, &s.config) + c.Assert(err, IsNil) + + f, _ := os.Open(configname) + defer func() { + _ = f.Close() + }() + + st, _ := f.Stat() + buf := make([]byte, st.Size()) + _, _ = f.Read(buf) + + c.Check(string(buf), Equals, ""+ + "root_dir: \"\"\n"+ + "log_level: \"\"\n"+ + "log_format: \"\"\n"+ + "database_open_attempts: 0\n"+ + "architectures: []\n"+ + "skip_legacy_pool: false\n"+ + "dep_follow_suggests: false\n"+ + "dep_follow_recommends: false\n"+ + "dep_follow_all_variants: false\n"+ + "dep_follow_source: false\n"+ + "dep_verboseresolve: false\n"+ + "ppa_distributor_id: \"\"\n"+ + "ppa_codename: \"\"\n"+ + "ppa_baseurl: \"\"\n"+ + "serve_in_api_mode: false\n"+ + "enable_metrics_endpoint: false\n"+ + "enable_swagger_endpoint: false\n"+ + "async_api: false\n"+ + "database_backend:\n"+ + " type: \"\"\n"+ + " db_path: \"\"\n"+ + " url: \"\"\n"+ + "downloader: \"\"\n"+ + "download_concurrency: 0\n"+ + "download_limit: 0\n"+ + "download_retries: 0\n"+ + "download_sourcepackages: false\n"+ + "gpg_provider: \"\"\n"+ + "gpg_disable_sign: false\n"+ + "gpg_disable_verify: false\n"+ + "gpg_keys: []\n"+ + "skip_contents_publishing: false\n"+ + "skip_bz2_publishing: false\n"+ + "filesystem_publish_endpoints: {}\n"+ + "jfrog_publish_endpoints: {}\n"+ + "s3_publish_endpoints: {}\n"+ + "gcs_publish_endpoints: {}\n"+ + "swift_publish_endpoints: {}\n"+ + "azure_publish_endpoints: {}\n"+ + "packagepool_storage:\n"+ + " type: local\n"+ + " path: /tmp/aptly-pool\n") +} + func (s *ConfigSuite) TestLoadEmptyConfig(c *C) { configname := filepath.Join(c.MkDir(), "aptly.yaml5") f, _ := os.Create(configname) @@ -250,6 +371,7 @@ filesystem_publish_endpoints: root_dir: /opt/srv/aptly_public link_method: hardlink verify_method: md5 +jfrog_publish_endpoints: {} s3_publish_endpoints: test: region: us-east-1