|
|
|
@ -200,11 +200,13 @@ func TestCheckDupJSONKeys(t *testing.T) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Tests config validator..
|
|
|
|
|
func TestValidateConfig(t *testing.T) { |
|
|
|
|
rootPath, err := newTestConfig(globalMinioDefaultRegion) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("Init Test config failed") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// remove the root directory after the test ends.
|
|
|
|
|
defer removeAll(rootPath) |
|
|
|
|
|
|
|
|
@ -234,52 +236,55 @@ func TestValidateConfig(t *testing.T) { |
|
|
|
|
// Test 6 - missing secret key
|
|
|
|
|
{`{"version": "` + v + `", "browser": "on", "credential" : {"accessKey":"minio", "secretKey":""}}`, false}, |
|
|
|
|
|
|
|
|
|
// Test 7 - missing region
|
|
|
|
|
{`{"version": "` + v + `", "browser": "on", "credential" : {"accessKey":"minio", "secretKey":"minio123"}}`, false}, |
|
|
|
|
// Test 7 - missing region should pass, defaults to 'us-east-1'.
|
|
|
|
|
{`{"version": "` + v + `", "browser": "on", "credential" : {"accessKey":"minio", "secretKey":"minio123"}}`, true}, |
|
|
|
|
|
|
|
|
|
// Test 8 - missing browser should pass, defaults to 'on'.
|
|
|
|
|
{`{"version": "` + v + `", "region": "us-east-1", "credential" : {"accessKey":"minio", "secretKey":"minio123"}}`, true}, |
|
|
|
|
|
|
|
|
|
// Test 8 - success
|
|
|
|
|
// Test 9 - success
|
|
|
|
|
{`{"version": "` + v + `", "browser": "on", "region":"us-east-1", "credential" : {"accessKey":"minio", "secretKey":"minio123"}}`, true}, |
|
|
|
|
|
|
|
|
|
// Test 9 - duplicated json keys
|
|
|
|
|
// Test 10 - duplicated json keys
|
|
|
|
|
{`{"version": "` + v + `", "browser": "on", "browser": "on", "region":"us-east-1", "credential" : {"accessKey":"minio", "secretKey":"minio123"}}`, false}, |
|
|
|
|
|
|
|
|
|
// Test 10 - Wrong Console logger level
|
|
|
|
|
// Test 11 - Wrong Console logger level
|
|
|
|
|
{`{"version": "` + v + `", "credential": { "accessKey": "minio", "secretKey": "minio123" }, "region": "us-east-1", "browser": "on", "logger": { "console": { "enable": true, "level": "foo" } }}`, false}, |
|
|
|
|
|
|
|
|
|
// Test 11 - Wrong File logger level
|
|
|
|
|
// Test 12 - Wrong File logger level
|
|
|
|
|
{`{"version": "` + v + `", "credential": { "accessKey": "minio", "secretKey": "minio123" }, "region": "us-east-1", "browser": "on", "logger": { "file": { "enable": true, "level": "foo" } }}`, false}, |
|
|
|
|
|
|
|
|
|
// Test 12 - Test AMQP
|
|
|
|
|
// Test 13 - Test AMQP
|
|
|
|
|
{`{"version": "` + v + `", "credential": { "accessKey": "minio", "secretKey": "minio123" }, "region": "us-east-1", "browser": "on", "notify": { "amqp": { "1": { "enable": true, "url": "", "exchange": "", "routingKey": "", "exchangeType": "", "mandatory": false, "immediate": false, "durable": false, "internal": false, "noWait": false, "autoDeleted": false }}}}`, false}, |
|
|
|
|
|
|
|
|
|
// Test 13 - Test NATS
|
|
|
|
|
// Test 14 - Test NATS
|
|
|
|
|
{`{"version": "` + v + `", "credential": { "accessKey": "minio", "secretKey": "minio123" }, "region": "us-east-1", "browser": "on", "notify": { "nats": { "1": { "enable": true, "address": "", "subject": "", "username": "", "password": "", "token": "", "secure": false, "pingInterval": 0, "streaming": { "enable": false, "clusterID": "", "clientID": "", "async": false, "maxPubAcksInflight": 0 } } }}}`, false}, |
|
|
|
|
|
|
|
|
|
// Test 14 - Test ElasticSearch
|
|
|
|
|
// Test 15 - Test ElasticSearch
|
|
|
|
|
{`{"version": "` + v + `", "credential": { "accessKey": "minio", "secretKey": "minio123" }, "region": "us-east-1", "browser": "on", "notify": { "elasticsearch": { "1": { "enable": true, "url": "", "index": "" } }}}`, false}, |
|
|
|
|
|
|
|
|
|
// Test 15 - Test Redis
|
|
|
|
|
// Test 16 - Test Redis
|
|
|
|
|
{`{"version": "` + v + `", "credential": { "accessKey": "minio", "secretKey": "minio123" }, "region": "us-east-1", "browser": "on", "notify": { "redis": { "1": { "enable": true, "address": "", "password": "", "key": "" } }}}`, false}, |
|
|
|
|
|
|
|
|
|
// Test 16 - Test PostgreSQL
|
|
|
|
|
// Test 17 - Test PostgreSQL
|
|
|
|
|
{`{"version": "` + v + `", "credential": { "accessKey": "minio", "secretKey": "minio123" }, "region": "us-east-1", "browser": "on", "notify": { "postgresql": { "1": { "enable": true, "connectionString": "", "table": "", "host": "", "port": "", "user": "", "password": "", "database": "" }}}}`, false}, |
|
|
|
|
|
|
|
|
|
// Test 17 - Test Kafka
|
|
|
|
|
// Test 18 - Test Kafka
|
|
|
|
|
{`{"version": "` + v + `", "credential": { "accessKey": "minio", "secretKey": "minio123" }, "region": "us-east-1", "browser": "on", "notify": { "kafka": { "1": { "enable": true, "brokers": null, "topic": "" } }}}`, false}, |
|
|
|
|
|
|
|
|
|
// Test 18 - Test Webhook
|
|
|
|
|
// Test 19 - Test Webhook
|
|
|
|
|
{`{"version": "` + v + `", "credential": { "accessKey": "minio", "secretKey": "minio123" }, "region": "us-east-1", "browser": "on", "notify": { "webhook": { "1": { "enable": true, "endpoint": "" } }}}`, false}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for i, testCase := range testCases { |
|
|
|
|
if err := ioutil.WriteFile(configPath, []byte(testCase.configData), 0700); err != nil { |
|
|
|
|
t.Error(err) |
|
|
|
|
if werr := ioutil.WriteFile(configPath, []byte(testCase.configData), 0700); werr != nil { |
|
|
|
|
t.Fatal(werr) |
|
|
|
|
} |
|
|
|
|
err := validateConfig() |
|
|
|
|
if testCase.shouldPass && err != nil { |
|
|
|
|
t.Errorf("Test %d, should pass but it failed with err = %v", i+1, err) |
|
|
|
|
verr := validateConfig() |
|
|
|
|
if testCase.shouldPass && verr != nil { |
|
|
|
|
t.Errorf("Test %d, should pass but it failed with err = %v", i+1, verr) |
|
|
|
|
} |
|
|
|
|
if !testCase.shouldPass && err == nil { |
|
|
|
|
if !testCase.shouldPass && verr == nil { |
|
|
|
|
t.Errorf("Test %d, should fail but it succeed.", i+1) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|