Files
helmfile/pkg/testhelper/require_log.go
T
Yusuke Kuoka fc306ec3d1 Make a few helmfile sub-commands consistently support needs-related flags (#78)
* Make a few helmfile sub-commands to consistently support needs-related flags

* helmfile-diff adds support for --include-transitive-needs
* helmfile-template adds support for --skip-needs
* helmfile-lint adds support for --skip-needs, --include-needs, and --include-transitive-needs

Ref https://github.com/roboll/helmfile/issues/2055

Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>

* Fix a few helmfile-lint needs related bugs and add tests

Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>

* Is include-transitive-needs realy working as intended? 🤔

Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>

* Confirm that it does fail on unselected need by default

Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>

* Add missing testdata

Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>

* Test helmfile-template for include/skip needs support

Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>

* Fix a few terms

Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>

* Add more tests to better know the current helmfile-diff behavior around needs

Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>

* Fix failing tests

Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>

* Fix helmfile-diff to consistently handle skip/include-needs

Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>

* Extract testhelper.RequireLog for reusing

Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>

* Fix all bugs and test cases for TestDiff and TestDiff_2

Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>

* Fix TestDiff_2

Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>

* Fix TestDiff

Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>

* Fix TestDiffWithNeeds

Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>

* Unify behavior on including disabled releases as needs for lint and template

Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>

* Fix bug that --include-transitive-needs does not imply include-needs

Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>
2022-06-20 07:19:39 +09:00

42 lines
1.0 KiB
Go

package testhelper
import (
"bytes"
"os"
"path/filepath"
"strings"
"testing"
)
func RequireLog(t *testing.T, dir string, bs *bytes.Buffer) {
t.Helper()
testNameComponents := strings.Split(t.Name(), "/")
testBaseName := strings.ToLower(
strings.ReplaceAll(
testNameComponents[len(testNameComponents)-1],
" ",
"_",
),
)
wantLogFileDir := filepath.Join("testdata", dir)
wantLogFile := filepath.Join(wantLogFileDir, testBaseName)
wantLogData, err := os.ReadFile(wantLogFile)
updateLogFile := err != nil
wantLog := string(wantLogData)
gotLog := bs.String()
if updateLogFile {
if err := os.MkdirAll(wantLogFileDir, 0755); err != nil {
t.Fatalf("unable to create directory %q: %v", wantLogFileDir, err)
}
if err := os.WriteFile(wantLogFile, bs.Bytes(), 0644); err != nil {
t.Fatalf("unable to update lint log snapshot: %v", err)
}
}
diff, exists := Diff(wantLog, gotLog, 3)
if exists {
t.Errorf("unexpected log:\nDIFF\n%s\nEOD\nPlease remove %s and rerun the test to recapture this test snapshot", diff, wantLogFile)
}
}