Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
Run read tests as part of make test (#260)
Browse files Browse the repository at this point in the history
* Run ReadPlannedAssets tests as part of unit tests

* Fixed full_container_cluster test

Had to update the terraform file for compatibility with GoogleCloudPlatform/magic-modules#4762

* Regenerated full_spanner_instance plan

* Regenerated full_compute_instance plan json

* Removed example_compute_forwarding_rule read test since it can't run in offline mode

* Re-generated example_sql_database_instance tfplan json

* Removed example_compute_instance test

This can't run in offline mode

* Fixed marshalling/unmarshalling of timestamps

* Regenerated project organization policy tfplan json
  • Loading branch information
melinath authored Jul 21, 2021
1 parent d6af2f0 commit f728b0c
Show file tree
Hide file tree
Showing 11 changed files with 248 additions and 753 deletions.
4 changes: 2 additions & 2 deletions converters/google/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ type Timestamp struct {
}

func (t Timestamp) MarshalJSON() ([]byte, error) {
return []byte(`"` + time.Unix(t.Seconds, t.Nanos).Format(time.RFC3339Nano) + `"`), nil
return []byte(`"` + time.Unix(0, t.Nanos).UTC().Format(time.RFC3339Nano) + `"`), nil
}

func (t Timestamp) UnmarshalJSON(b []byte) error {
func (t *Timestamp) UnmarshalJSON(b []byte) error {
p, err := time.Parse(time.RFC3339Nano, strings.Trim(string(b), `"`))
if err != nil {
return fmt.Errorf("bad Timestamp: %v", err)
Expand Down
30 changes: 30 additions & 0 deletions converters/google/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"sort"
"testing"
"time"

"github.com/GoogleCloudPlatform/terraform-validator/ancestrymanager"
tfjson "github.com/hashicorp/terraform-json"
Expand Down Expand Up @@ -401,3 +402,32 @@ func TestAddStorageModuleAfterUnknown(t *testing.T) {
}

}

func TestTimestampMarshalJSON(t *testing.T) {
expectedJSON := []byte("\"2021-04-14T15:16:17Z\"")
date := time.Date(2021, time.April, 14, 15, 16, 17, 0, time.UTC)
ts := Timestamp{
Seconds: int64(date.Unix()),
Nanos: int64(date.UnixNano()),
}
json, err := ts.MarshalJSON()
if err != nil {
t.Fatalf("Unexpected error: %s", err)
}
assert.EqualValues(t, json, expectedJSON)
}

func TestTimestampUnmarshalJSON(t *testing.T) {
expectedDate := time.Date(2021, time.April, 14, 15, 16, 17, 0, time.UTC)
expected := Timestamp{
Seconds: int64(expectedDate.Unix()),
Nanos: int64(expectedDate.UnixNano()),
}
json := []byte("\"2021-04-14T15:16:17Z\"")
ts := Timestamp{}
err := ts.UnmarshalJSON(json)
if err != nil {
t.Fatalf("Unexpected error: %s", err)
}
assert.EqualValues(t, ts, expected)
}
11 changes: 4 additions & 7 deletions test/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,19 @@ import (
)

func TestReadPlannedAssetsCoverage(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test in short mode.")
return
}

cases := []struct {
name string
}{
{name: "example_bigquery_dataset"},
{name: "example_bigtable_instance"},
{name: "example_compute_disk"},
{name: "example_compute_firewall"},
{name: "example_compute_instance"},
// This test can't run in offline mode
// {name: "example_compute_instance"},
{name: "example_compute_network"},
{name: "example_compute_subnetwork"},
{name: "example_compute_forwarding_rule"},
// This test can't run in offline mode.
// {name: "example_compute_forwarding_rule"},
{name: "example_compute_global_forwarding_rule"},
{name: "example_container_cluster"},
{name: "example_filestore_instance"},
Expand Down
118 changes: 0 additions & 118 deletions testdata/templates/example_compute_forwarding_rule.tfplan.json

This file was deleted.

Loading

0 comments on commit f728b0c

Please sign in to comment.