configuration: use "fake" values for tests

These tests don't validate if options are valid for the storage-driver,
nor do they test if the storage-driver itself is valid. However, the tests
were using actual values (such as s3) and options (such as "region") which
may lead to the conclusion that it's also testing validity of those values.

This patch replaces the test-values with non-existing driver-names and
options to make it more clear these are fake values.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>
pull/3706/head
Tiger Kaovilai 2022-08-04 16:01:48 -04:00
parent 6c237953cb
commit 567158c365
1 changed files with 28 additions and 30 deletions

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")