From 972c71c71018f8ec6ac61be2bd10c8b2982a491c Mon Sep 17 00:00:00 2001 From: laureanray Date: Thu, 17 Aug 2023 04:25:19 +0800 Subject: [PATCH] remove useless test case --- test/integration_test.go | 80 ---------------------------------------- testdata/help.golden | 17 --------- 2 files changed, 97 deletions(-) delete mode 100644 testdata/help.golden diff --git a/test/integration_test.go b/test/integration_test.go index 735c540..dfa1829 100644 --- a/test/integration_test.go +++ b/test/integration_test.go @@ -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 = "" @@ -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) @@ -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 @@ -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) -} diff --git a/testdata/help.golden b/testdata/help.golden deleted file mode 100644 index 74b8286..0000000 --- a/testdata/help.golden +++ /dev/null @@ -1,17 +0,0 @@ - -Clibgen is a CLI application to search and download epubs, pdfs, from library genesis. -Useful if you are lazy to open up a browser to download e-books/resources. - -Usage: - clibgen [command] - -Available Commands: - completion Generate the autocompletion script for the specified shell - help Help about any command - search search for a book, paper or article - version Print the version number of Hugo - -Flags: - -h, --help help for clibgen - -Use "clibgen [command] --help" for more information about a command.