17187: costanalyzer: print the total from the aggregate cost accounting
authorWard Vandewege <ward@curii.com>
Sun, 6 Dec 2020 15:54:11 +0000 (10:54 -0500)
committerWard Vandewege <ward@curii.com>
Sun, 6 Dec 2020 15:54:11 +0000 (10:54 -0500)
       across all uuids to stdout.

Arvados-DCO-1.1-Signed-off-by: Ward Vandewege <ward@curii.com>

lib/costanalyzer/costanalyzer.go
lib/costanalyzer/costanalyzer_test.go

index 01a9d9fdb6b140280e89f63a30def7d77d2b365b..bca23b1535c6440e49bbf8029b28e7da3beabc76 100644 (file)
@@ -94,6 +94,9 @@ Usage:
        In order to get the data for the uuids supplied, the ARVADOS_API_HOST and
        ARVADOS_API_TOKEN environment variables must be set.
 
+       This program prints the total dollar amount from the aggregate cost
+       accounting across all provided uuids on stdout.
+
 Options:
 `, prog)
                flags.PrintDefaults()
@@ -548,5 +551,8 @@ func costanalyzer(prog string, args []string, loader *config.Loader, logger *log
                return
        }
        logger.Infof("Aggregate cost accounting for all supplied uuids in %s\n", aFile)
+       // Output the total dollar amount on stdout
+       fmt.Fprintf(stdout, "%s\n", strconv.FormatFloat(total, 'f', 8, 64))
+
        return
 }
index 36421dc7f2daf98a1a11bd51974299b6879d14bf..48e7733e1878ba9ff0524b62edd7b8421f33137f 100644 (file)
@@ -290,6 +290,12 @@ func (*Suite) TestMultipleContainerRequestUUIDWithReuse(c *check.C) {
        c.Check(exitcode, check.Equals, 0)
        c.Assert(stderr.String(), check.Matches, "(?ms).*supplied uuids in .*")
 
+       // Check that the total amount was printed to stdout
+       c.Check(stdout.String(), check.Matches, "0.01492030\n")
+
+       stdout.Truncate(0)
+       stderr.Truncate(0)
+
        // Run costanalyzer with 2 container request uuids
        exitcode = Command.RunCommand("costanalyzer.test", []string{"-uuid", arvadostest.CompletedDiagnosticsContainerRequest1UUID, "-uuid", arvadostest.CompletedDiagnosticsContainerRequest2UUID, "-output", "results"}, &bytes.Buffer{}, &stdout, &stderr)
        c.Check(exitcode, check.Equals, 0)