19164: add a few flags to the compute image builder script.
[arvados.git] / tools / keep-block-check / keep-block-check_test.go
index f7d0fb9b9859320b558cc79bafa42d1e0a6db1ff..d973e06027c6ed2b707fce39a4f2ab00fcc51a11 100644 (file)
@@ -43,12 +43,7 @@ var TestHash2 = "aaaac516f788aec4f30932ffb6395c39"
 
 var blobSignatureTTL = time.Duration(2*7*24) * time.Hour
 
-func (s *ServerRequiredSuite) SetUpSuite(c *C) {
-       arvadostest.StartAPI()
-}
-
 func (s *ServerRequiredSuite) TearDownSuite(c *C) {
-       arvadostest.StopAPI()
        arvadostest.ResetEnv()
 }
 
@@ -194,7 +189,7 @@ func (s *ServerRequiredSuite) TestBlockCheck_NoSuchBlock(c *C) {
        allLocators = append(allLocators, TestHash2)
        err := performKeepBlockCheck(kc, blobSignatureTTL, "", allLocators, true)
        c.Check(err, NotNil)
-       c.Assert(err.Error(), Equals, "Block verification failed for 2 out of 7 blocks with matching prefix.")
+       c.Assert(err.Error(), Equals, "Block verification failed for 2 out of 7 blocks with matching prefix")
        checkErrorLog(c, []string{TestHash, TestHash2}, "Error verifying block", "Block not found")
 }
 
@@ -210,7 +205,7 @@ func (s *ServerRequiredSuite) TestBlockCheck_NoSuchBlock_WithMatchingPrefix(c *C
        err = performKeepBlockCheck(kc, blobSignatureTTL, "", locators, true)
        c.Check(err, NotNil)
        // Of the 7 blocks in allLocators, only two match the prefix and hence only those are checked
-       c.Assert(err.Error(), Equals, "Block verification failed for 2 out of 2 blocks with matching prefix.")
+       c.Assert(err.Error(), Equals, "Block verification failed for 2 out of 2 blocks with matching prefix")
        checkErrorLog(c, []string{TestHash, TestHash2}, "Error verifying block", "Block not found")
 }
 
@@ -231,7 +226,7 @@ func (s *ServerRequiredSuite) TestBlockCheck_BadSignature(c *C) {
        setupKeepBlockCheck(c, true, "")
        setupTestData(c)
        err := performKeepBlockCheck(kc, blobSignatureTTL, "badblobsigningkey", []string{TestHash, TestHash2}, false)
-       c.Assert(err.Error(), Equals, "Block verification failed for 2 out of 2 blocks with matching prefix.")
+       c.Assert(err.Error(), Equals, "Block verification failed for 2 out of 2 blocks with matching prefix")
        checkErrorLog(c, []string{TestHash, TestHash2}, "Error verifying block", "HTTP 403")
        // verbose logging not requested
        c.Assert(strings.Contains(logBuffer.String(), "Verifying block 1 of 2"), Equals, false)
@@ -267,7 +262,7 @@ var testKeepServicesJSON = `{
 func (s *ServerRequiredSuite) TestErrorDuringKeepBlockCheck_FakeKeepservers(c *C) {
        setupKeepBlockCheck(c, false, testKeepServicesJSON)
        err := performKeepBlockCheck(kc, blobSignatureTTL, "", []string{TestHash, TestHash2}, true)
-       c.Assert(err.Error(), Equals, "Block verification failed for 2 out of 2 blocks with matching prefix.")
+       c.Assert(err.Error(), Equals, "Block verification failed for 2 out of 2 blocks with matching prefix")
        checkErrorLog(c, []string{TestHash, TestHash2}, "Error verifying block", "")
 }
 
@@ -302,16 +297,18 @@ func (s *ServerRequiredSuite) TestLoadConfig(c *C) {
 
 func (s *DoMainTestSuite) Test_doMain_WithNoConfig(c *C) {
        args := []string{"-prefix", "a"}
-       err := doMain(args)
-       c.Check(err, NotNil)
-       c.Assert(strings.Contains(err.Error(), "config file not specified"), Equals, true)
+       var stderr bytes.Buffer
+       code := doMain(args, &stderr)
+       c.Check(code, Equals, 1)
+       c.Check(stderr.String(), Matches, ".*config file not specified\n")
 }
 
 func (s *DoMainTestSuite) Test_doMain_WithNoSuchConfigFile(c *C) {
        args := []string{"-config", "no-such-file"}
-       err := doMain(args)
-       c.Check(err, NotNil)
-       c.Assert(strings.Contains(err.Error(), "no such file or directory"), Equals, true)
+       var stderr bytes.Buffer
+       code := doMain(args, &stderr)
+       c.Check(code, Equals, 1)
+       c.Check(stderr.String(), Matches, ".*no such file or directory\n")
 }
 
 func (s *DoMainTestSuite) Test_doMain_WithNoBlockHashFile(c *C) {
@@ -323,8 +320,10 @@ func (s *DoMainTestSuite) Test_doMain_WithNoBlockHashFile(c *C) {
        defer arvadostest.StopKeep(2)
 
        args := []string{"-config", config}
-       err := doMain(args)
-       c.Assert(strings.Contains(err.Error(), "block-hash-file not specified"), Equals, true)
+       var stderr bytes.Buffer
+       code := doMain(args, &stderr)
+       c.Check(code, Equals, 1)
+       c.Check(stderr.String(), Matches, ".*block-hash-file not specified\n")
 }
 
 func (s *DoMainTestSuite) Test_doMain_WithNoSuchBlockHashFile(c *C) {
@@ -335,8 +334,10 @@ func (s *DoMainTestSuite) Test_doMain_WithNoSuchBlockHashFile(c *C) {
        defer arvadostest.StopKeep(2)
 
        args := []string{"-config", config, "-block-hash-file", "no-such-file"}
-       err := doMain(args)
-       c.Assert(strings.Contains(err.Error(), "no such file or directory"), Equals, true)
+       var stderr bytes.Buffer
+       code := doMain(args, &stderr)
+       c.Check(code, Equals, 1)
+       c.Check(stderr.String(), Matches, ".*no such file or directory\n")
 }
 
 func (s *DoMainTestSuite) Test_doMain(c *C) {
@@ -351,9 +352,10 @@ func (s *DoMainTestSuite) Test_doMain(c *C) {
        defer os.Remove(locatorFile)
 
        args := []string{"-config", config, "-block-hash-file", locatorFile, "-v"}
-       err := doMain(args)
-       c.Check(err, NotNil)
-       c.Assert(err.Error(), Equals, "Block verification failed for 2 out of 2 blocks with matching prefix.")
+       var stderr bytes.Buffer
+       code := doMain(args, &stderr)
+       c.Check(code, Equals, 1)
+       c.Assert(stderr.String(), Matches, "Block verification failed for 2 out of 2 blocks with matching prefix\n")
        checkErrorLog(c, []string{TestHash, TestHash2}, "Error verifying block", "Block not found")
        c.Assert(strings.Contains(logBuffer.String(), "Verifying block 1 of 2"), Equals, true)
 }