20846: Update ruby install recipe, add libyaml dep for psych gem.
[arvados.git] / lib / costanalyzer / costanalyzer_test.go
index 2975e3b3de06332d16b525efed7ebc9097fcdf82..1054870add65276385a6b11c3f99c33677dc0694 100644 (file)
@@ -35,6 +35,10 @@ func (s *Suite) TearDownSuite(c *check.C) {
 func (s *Suite) SetUpSuite(c *check.C) {
        arvadostest.StartKeep(2, true)
 
+       // Use a small page size to exercise paging without adding
+       // lots of fixtures
+       pagesize = 2
+
        // Get the various arvados, arvadosclient, and keep client objects
        ac := arvados.NewClientFromEnv()
        arv, err := arvadosclient.MakeArvadosClient()
@@ -152,7 +156,7 @@ func createNodeJSON(c *check.C, arv *arvadosclient.ArvadosClient, ac *arvados.Cl
 func (*Suite) TestUsage(c *check.C) {
        var stdout, stderr bytes.Buffer
        exitcode := Command.RunCommand("costanalyzer.test", []string{"-help", "-log-level=debug"}, &bytes.Buffer{}, &stdout, &stderr)
-       c.Check(exitcode, check.Equals, 1)
+       c.Check(exitcode, check.Equals, 0)
        c.Check(stdout.String(), check.Equals, "")
        c.Check(stderr.String(), check.Matches, `(?ms).*Usage:.*`)
 }
@@ -205,19 +209,23 @@ func (*Suite) TestContainerRequestUUID(c *check.C) {
 
 func (*Suite) TestCollectionUUID(c *check.C) {
        var stdout, stderr bytes.Buffer
-
        resultsDir := c.MkDir()
-       // Run costanalyzer with 1 collection uuid, without 'container_request' property
-       exitcode := Command.RunCommand("costanalyzer.test", []string{"-output", resultsDir, arvadostest.FooCollection}, &bytes.Buffer{}, &stdout, &stderr)
-       c.Check(exitcode, check.Equals, 2)
-       c.Assert(stderr.String(), check.Matches, "(?ms).*does not have a 'container_request' property.*")
 
-       // Update the collection, attach a 'container_request' property
+       // Create a collection with no container_request property
        ac := arvados.NewClientFromEnv()
        var coll arvados.Collection
+       err := ac.RequestAndDecode(&coll, "POST", "arvados/v1/collections", nil, nil)
+       c.Assert(err, check.IsNil)
 
-       // Update collection record
-       err := ac.RequestAndDecode(&coll, "PUT", "arvados/v1/collections/"+arvadostest.FooCollection, nil, map[string]interface{}{
+       exitcode := Command.RunCommand("costanalyzer.test", []string{"-output", resultsDir, coll.UUID}, &bytes.Buffer{}, &stdout, &stderr)
+       c.Check(exitcode, check.Equals, 2)
+       c.Assert(stderr.String(), check.Matches, "(?ms).*does not have a 'container_request' property.*")
+
+       stdout.Truncate(0)
+       stderr.Truncate(0)
+
+       // Add a container_request property
+       err = ac.RequestAndDecode(&coll, "PATCH", "arvados/v1/collections/"+coll.UUID, nil, map[string]interface{}{
                "collection": map[string]interface{}{
                        "properties": map[string]interface{}{
                                "container_request": arvadostest.CompletedContainerRequestUUID,
@@ -226,12 +234,9 @@ func (*Suite) TestCollectionUUID(c *check.C) {
        })
        c.Assert(err, check.IsNil)
 
-       stdout.Truncate(0)
-       stderr.Truncate(0)
-
-       // Run costanalyzer with 1 collection uuid
+       // Re-run costanalyzer on the updated collection
        resultsDir = c.MkDir()
-       exitcode = Command.RunCommand("costanalyzer.test", []string{"-output", resultsDir, arvadostest.FooCollection}, &bytes.Buffer{}, &stdout, &stderr)
+       exitcode = Command.RunCommand("costanalyzer.test", []string{"-output", resultsDir, coll.UUID}, &bytes.Buffer{}, &stdout, &stderr)
        c.Check(exitcode, check.Equals, 0)
        c.Assert(stderr.String(), check.Matches, "(?ms).*supplied uuids in .*")