Snippets

Jason Kenny ATS simple test examples

Created by Jason Kenny last modified
How to extend test
Add to a file that ends with test.ext and register function with ExtendTest. This allow the in the simple case an easy way to make macro like functions. In more complex cases a way to extend the system. A common case example of using this would be to add function that deal with common behavior for your application. For example, you might be compiling files. Instead of telling the system a common setup steps to compile a given program you might define an extension such as:
def Buid(Test,filename=’test.cpp’):
        tr=Test.AddTestRun("Build","build test file: {0}".format(filename))
        tr.Command='gcc {0}'.format(filename)
        tr.ReturnCode=0
        return tr

So instead of writing a test like this:
tr=Test.AddTestRun("Build-Test","build test file: test1.cpp")
tr.Command='gcc test1'
tr.ReturnCode=0
tr=Test.AddTestRun("Run-Test")
tr.Command='test1'
tr.ReturnCode=0

you can now say something like:
Test.Build(“test1.cpp”)
tr=Test.AddTestRun("Run-Test")
tr.Command='test1'
tr.ReturnCode=0
# this example would be started with something like "autest --ats-bin=/opt/ats/bin"

# very simple test

Test.Summary = "Test Trafficserver starting and curl test"

Test.Processes.Process("ts", "traffic_server")
t = Test.AddTestRun("Test traffic started properly ")
t.StillRunningAfter = Test.Processes.ts

p = t.Processes.Default
p.Command = "curl http://127.0.0.1:8080"
p.ReturnCode = 0

p.StartBefore(Test.Processes.ts)
Test.Processes.ts.Ready = When.PortOpen(8080)

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.