mirror of
https://github.com/hashicorp/terraform.git
synced 2026-03-21 18:10:30 -04:00
88 lines
1.8 KiB
Go
88 lines
1.8 KiB
Go
// Copyright IBM Corp. 2014, 2026
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package arguments
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
"github.com/hashicorp/terraform/internal/tfdiags"
|
|
)
|
|
|
|
func TestParseProviders_valid(t *testing.T) {
|
|
testCases := map[string]struct {
|
|
args []string
|
|
want *Providers
|
|
}{
|
|
"defaults": {
|
|
nil,
|
|
&Providers{
|
|
TestsDirectory: "tests",
|
|
},
|
|
},
|
|
"test directory": {
|
|
[]string{"-test-directory=integration-tests"},
|
|
&Providers{
|
|
TestsDirectory: "integration-tests",
|
|
},
|
|
},
|
|
}
|
|
|
|
for name, tc := range testCases {
|
|
t.Run(name, func(t *testing.T) {
|
|
got, diags := ParseProviders(tc.args)
|
|
if len(diags) > 0 {
|
|
t.Fatalf("unexpected diags: %v", diags)
|
|
}
|
|
if diff := cmp.Diff(tc.want, got); diff != "" {
|
|
t.Fatalf("unexpected result\n%s", diff)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseProviders_invalid(t *testing.T) {
|
|
testCases := map[string]struct {
|
|
args []string
|
|
want *Providers
|
|
wantDiags tfdiags.Diagnostics
|
|
}{
|
|
"unknown flag": {
|
|
[]string{"-wat"},
|
|
&Providers{
|
|
TestsDirectory: "tests",
|
|
},
|
|
tfdiags.Diagnostics{
|
|
tfdiags.Sourceless(
|
|
tfdiags.Error,
|
|
"Failed to parse command-line flags",
|
|
"flag provided but not defined: -wat",
|
|
),
|
|
},
|
|
},
|
|
"too many positional arguments": {
|
|
[]string{"foo"},
|
|
&Providers{
|
|
TestsDirectory: "tests",
|
|
},
|
|
tfdiags.Diagnostics{
|
|
tfdiags.Sourceless(
|
|
tfdiags.Error,
|
|
"Too many command line arguments",
|
|
"Did you mean to use -chdir?",
|
|
),
|
|
},
|
|
},
|
|
}
|
|
|
|
for name, tc := range testCases {
|
|
t.Run(name, func(t *testing.T) {
|
|
got, gotDiags := ParseProviders(tc.args)
|
|
if diff := cmp.Diff(tc.want, got); diff != "" {
|
|
t.Fatalf("unexpected result\n%s", diff)
|
|
}
|
|
tfdiags.AssertDiagnosticsMatch(t, gotDiags, tc.wantDiags)
|
|
})
|
|
}
|
|
}
|