Merge pull request #3706 from kaovilai/s3-no-hostport

configuration: use "fake" values for tests
This commit is contained in:
Milos Gajdos 2022-08-18 18:11:35 +01:00 committed by GitHub
commit cec2cad801
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -32,16 +32,15 @@ var configStruct = Configuration{
Fields: map[string]interface{}{"environment": "test"}, Fields: map[string]interface{}{"environment": "test"},
}, },
Storage: Storage{ Storage: Storage{
"s3": Parameters{ "somedriver": Parameters{
"region": "us-east-1", "string1": "string-value1",
"bucket": "my-bucket", "string2": "string-value2",
"rootdirectory": "/registry", "bool1": true,
"encrypt": true, "bool2": false,
"secure": false, "nil1": nil,
"accesskey": "SAMPLEACCESSKEY", "int1": 42,
"secretkey": "SUPERSECRET", "url1": "https://foo.example.com",
"host": nil, "path1": "/some-path",
"port": 42,
}, },
}, },
Auth: Auth{ Auth: Auth{
@ -136,16 +135,15 @@ log:
fields: fields:
environment: test environment: test
storage: storage:
s3: somedriver:
region: us-east-1 string1: string-value1
bucket: my-bucket string2: string-value2
rootdirectory: /registry bool1: true
encrypt: true bool2: false
secure: false nil1: ~
accesskey: SAMPLEACCESSKEY int1: 42
secretkey: SUPERSECRET url1: "https://foo.example.com"
host: ~ path1: "/some-path"
port: 42
auth: auth:
silly: silly:
realm: silly realm: silly
@ -275,10 +273,10 @@ func (suite *ConfigSuite) TestParseIncomplete(c *C) {
// that match the given storage type will only include environment-defined // that match the given storage type will only include environment-defined
// parameters and remove yaml-defined parameters // parameters and remove yaml-defined parameters
func (suite *ConfigSuite) TestParseWithSameEnvStorage(c *C) { func (suite *ConfigSuite) TestParseWithSameEnvStorage(c *C) {
suite.expectedConfig.Storage = Storage{"s3": Parameters{"region": "us-east-1"}} suite.expectedConfig.Storage = Storage{"somedriver": Parameters{"region": "us-east-1"}}
os.Setenv("REGISTRY_STORAGE", "s3") os.Setenv("REGISTRY_STORAGE", "somedriver")
os.Setenv("REGISTRY_STORAGE_S3_REGION", "us-east-1") os.Setenv("REGISTRY_STORAGE_SOMEDRIVER_REGION", "us-east-1")
config, err := Parse(bytes.NewReader([]byte(configYamlV0_1))) config, err := Parse(bytes.NewReader([]byte(configYamlV0_1)))
c.Assert(err, IsNil) c.Assert(err, IsNil)
@ -289,13 +287,13 @@ func (suite *ConfigSuite) TestParseWithSameEnvStorage(c *C) {
// and add to the given storage parameters will change and add parameters to the parsed // and add to the given storage parameters will change and add parameters to the parsed
// Configuration struct // Configuration struct
func (suite *ConfigSuite) TestParseWithDifferentEnvStorageParams(c *C) { func (suite *ConfigSuite) TestParseWithDifferentEnvStorageParams(c *C) {
suite.expectedConfig.Storage.setParameter("region", "us-west-1") suite.expectedConfig.Storage.setParameter("string1", "us-west-1")
suite.expectedConfig.Storage.setParameter("secure", true) suite.expectedConfig.Storage.setParameter("bool1", true)
suite.expectedConfig.Storage.setParameter("newparam", "some Value") suite.expectedConfig.Storage.setParameter("newparam", "some Value")
os.Setenv("REGISTRY_STORAGE_S3_REGION", "us-west-1") os.Setenv("REGISTRY_STORAGE_SOMEDRIVER_STRING1", "us-west-1")
os.Setenv("REGISTRY_STORAGE_S3_SECURE", "true") os.Setenv("REGISTRY_STORAGE_SOMEDRIVER_BOOL1", "true")
os.Setenv("REGISTRY_STORAGE_S3_NEWPARAM", "some Value") os.Setenv("REGISTRY_STORAGE_SOMEDRIVER_NEWPARAM", "some Value")
config, err := Parse(bytes.NewReader([]byte(configYamlV0_1))) config, err := Parse(bytes.NewReader([]byte(configYamlV0_1)))
c.Assert(err, IsNil) c.Assert(err, IsNil)
@ -433,7 +431,7 @@ func (suite *ConfigSuite) TestParseEnvVarImplicitMaps(c *C) {
// TestParseEnvWrongTypeMap validates that incorrectly attempting to unmarshal a // TestParseEnvWrongTypeMap validates that incorrectly attempting to unmarshal a
// string over existing map fails. // string over existing map fails.
func (suite *ConfigSuite) TestParseEnvWrongTypeMap(c *C) { func (suite *ConfigSuite) TestParseEnvWrongTypeMap(c *C) {
os.Setenv("REGISTRY_STORAGE_S3", "somestring") os.Setenv("REGISTRY_STORAGE_SOMEDRIVER", "somestring")
_, err := Parse(bytes.NewReader([]byte(configYamlV0_1))) _, err := Parse(bytes.NewReader([]byte(configYamlV0_1)))
c.Assert(err, NotNil) c.Assert(err, NotNil)
@ -468,7 +466,7 @@ func (suite *ConfigSuite) TestParseEnvMany(c *C) {
os.Setenv("REGISTRY_LOG_FIELDS", "abc: xyz") os.Setenv("REGISTRY_LOG_FIELDS", "abc: xyz")
os.Setenv("REGISTRY_LOG_HOOKS", "- type: asdf") os.Setenv("REGISTRY_LOG_HOOKS", "- type: asdf")
os.Setenv("REGISTRY_LOGLEVEL", "debug") os.Setenv("REGISTRY_LOGLEVEL", "debug")
os.Setenv("REGISTRY_STORAGE", "s3") os.Setenv("REGISTRY_STORAGE", "somedriver")
os.Setenv("REGISTRY_AUTH_PARAMS", "param1: value1") os.Setenv("REGISTRY_AUTH_PARAMS", "param1: value1")
os.Setenv("REGISTRY_AUTH_PARAMS_VALUE2", "value2") os.Setenv("REGISTRY_AUTH_PARAMS_VALUE2", "value2")
os.Setenv("REGISTRY_AUTH_PARAMS_VALUE2", "value2") os.Setenv("REGISTRY_AUTH_PARAMS_VALUE2", "value2")