|
|
|
|
@ -7,6 +7,7 @@ import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
|
|
|
"github.com/google/go-cmp/cmp/cmpopts"
|
|
|
|
|
"github.com/hashicorp/terraform/internal/tfdiags"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@ -20,6 +21,7 @@ func TestParseProvidersMirror_valid(t *testing.T) {
|
|
|
|
|
&ProvidersMirror{
|
|
|
|
|
LockFile: true,
|
|
|
|
|
OutputDir: "./mirror",
|
|
|
|
|
Vars: &Vars{},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"all options": {
|
|
|
|
|
@ -32,17 +34,20 @@ func TestParseProvidersMirror_valid(t *testing.T) {
|
|
|
|
|
&ProvidersMirror{
|
|
|
|
|
Platforms: FlagStringSlice{"linux_amd64", "darwin_arm64"},
|
|
|
|
|
OutputDir: "./mirror",
|
|
|
|
|
Vars: &Vars{},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmpOpts := cmpopts.IgnoreUnexported(Vars{})
|
|
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
|
got, diags := ParseProvidersMirror(tc.args)
|
|
|
|
|
if len(diags) > 0 {
|
|
|
|
|
t.Fatalf("unexpected diags: %v", diags)
|
|
|
|
|
}
|
|
|
|
|
if diff := cmp.Diff(tc.want, got); diff != "" {
|
|
|
|
|
if diff := cmp.Diff(tc.want, got, cmpOpts); diff != "" {
|
|
|
|
|
t.Fatalf("unexpected result\n%s", diff)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
@ -59,6 +64,7 @@ func TestParseProvidersMirror_invalid(t *testing.T) {
|
|
|
|
|
nil,
|
|
|
|
|
&ProvidersMirror{
|
|
|
|
|
LockFile: true,
|
|
|
|
|
Vars: &Vars{},
|
|
|
|
|
},
|
|
|
|
|
tfdiags.Diagnostics{
|
|
|
|
|
tfdiags.Sourceless(
|
|
|
|
|
@ -72,6 +78,7 @@ func TestParseProvidersMirror_invalid(t *testing.T) {
|
|
|
|
|
[]string{"./mirror", "./extra"},
|
|
|
|
|
&ProvidersMirror{
|
|
|
|
|
LockFile: true,
|
|
|
|
|
Vars: &Vars{},
|
|
|
|
|
},
|
|
|
|
|
tfdiags.Diagnostics{
|
|
|
|
|
tfdiags.Sourceless(
|
|
|
|
|
@ -85,6 +92,7 @@ func TestParseProvidersMirror_invalid(t *testing.T) {
|
|
|
|
|
[]string{"-wat"},
|
|
|
|
|
&ProvidersMirror{
|
|
|
|
|
LockFile: true,
|
|
|
|
|
Vars: &Vars{},
|
|
|
|
|
},
|
|
|
|
|
tfdiags.Diagnostics{
|
|
|
|
|
tfdiags.Sourceless(
|
|
|
|
|
@ -101,13 +109,60 @@ func TestParseProvidersMirror_invalid(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmpOpts := cmpopts.IgnoreUnexported(Vars{})
|
|
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
|
got, gotDiags := ParseProvidersMirror(tc.args)
|
|
|
|
|
if diff := cmp.Diff(tc.want, got); diff != "" {
|
|
|
|
|
if diff := cmp.Diff(tc.want, got, cmpOpts); diff != "" {
|
|
|
|
|
t.Fatalf("unexpected result\n%s", diff)
|
|
|
|
|
}
|
|
|
|
|
tfdiags.AssertDiagnosticsMatch(t, gotDiags, tc.wantDiags)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestParseProvidersMirror_vars(t *testing.T) {
|
|
|
|
|
testCases := map[string]struct {
|
|
|
|
|
args []string
|
|
|
|
|
want []FlagNameValue
|
|
|
|
|
}{
|
|
|
|
|
"var": {
|
|
|
|
|
args: []string{"-var", "foo=bar", "./mirror"},
|
|
|
|
|
want: []FlagNameValue{
|
|
|
|
|
{Name: "-var", Value: "foo=bar"},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"var-file": {
|
|
|
|
|
args: []string{"-var-file", "cool.tfvars", "./mirror"},
|
|
|
|
|
want: []FlagNameValue{
|
|
|
|
|
{Name: "-var-file", Value: "cool.tfvars"},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"both": {
|
|
|
|
|
args: []string{
|
|
|
|
|
"-var", "foo=bar",
|
|
|
|
|
"-var-file", "cool.tfvars",
|
|
|
|
|
"-var", "boop=beep",
|
|
|
|
|
"./mirror",
|
|
|
|
|
},
|
|
|
|
|
want: []FlagNameValue{
|
|
|
|
|
{Name: "-var", Value: "foo=bar"},
|
|
|
|
|
{Name: "-var-file", Value: "cool.tfvars"},
|
|
|
|
|
{Name: "-var", Value: "boop=beep"},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
|
got, diags := ParseProvidersMirror(tc.args)
|
|
|
|
|
if len(diags) > 0 {
|
|
|
|
|
t.Fatalf("unexpected diags: %v", diags)
|
|
|
|
|
}
|
|
|
|
|
if vars := got.Vars.All(); !cmp.Equal(vars, tc.want) {
|
|
|
|
|
t.Fatalf("unexpected vars: %#v", vars)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|