Skip to content

Commit

Permalink
tfexec: add initJSONCmd tests
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Schaatsbergen <git@bschaatsbergen.com>
  • Loading branch information
bschaatsbergen committed Oct 6, 2024
1 parent 160e8e8 commit 1589e33
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tfexec/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,57 @@ func TestInitCmd_v1(t *testing.T) {
}, nil, initCmd)
})
}

func TestInitJSONCmd(t *testing.T) {
td := t.TempDir()

tf, err := NewTerraform(td, tfVersion(t, testutil.Latest_v1_9))
if err != nil {
t.Fatal(err)
}

// empty env, to avoid environ mismatch in testing
tf.SetEnv(map[string]string{})

t.Run("defaults", func(t *testing.T) {
// defaults
initCmd, err := tf.initJSONCmd(context.Background())
if err != nil {
t.Fatal(err)
}

assertCmd(t, []string{
"init",
"-no-color",
"-input=false",
"-backend=true",
"-get=true",
"-upgrade=false",
"-json",
}, nil, initCmd)
})

t.Run("override all defaults", func(t *testing.T) {
initCmd, err := tf.initJSONCmd(context.Background(), Backend(false), BackendConfig("confpath1"), BackendConfig("confpath2"), FromModule("testsource"), Get(false), PluginDir("testdir1"), PluginDir("testdir2"), Reconfigure(true), Upgrade(true), Dir("initdir"))
if err != nil {
t.Fatal(err)
}

assertCmd(t, []string{
"init",
"-no-color",
"-input=false",
"-from-module=testsource",
"-backend=false",
"-get=false",
"-upgrade=true",
"-reconfigure",
"-backend-config=confpath1",
"-backend-config=confpath2",
"-plugin-dir=testdir1",
"-plugin-dir=testdir2",
"-json",
"initdir",
}, nil, initCmd)
})
}

0 comments on commit 1589e33

Please sign in to comment.