Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
CI-friendly golden testing fixes
  • Loading branch information
Drew O'Meara committed Feb 12, 2022
commit 4a49a6d8eed18fa591fd30abe05c0f8046ca4c32
33 changes: 21 additions & 12 deletions examples/embedding/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,33 @@ package main

import (
"bytes"
"flag"
"os"
"os/exec"
"path/filepath"
"testing"
)

const embeddingTestOutput = "testdata/embedding_golden.txt"
const embeddingTestOutput = "testdata/embedding_out_golden.txt"

var regen = flag.Bool("regen", false, "regenerate golden files")

func TestEmbeddedExample(t *testing.T) {

tmp, err := os.MkdirTemp("", "go-python-embedding-")
if err != nil { t.Fatal(err) }
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmp)
cmd := exec.Command("go", "build", "-o", filepath.Join(tmp,"exe"), ".")
err := cmd.Run()

cmd := exec.Command("go", "build", "-o", filepath.Join(tmp, "exe"), ".")
Comment thread
drew-512 marked this conversation as resolved.
Outdated
err = cmd.Run()
if err != nil {
t.Fatalf("failed to compile embedding example: %v", err)
}

out := new(bytes.Buffer)
cmd = exec.Command(filepath.Join(tmp,"exe"), "mylib-demo.py")
cmd = exec.Command(filepath.Join(tmp, "exe"), "mylib-demo.py")
Comment thread
drew-512 marked this conversation as resolved.
Outdated
cmd.Stdout = out

err = cmd.Run()
Expand All @@ -31,17 +37,20 @@ func TestEmbeddedExample(t *testing.T) {
}

testOutput := out.Bytes()

flag.Parse()
if *regen {
err = os.WriteFile(embeddingTestOutput, testOutput, 0644)
if err != nil {
t.Fatalf("failed to write test output: %v", err)
}
}
mustMatch, err := os.ReadFile(embeddingTestOutput)
if err != nil {
t.Fatalf("failed read %q", embeddingTestOutput)
}
if !bytes.Equal(testOutput, mustMatch) {
t.Fatalf("embedded test output did not match accepted output from %q", embeddingTestOutput)
}

mustMatch, err := os.ReadFile(embeddingTestOutput)
if err != nil {
t.Fatalf("failed read %q", embeddingTestOutput)
}
if !bytes.Equal(testOutput, mustMatch) {
t.Fatalf("embedded test output did not match accepted output from %q", embeddingTestOutput)
}
Comment thread
drew-512 marked this conversation as resolved.
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Spring Break itinerary:
Stop 2: Mallorca, Spain | 3 nights
Stop 3: Ibiza, Spain | 14 nights
Stop 4: Monaco | 12 nights
### Made with Vacaton 1.0 by Fletch F. Fletcher
### Made with Vacation 1.0 by Fletch F. Fletcher

I bet Monaco will be the best!