From e61a7b3d650e6fb65ecdd1b898bda4189b5fd761 Mon Sep 17 00:00:00 2001 From: KeeganForelight Date: Fri, 16 Jun 2023 17:17:39 -0400 Subject: [PATCH] adding test file --- .gitignore | 12 +------ bin/gotest.py | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 11 deletions(-) create mode 100755 bin/gotest.py diff --git a/.gitignore b/.gitignore index 774fc26..44e7ac8 100644 --- a/.gitignore +++ b/.gitignore @@ -13,19 +13,9 @@ # swap files *.swp -# Dependency directories (remove the comment below to include it) -# vendor/ # binaries -bin -*.tar.gz -# logs -*.log +bin/frms* # task related .task/ - -# machine dependent -tokens/ -logs/ -influxdb/config diff --git a/bin/gotest.py b/bin/gotest.py new file mode 100755 index 0000000..1fa03c9 --- /dev/null +++ b/bin/gotest.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python +import json +import subprocess + +class PackageTest: + def __init__(self): + self.status = "" + self.tests = [] + self.totaltime = 0 + +res = {} + +output = subprocess.run(["go","test","-count=1","-json","./..."], capture_output=True, text=True) + +output = str(output.stdout) +output = output.split('\n') + +for line in output[:-1]: + # parse the json + parsed = json.loads(line) + action = parsed["Action"] + + # skip + if action in ["start", "output", "run"]: + continue + + # create blank if doesn't exist + if parsed["Package"] not in res: + res[parsed["Package"]] = PackageTest() + + pkg = res[parsed["Package"]] + + if "Test" not in parsed: + # top level package result + pkg.status = action + if "Elapsed" in parsed: + pkg.totaltime = parsed["Elapsed"] + else: + # individual test + pkg.tests.append((parsed["Test"],parsed["Action"],parsed["Elapsed"])) + +totalRan = 0 +totalPassed = 0 +totalTime = 0 +# generating output from parsed json +for name, info in res.items(): + pkgname = name.split('/') + pkgname = '/'.join(name.split('/')[1:]) + if info.status == "skip": + print("Skipped %s" % (pkgname)) + continue + + print("\nTesting %s:" % (pkgname)) + + passed = 0 + total = 0 + + for test in info.tests: + total += 1 + out = [] + if test[1] == "pass": + passed += 1 + out = [" " + test[0] + ":",'\033[32mpass\033[0m ',str(test[2]) + 's'] + elif test[1] == "fail": + out = [" " + test[0] + ":",'\033[31mfail\033[0m ',str(test[2]) + 's'] + + print(f"{out[0] : <30}{out[1] : >5}{out[2] : >8}") + + result = "" + if info.status == "pass": + result = "\033[32mPASSED\033[0m" + else: + result = "\033[31mFAILED\033[0m" + + # keep track of grand totals + totalRan += total + totalPassed += passed + totalTime += info.totaltime + + print(" %s %d/%d in %.3fs/n" % (result, passed, total, info.totaltime)) + + +# output overall test statistics +if totalRan == totalPassed: + result = "\033[32mPASSED\033[0m" +else: + result = "\033[31mFAILED\033[0m" + +print("\nSUMMARY:\n\t%s %d/%d in %.3fs" % (result, totalPassed, totalRan, totalTime))