DEV Community

loading...

Sample test automation framework written in Golang

Sebastian Pazmay
Updated on ・1 min read

There are multiple test automation tools which are already well-developed and highly used. However as a POC and to brush-up my golang skills, I have created a sample test automation framework.

The test suites are written in Golang and they can be used to verify Linux systems configuration.

fmt.Println("## TEST CASES ##")
fmt.Println("1. Verify software OS version")
fmt.Println(testSuites.VerifyOSVersion(expectedVersion))
Enter fullscreen mode Exit fullscreen mode

Each test case calls another function which executes and parses the output.

func VerifyOSVersion(osVersion string) (bool) {
    var resultBool bool
    cmdOut, err := exec.Command("cat","/etc/issue").Output()
    fmt.Printf("OS version: %s", cmdOut)
    if err != nil {
        fmt.Printf("%s", err)
    }
    cmdOutStr := string(cmdOut[:])
    if cmdOutStrContainsOSVer := strings.Contains(cmdOutStr, osVersion) ; cmdOutStrContainsOSVer {
        resultBool = true
    } else { 
        resultBool = false 
    }
    return resultBool
}
Enter fullscreen mode Exit fullscreen mode

Furthermore, I have included a CI using github actions. The entire repository can be found in my github.

Discussion (0)