Skip to content

Commit 6b88b02

Browse files
committed
[s3inbox] tests: improve tests
1 parent e2c1deb commit 6b88b02

File tree

1 file changed

+18
-28
lines changed

1 file changed

+18
-28
lines changed

Diff for: sda/cmd/s3inbox/proxy_test.go

+18-28
Original file line numberDiff line numberDiff line change
@@ -561,23 +561,6 @@ func (suite *ProxyTests) TestFormatUploadFilePath() {
561561
}
562562

563563
func (suite *ProxyTests) TestCheckFileExists() {
564-
filepath := "somefile"
565-
suite.fakeServer.resp = "fileExists!"
566-
567-
database, err := database.NewSDAdb(suite.DBConf)
568-
assert.NoError(suite.T(), err)
569-
defer database.Close()
570-
messenger, err := broker.NewMQ(suite.MQConf)
571-
assert.NoError(suite.T(), err)
572-
defer messenger.Connection.Close()
573-
proxy := NewProxy(suite.S3Fakeconf, helper.NewAlwaysAllow(), suite.messenger, suite.database, new(tls.Config))
574-
575-
res, err := proxy.checkFileExists(filepath)
576-
assert.True(suite.T(), res)
577-
assert.Nil(suite.T(), err)
578-
}
579-
580-
func (suite *ProxyTests) TestCheckFileExists_realBackend() {
581564
database, err := database.NewSDAdb(suite.DBConf)
582565
assert.NoError(suite.T(), err)
583566
defer database.Close()
@@ -592,6 +575,8 @@ func (suite *ProxyTests) TestCheckFileExists_realBackend() {
592575
}
593576

594577
func (suite *ProxyTests) TestCheckFileExists_nonExistingFile() {
578+
// Check that looking for a non-existing file gives (false, nil)
579+
// from checkFileExists
595580
database, err := database.NewSDAdb(suite.DBConf)
596581
assert.NoError(suite.T(), err)
597582
defer database.Close()
@@ -602,28 +587,33 @@ func (suite *ProxyTests) TestCheckFileExists_nonExistingFile() {
602587

603588
res, err := proxy.checkFileExists("nonexistingfilepath")
604589
assert.False(suite.T(), res)
605-
assert.NotNil(suite.T(), err)
606-
assert.Contains(suite.T(), err.Error(), "NotFound")
590+
assert.Nil(suite.T(), err)
607591
}
608592

609593
func (suite *ProxyTests) TestCheckFileExists_unresponsive() {
610-
suite.fakeServer.resp = "fileExists!"
594+
// Check that errors when connecting to S3 are forwarded
595+
// and that checkFileExists return (false, someError)
611596
database, err := database.NewSDAdb(suite.DBConf)
612597
assert.NoError(suite.T(), err)
613598
defer database.Close()
614599
messenger, err := broker.NewMQ(suite.MQConf)
615600
assert.NoError(suite.T(), err)
616601
defer messenger.Connection.Close()
617-
s3conf := storage.S3Conf{
618-
URL: "http://localhost:40211",
619-
AccessKey: "someAccess",
620-
SecretKey: "someSecret",
621-
Bucket: "buckbuck",
622-
Region: "us-east-1",
623-
}
624-
proxy := NewProxy(s3conf, helper.NewAlwaysAllow(), suite.messenger, suite.database, new(tls.Config))
602+
603+
// Unaccessible S3 (wrong port)
604+
proxy := NewProxy(suite.S3conf, helper.NewAlwaysAllow(), suite.messenger, suite.database, new(tls.Config))
605+
proxy.s3.Port = 1111
625606

626607
res, err := proxy.checkFileExists("nonexistingfilepath")
627608
assert.False(suite.T(), res)
628609
assert.NotNil(suite.T(), err)
610+
assert.Contains(suite.T(), err.Error(), "S3: HeadObject")
611+
612+
// Bad access key gives 403
613+
proxy.s3.Port = suite.S3conf.Port
614+
proxy.s3.AccessKey = "invaild"
615+
res, err = proxy.checkFileExists("nonexistingfilepath")
616+
assert.False(suite.T(), res)
617+
assert.NotNil(suite.T(), err)
618+
assert.Contains(suite.T(), err.Error(), "StatusCode: 403")
629619
}

0 commit comments

Comments
 (0)