featurebase/cmd/roaring-migrate/main_test.go
CLoZengineer f9ddb5d5c1
fix: updating code to meet linting requirements (#2171)
* removes unused filesize function

* removes ioutil usage

* updates ioutil.ReadAll to io.ReadAll

* updates ioutil.TempFile to os.CreateTemp

* updates ioutil.TempDir to os.MkdirTemp

* updates ioutil.ReadAll to os.ReadAll

* update ioutil.WriteFile to os.WriteFile

* updates ioutil.Discard to io.Discard

* updates ioutil.ReadDir to os.ReadDir where applicable

* removes unused code in idk

* creates type to use for context value keys

* replaces assert.Nil with assert.NoError for error checks
2022-09-29 12:34:29 -04:00

55 lines
986 B
Go

package main
import (
"os"
"testing"
)
func TestFileExists(t *testing.T) {
fileName := "missing"
if x, _ := fileExists(fileName); x {
t.Fatalf("file %v doesn't exist", fileName)
}
file, err := os.Create(fileName)
if err != nil {
t.Fatal(err)
}
file.Close()
if x, _ := fileExists(fileName); !x {
t.Fatalf("file %v doesn't exist", fileName)
}
t.Cleanup(func() {
os.Remove(fileName)
})
}
func TestMainProgram(t *testing.T) {
os.Args = []string{"roaring-migrate",
"--verbose",
}
if realMain() == 0 {
t.Fatal("should fail and it succeeded")
}
os.Args = []string{"roaring-migrate",
"--verbose",
}
if realMain() == 0 {
t.Fatal("should fail and it succeeded")
}
dir, err := os.MkdirTemp("", "backup")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir) // clean up
os.Args = []string{"roaring-migrate",
"--verbose=true",
"--data-dir=testdata/data-dir/",
"--backup-dir=" + dir,
}
if realMain() == 1 {
t.Fatal("shouldn't fail")
}
}