Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions cmd/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,16 @@ func TestStateSubcommandsAreRegistered(t *testing.T) {
"diff": true,
"drift": true,
}
// cobra の Commands() は初回呼び出し時に内部スライスを遅延ソートするため、
// 複数の並行テストから同じコマンドに対して呼ぶと data race になる。
// stateCmd.Commands() を呼ぶ検証はこのテストに集約する。
for _, c := range stateCmd.Commands() {
if c.Name() == "sync" {
t.Errorf("state sync subcommand should not exist after merge into apply")
}
delete(want, c.Name())
}
if len(want) != 0 {
t.Errorf("state subcommands missing: %v", want)
}
}

func TestStateSyncSubcommandIsRemoved(t *testing.T) {
t.Parallel()
for _, c := range stateCmd.Commands() {
if c.Name() == "sync" {
t.Errorf("state sync subcommand should not exist after merge into apply")
}
}
}
7 changes: 7 additions & 0 deletions cmd/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

v1 "github.com/pepabo/tazuna/api/v1"
"github.com/spf13/pflag"
)

func TestInitialMinimumSupportedVersion(t *testing.T) {
Expand Down Expand Up @@ -50,6 +51,12 @@ func runInit(t *testing.T, args ...string) (string, error) {
rootCmd.SetArgs(nil)
rootCmd.SetOut(nil)
rootCmd.SetErr(nil)
// cobra のフラグ値は Execute() をまたいでプロセス内に保持されるため、
// デフォルトに戻さないと後続のテスト実行(-count>1 など)に漏れる。
initCmd.Flags().VisitAll(func(f *pflag.Flag) {
_ = f.Value.Set(f.DefValue)
f.Changed = false
})
})
err := rootCmd.Execute()
return buf.String(), err
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ require (
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.1
github.com/spf13/cobra v1.10.2
github.com/spf13/pflag v1.0.10
github.com/stretchr/testify v1.11.1
go.opentelemetry.io/otel v1.43.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.43.0
Expand Down Expand Up @@ -153,7 +154,6 @@ require (
github.com/shopspring/decimal v1.4.0 // indirect
github.com/sirupsen/logrus v1.9.4 // indirect
github.com/spf13/cast v1.10.0 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/tidwall/gjson v1.19.0 // indirect
github.com/tidwall/match v1.2.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
Expand Down