-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support for GCS history backend
- Loading branch information
Showing
10 changed files
with
834 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package config | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
storage "github.com/minamijoyo/tfmigrate-storage" | ||
"github.com/minamijoyo/tfmigrate-storage/gcs" | ||
) | ||
|
||
func TestParseGCSStorageBlock(t *testing.T) { | ||
cases := []struct { | ||
desc string | ||
source string | ||
want storage.Config | ||
ok bool | ||
}{ | ||
{ | ||
desc: "valid (required)", | ||
source: ` | ||
tfmigrate { | ||
history { | ||
storage "gcs" { | ||
bucket = "tfmigrate-test" | ||
name = "tfmigrate/history.json" | ||
} | ||
} | ||
} | ||
`, | ||
want: &gcs.Config{ | ||
Bucket: "tfmigrate-test", | ||
Name: "tfmigrate/history.json", | ||
}, | ||
ok: true, | ||
}, | ||
{ | ||
desc: "valid (with optional)", | ||
source: ` | ||
tfmigrate { | ||
history { | ||
storage "gcs" { | ||
bucket = "tfmigrate-test" | ||
name = "tfmigrate/history.json" | ||
} | ||
} | ||
} | ||
`, | ||
want: &gcs.Config{ | ||
Bucket: "tfmigrate-test", | ||
Name: "tfmigrate/history.json", | ||
}, | ||
ok: true, | ||
}, | ||
{ | ||
desc: "missing required attribute (bucket)", | ||
source: ` | ||
tfmigrate { | ||
history { | ||
storage "gcs" { | ||
Name = "tfmigrate/history.json" | ||
} | ||
} | ||
} | ||
`, | ||
want: nil, | ||
ok: false, | ||
}, | ||
{ | ||
desc: "missing required attribute (name)", | ||
source: ` | ||
tfmigrate { | ||
history { | ||
storage "gcs" { | ||
bucket = "tfmigrate-test" | ||
} | ||
} | ||
} | ||
`, | ||
want: nil, | ||
ok: false, | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
t.Run(tc.desc, func(t *testing.T) { | ||
config, err := ParseConfigurationFile("test.hcl", []byte(tc.source)) | ||
if tc.ok && err != nil { | ||
t.Fatalf("unexpected err: %s", err) | ||
} | ||
if !tc.ok && err == nil { | ||
t.Fatalf("expected to return an error, but no error, got: %#v", config) | ||
} | ||
if tc.ok { | ||
got := config.History.Storage | ||
if !reflect.DeepEqual(got, tc.want) { | ||
t.Errorf("got: %#v, want: %#v", got, tc.want) | ||
} | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.