From e93b3d8fa37e10624974f524cdf850da2090beed Mon Sep 17 00:00:00 2001 From: domi41 Date: Thu, 21 Oct 2021 11:32:24 +0200 Subject: [PATCH] test: add smoke tests on some basic calls --- .github/workflows/go.yml | 15 ++++-- build.sh | 3 +- go.mod | 3 ++ main_test.go | 98 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 115 insertions(+), 4 deletions(-) create mode 100644 main_test.go diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 0a4aad2..11f3fec 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -18,11 +18,20 @@ jobs: with: go-version: 1.17 + - name: Install UPX + run: apt install upx + + - name: Go Get Govvv + run: go get github.com/ahmetb/govvv + - name: Go Get run: go get - + + - name: Integration Tests + run: go test -v + - name: Build Linux - run: go build -v -o mj + run: ./build.sh - - name: Test + - name: Test Build run: ./mj example/example.csv --sort diff --git a/build.sh b/build.sh index d94a58d..b18e9ed 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,7 @@ #!/bin/bash -# Install govvv first +# Install things first +#apt install upx #go get github.com/ahmetb/govvv go build \ diff --git a/go.mod b/go.mod index 97c1a00..a3fff98 100644 --- a/go.mod +++ b/go.mod @@ -6,16 +6,19 @@ require ( github.com/mieuxvoter/majority-judgment-library-go v0.2.2 github.com/spf13/cobra v1.2.1 github.com/spf13/viper v1.9.0 + github.com/stretchr/testify v1.7.0 gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b ) require ( + github.com/davecgh/go-spew v1.1.1 // indirect github.com/fsnotify/fsnotify v1.5.1 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/magiconair/properties v1.8.5 // indirect github.com/mitchellh/mapstructure v1.4.2 // indirect github.com/pelletier/go-toml v1.9.4 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/spf13/afero v1.6.0 // indirect github.com/spf13/cast v1.4.1 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..b702c35 --- /dev/null +++ b/main_test.go @@ -0,0 +1,98 @@ +package main + +import ( + "os" + "testing" +) + +//func Test(t *testing.T) { +// os.Args = []string{os.Args[0], "example/example6.csv", "--format", "gnuplot"} +// main() +//} + +//func Test2(t *testing.T) { +// os.Args = []string{os.Args[0], "example/example6.csv", "--fo"} +// main() +//} + +var testData = []struct { + name string + args []string + code int + stdout string + stderr string +}{ + { + name: "Basic usage, example.csv", + args: []string{ + "example/example.csv", + }, + }, + { + name: "Basic usage, example1.csv", + args: []string{ + "example/example1.csv", + }, + }, + { + name: "Basic usage, example2.csv", + args: []string{ + "example/example2.csv", + }, + }, + { + name: "Basic usage, example3.csv", + args: []string{ + "example/example3.csv", + }, + }, + { + name: "Basic usage, example4.csv", + args: []string{ + "example/example4.csv", + }, + }, + { + name: "Basic usage, example5.csv", + args: []string{ + "example/example5.csv", + }, + }, + { + name: "Basic usage, example6.csv", + args: []string{ + "example/example6.csv", + }, + }, + { + name: "--sort usage, example.csv", + args: []string{ + "example/example.csv", + "--sort", + }, + }, + { + name: "--format gnuplot, example.csv", + args: []string{ + "example/example.csv", + "--format", + "gnuplot", + }, + }, +} + +func TestAll(t *testing.T) { + for _, tt := range testData { + t.Run(tt.name, func(t *testing.T) { + + os.Args = []string{os.Args[0]} + os.Args = append(os.Args, tt.args...) + main() + + // How to do? + // Check return code against tt.code + // Check stdout against tt.stdout + // Check stderr against tt.stderr + }) + } +}