diff --git a/script/test/cmd/tests.go b/script/test/cmd/tests.go new file mode 100644 index 0000000000..c6ea36760d --- /dev/null +++ b/script/test/cmd/tests.go @@ -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") +} \ No newline at end of file