(Feat): Initial Commit
Some checks failed
Build & Test / build-test (push) Has been cancelled
Build & Test / swagger-codegen-cli (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled

This commit is contained in:
2026-07-03 19:41:31 +05:30
commit 7e940c83a7
461 changed files with 45002 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
package test
import (
"errors"
"os"
"path/filepath"
"testing"
"allaboutapps.dev/aw/go-starter/internal/config"
"allaboutapps.dev/aw/go-starter/internal/util"
)
// DotEnvLoadLocalOrSkipTest tries to load the `.env.local` file in the projectroot
// overwriting ENV vars. If the file is not found, the test will be automatically skipped.
func DotEnvLoadLocalOrSkipTest(t *testing.T) {
t.Helper()
absolutePathToEnvFile := filepath.Join(util.GetProjectRootDir(), ".env.local")
DotEnvLoadFileOrSkipTest(t, absolutePathToEnvFile)
}
// DotEnvLoadFileOrSkipTest tries to load the overgiven path to the dotenv file overwriting
// ENV vars. If the file is not found, the test will be automatically skipped.
func DotEnvLoadFileOrSkipTest(t *testing.T, absolutePathToEnvFile string) {
t.Helper()
// this test should be automatically skipped if no default `.env.local` file was found.
err := config.DotEnvLoad(
absolutePathToEnvFile,
func(k string, v string) error { t.Setenv(k, v); return nil })
if err != nil {
if errors.Is(err, os.ErrNotExist) {
t.Skip(absolutePathToEnvFile, "not found, skipping test.")
} else {
t.Fatal(err)
}
} else {
t.Log(absolutePathToEnvFile, "override ENV variables!")
}
}