tests: cleanup the basic structure of integration tests.

This commit is contained in:
Alexandre Pujol 2024-11-19 21:27:04 +00:00
parent 206bc3473d
commit 5c70c50c26
No known key found for this signature in database
GPG key ID: C5469996F0DF68EC
45 changed files with 49 additions and 501 deletions

View file

@ -68,7 +68,6 @@ func run() error {
if err != nil {
return err
}
tests = tests.Filter()
if err := cfg.BatsDir.RemoveAll(); err != nil {
return err
@ -76,6 +75,12 @@ func run() error {
if err := cfg.BatsDir.MkdirAll(); err != nil {
return err
}
if err := cfg.BatsDir.Join("profiled").MkdirAll(); err != nil {
return err
}
if err := cfg.BatsDir.Join("unprofiled").MkdirAll(); err != nil {
return err
}
for _, test := range tests {
if err := test.Write(cfg.BatsDir); err != nil {
return err

View file

@ -20,16 +20,10 @@ const tmplTest = `#!/usr/bin/env bats
# SPDX-License-Identifier: GPL-2.0-only
load common
setup_file() {
aa_setup
}
{{ $name := .Name -}}
{{ range .Commands }}
# bats test_tags={{ $name }}
@test "{{ $name }}: {{ .Description }}" {
{{ .Cmd }}
aa_check
}
{{ end }}
`
@ -77,13 +71,14 @@ func (t Test) IsInstalled() bool {
}
func (t Test) Write(dir *paths.Path) error {
dstDir := dir.Join("profiled")
if !t.HasProfile() {
return nil
dstDir = dir.Join("unprofiled")
}
path := dstDir.Join(t.Name + ".bats")
path := dir.Join(t.Name + ".bats")
if paths.New("tests/bats").Join(t.Name + ".bats").Exist() {
path = dir.Join("00." + t.Name + ".bats")
path = dstDir.Join("00." + t.Name + ".bats")
}
content := renderBatsFile(t)
if err := path.WriteFile([]byte(content)); err != nil {