Skip to content

Commit

Permalink
remove useless test case
Browse files Browse the repository at this point in the history
  • Loading branch information
laureanray committed Aug 16, 2023
1 parent 08eff5e commit 972c71c
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 97 deletions.
80 changes: 0 additions & 80 deletions test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@ import (
"os"
"os/exec"
"path/filepath"
"reflect"
"strings"
"testing"
"time"
)

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

var binaryName = "clibgen"
var binaryPath = ""

Expand All @@ -42,12 +37,6 @@ func TestMain(m *testing.M) {
os.Exit(m.Run())
}

func runBinary(args []string) ([]byte, error) {
cmd := exec.Command(binaryPath, args...)
cmd.Env = append(os.Environ(), "GOCOVERDIR=.coverdata")
return cmd.CombinedOutput()
}

func runBinaryWithFileInput(args []string, bytesToWrite []byte) ([]byte, error) {
fmt.Println("Running binary with file input", bytesToWrite)
fmt.Printf("Executing command: %s", binaryPath)
Expand Down Expand Up @@ -99,38 +88,6 @@ func runBinaryWithFileInput(args []string, bytesToWrite []byte) ([]byte, error)
return out, err
}

func TestStaticCliArgs(t *testing.T) {
tests := []struct {
name string
args []string
fixture string
}{
{"help args", []string{"--help"}, "help.golden"},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
output, err := runBinary(tt.args)

if err != nil {
t.Fatal(err)
}

if *update {
writeFixture(t, tt.fixture, output)
}

actual := string(output)

expected := loadFixture(t, tt.fixture)

if !reflect.DeepEqual(actual, expected) {
t.Fatalf("actual = %s, expected = %s", actual, expected)
}
})
}
}

func TestSearch(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -158,40 +115,3 @@ func TestSearch(t *testing.T) {
})
}
}

func removeLastLine(str string, num int) string {
lines := strings.Split(str, "\n")

if len(lines) > 0 {
lines = lines[:len(lines)-num]
}

return strings.Join(lines, "\n")
}

func writeFixture(t *testing.T, goldenFile string, actual []byte) {
t.Helper()
goldenPath := "testdata/" + goldenFile

f, err := os.OpenFile(goldenPath, os.O_RDWR, 0644)
defer f.Close()

_, err = f.WriteString(string(actual))

if err != nil {
t.Fatalf("Error writing to file %s: %s", goldenPath, err)
}
}

func loadFixture(t *testing.T, goldenFile string) string {
goldenPath := "testdata/" + goldenFile

f, err := os.OpenFile(goldenPath, os.O_RDWR, 0644)

content, err := ioutil.ReadAll(f)
if err != nil {
t.Fatalf("Error opening file %s: %s", goldenPath, err)
}

return string(content)
}
17 changes: 0 additions & 17 deletions testdata/help.golden

This file was deleted.

0 comments on commit 972c71c

Please sign in to comment.