Adding gosec and lint, fixing null_type overflow
ChangeLog: - Adding gosec linting - Adding static type to enum - fixing nulltype overflow - Trying out gotestsum as an alternative to go-junit-report.xml
This commit is contained in:
parent
f9358ca8d2
commit
f7082eda68
16 changed files with 193 additions and 93 deletions
|
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/go-jet/jet/v2/generator/mysql"
|
||||
|
|
@ -124,7 +125,7 @@ func initMySQLDB(isMariaDB bool) error {
|
|||
|
||||
fmt.Println(cmdLine)
|
||||
|
||||
cmd := exec.Command("sh", "-c", cmdLine)
|
||||
cmd := exec.Command("sh", "-c", cmdLine) // #nosec G204
|
||||
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Stdout = os.Stdout
|
||||
|
|
@ -183,7 +184,7 @@ func initPostgresDB(dbType string, connectionString string) error {
|
|||
}
|
||||
|
||||
func execFile(db *sql.DB, sqlFilePath string) error {
|
||||
testSampleSql, err := os.ReadFile(sqlFilePath)
|
||||
testSampleSql, err := os.ReadFile(sqlFilePath) // #nosec G304
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read sql file - %s: %w", sqlFilePath, err)
|
||||
}
|
||||
|
|
@ -210,7 +211,10 @@ func execInTx(db *sql.DB, f func(tx *sql.Tx) error) error {
|
|||
err = f(tx)
|
||||
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
rollBackError := tx.Rollback()
|
||||
if rollBackError != nil {
|
||||
return errors.Join(rollBackError, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import (
|
|||
// Exists expects file to exist on path constructed from pathElems and returns content of the file
|
||||
func Exists(t *testing.T, pathElems ...string) (fileContent string) {
|
||||
modelFilePath := path.Join(pathElems...)
|
||||
file, err := os.ReadFile(modelFilePath)
|
||||
file, err := os.ReadFile(modelFilePath) // #nosec G304
|
||||
require.Nil(t, err)
|
||||
require.NotEmpty(t, file)
|
||||
return string(file)
|
||||
|
|
@ -19,6 +19,6 @@ func Exists(t *testing.T, pathElems ...string) (fileContent string) {
|
|||
// NotExists expects file not to exist on path constructed from pathElems
|
||||
func NotExists(t *testing.T, pathElems ...string) {
|
||||
modelFilePath := path.Join(pathElems...)
|
||||
_, err := os.ReadFile(modelFilePath)
|
||||
_, err := os.ReadFile(modelFilePath) // #nosec G304
|
||||
require.True(t, os.IsNotExist(err))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,12 +6,9 @@ import (
|
|||
jetmysql "github.com/go-jet/jet/v2/mysql"
|
||||
"github.com/go-jet/jet/v2/postgres"
|
||||
"github.com/go-jet/jet/v2/tests/dbconfig"
|
||||
"github.com/stretchr/testify/require"
|
||||
"math/rand"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/stretchr/testify/require"
|
||||
"runtime"
|
||||
|
||||
"github.com/pkg/profile"
|
||||
"os"
|
||||
|
|
@ -33,7 +30,6 @@ func sourceIsMariaDB() bool {
|
|||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
rand.Seed(time.Now().Unix())
|
||||
defer profile.Start().Stop()
|
||||
|
||||
var err error
|
||||
|
|
|
|||
|
|
@ -5,13 +5,10 @@ import (
|
|||
"database/sql"
|
||||
"fmt"
|
||||
"github.com/go-jet/jet/v2/tests/internal/utils/repo"
|
||||
"math/rand"
|
||||
"github.com/jackc/pgx/v4/stdlib"
|
||||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v4/stdlib"
|
||||
|
||||
"github.com/go-jet/jet/v2/postgres"
|
||||
"github.com/go-jet/jet/v2/tests/dbconfig"
|
||||
|
|
@ -44,7 +41,6 @@ func skipForCockroachDB(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
rand.Seed(time.Now().Unix())
|
||||
defer profile.Start().Stop()
|
||||
|
||||
setTestRoot()
|
||||
|
|
|
|||
|
|
@ -8,30 +8,21 @@ import (
|
|||
"github.com/go-jet/jet/v2/postgres"
|
||||
"github.com/go-jet/jet/v2/sqlite"
|
||||
"github.com/go-jet/jet/v2/tests/dbconfig"
|
||||
"github.com/stretchr/testify/require"
|
||||
"math/rand"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/profile"
|
||||
"github.com/stretchr/testify/require"
|
||||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
var db *sql.DB
|
||||
var sampleDB *sql.DB
|
||||
var testRoot string
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
rand.Seed(time.Now().Unix())
|
||||
defer profile.Start().Stop()
|
||||
|
||||
setTestRoot()
|
||||
|
||||
var err error
|
||||
db, err = sql.Open("sqlite3", "file:"+dbconfig.SakilaDBPath)
|
||||
throw.OnError(err)
|
||||
|
|
@ -50,16 +41,6 @@ func TestMain(m *testing.M) {
|
|||
}
|
||||
}
|
||||
|
||||
func setTestRoot() {
|
||||
cmd := exec.Command("git", "rev-parse", "--show-toplevel")
|
||||
byteArr, err := cmd.Output()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
testRoot = strings.TrimSpace(string(byteArr)) + "/tests/"
|
||||
}
|
||||
|
||||
var loggedSQL string
|
||||
var loggedSQLArgs []interface{}
|
||||
var loggedDebugSQL string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue