Skip to content

Commit

Permalink
functional tests in golang
Browse files Browse the repository at this point in the history
This is the work I had done last week for writing functional test in golang. Here I am providing the `output.json` file to `ioutil.ReadFile` and then comparing it with the stdout of `kompose convert`.
  • Loading branch information
procrypt committed Mar 27, 2017
1 parent 3c3ae98 commit 94a1180
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions script/test/cmd/tests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package main


import (
"fmt"
"os"
"os/exec"
"io/ioutil"
"reflect"
"strings"
)

func ExpectSuccess(dockerComposeFile, result string) {
b, _ := ioutil.ReadFile(result)
output := string(b)
cmdName := "kompose"
cmdArgs := []string{"convert","-f",dockerComposeFile,"--stdout","-j"}
cmd, err := exec.Command(cmdName, cmdArgs...).CombinedOutput()
if err != nil {
fmt.Fprintln(os.Stderr, "Error Cmd", err)
os.Exit(1)
}
if reflect.DeepEqual(output, string(cmd)){
fmt.Println("Output matches")
} else {
fmt.Println("Output not matches")
}
}

func ExpectSuccessAndWarning(dockerComposeFile, result string) {
warning := "WARN"
b, _ := ioutil.ReadFile(result)
output := string(b)
cmdName := "kompose"
cmdArgs := []string{"convert","--stdout","-f",dockerComposeFile,"-j"}
cmd, err := exec.Command(cmdName, cmdArgs...).CombinedOutput()
if err != nil {
fmt.Fprintln(os.Stderr, "Error Cmd", err)
os.Exit(1)
}
file := string(cmd)
if strings.Contains(file, warning){
str,err := exec.Command(cmdName, cmdArgs...).Output()
if err != nil {
fmt.Fprintln(os.Stderr, "Err Cmd", err)
os.Exit(1)
}
if reflect.DeepEqual(output,string(str)){
fmt.Println("Output matches")
} else {
fmt.Println("Output not matches")
}
}
}
func main() {
ExpectSuccess("sample.yml", "output.json")
ExpectSuccessAndWarning("docker-compose.yml", "warn.json")
}

0 comments on commit 94a1180

Please sign in to comment.