From 2cf6d05b5b9e4ec711fa1f433d17b2d2b19342c1 Mon Sep 17 00:00:00 2001 From: Zhiwei Liang Date: Wed, 22 Jan 2025 18:08:40 -0500 Subject: [PATCH 1/4] Enforce code format including tests --- .github/workflows/ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 420bf1e62..7ae97bcfb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,6 +24,11 @@ jobs: - name: Run tidy run: make tidy + - name: Run formatter + run: | + go install mvdan.cc/gofumpt@86bffd62437a3c437c0b84d5d5ab244824e762fc + gofumpt -l -w . + - name: Fail if changes run: git diff-index --exit-code HEAD From 01e22d6c065799b5dd4ac3ea55eaaf69df1887e1 Mon Sep 17 00:00:00 2001 From: Zhiwei Liang Date: Wed, 22 Jan 2025 18:16:29 -0500 Subject: [PATCH 2/4] Format existing tests --- test/unit/stackscripts_test.go | 34 +++++++++++++++++----------------- test/unit/tag_test.go | 3 --- test/unit/types_test.go | 6 +++--- test/unit/vlan_test.go | 5 +++-- 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/test/unit/stackscripts_test.go b/test/unit/stackscripts_test.go index b6202350b..e2be45b8e 100644 --- a/test/unit/stackscripts_test.go +++ b/test/unit/stackscripts_test.go @@ -5,34 +5,34 @@ import ( "fmt" "testing" - "github.com/stretchr/testify/assert" "github.com/linode/linodego" + "github.com/stretchr/testify/assert" "golang.org/x/exp/slices" ) func TestListStackscripts(t *testing.T) { - // Mock the API response to match the expected structure for a paginated response - fixtureData, err := fixtures.GetFixture("stackscripts_list") - assert.NoError(t, err) + // Mock the API response to match the expected structure for a paginated response + fixtureData, err := fixtures.GetFixture("stackscripts_list") + assert.NoError(t, err) - var base ClientBaseCase - base.SetUp(t) - defer base.TearDown(t) + var base ClientBaseCase + base.SetUp(t) + defer base.TearDown(t) - // Mock the request with a correct paginated structure - base.MockGet("linode/stackscripts", fixtureData) + // Mock the request with a correct paginated structure + base.MockGet("linode/stackscripts", fixtureData) - stackscripts, err := base.Client.ListStackscripts(context.Background(), &linodego.ListOptions{}) - assert.NoError(t, err) + stackscripts, err := base.Client.ListStackscripts(context.Background(), &linodego.ListOptions{}) + assert.NoError(t, err) - assert.NotEmpty(t, stackscripts, "Expected non-empty stackscripts list") + assert.NotEmpty(t, stackscripts, "Expected non-empty stackscripts list") - // Check if a specific stackscript exists using slices.ContainsFunc - exists := slices.ContainsFunc(stackscripts, func(stackscript linodego.Stackscript) bool { - return stackscript.Label == "Test Stackscript" - }) + // Check if a specific stackscript exists using slices.ContainsFunc + exists := slices.ContainsFunc(stackscripts, func(stackscript linodego.Stackscript) bool { + return stackscript.Label == "Test Stackscript" + }) - assert.True(t, exists, "Expected stackscripts list to contain 'Test Stackscript'") + assert.True(t, exists, "Expected stackscripts list to contain 'Test Stackscript'") } func TestCreateStackscript(t *testing.T) { diff --git a/test/unit/tag_test.go b/test/unit/tag_test.go index 3cfaef762..d06cc9e25 100644 --- a/test/unit/tag_test.go +++ b/test/unit/tag_test.go @@ -34,7 +34,6 @@ func TestListTags(t *testing.T) { assert.True(t, exists, "Expected tag list to contain 'example-tag'") } - func TestCreateTag(t *testing.T) { // Load the fixture data for tag creation fixtureData, err := fixtures.GetFixture("tag_create") @@ -57,7 +56,6 @@ func TestCreateTag(t *testing.T) { assert.Equal(t, "new-tag", tag.Label, "Expected created tag label to match input") } - func TestDeleteTag(t *testing.T) { var base ClientBaseCase base.SetUp(t) @@ -98,7 +96,6 @@ func TestListTaggedObjects(t *testing.T) { } } - func TestSortedObjects(t *testing.T) { // Load the fixture data for tagged objects fixtureData, err := fixtures.GetFixture("tagged_objects_list") diff --git a/test/unit/types_test.go b/test/unit/types_test.go index 25e1623cf..b986560da 100644 --- a/test/unit/types_test.go +++ b/test/unit/types_test.go @@ -3,11 +3,11 @@ package unit import ( "context" "fmt" - "github.com/linode/linodego" - "github.com/stretchr/testify/assert" "testing" - "golang.org/x/exp/slices" + "github.com/linode/linodego" + "github.com/stretchr/testify/assert" + "golang.org/x/exp/slices" ) func TestLinodeTypes_List(t *testing.T) { diff --git a/test/unit/vlan_test.go b/test/unit/vlan_test.go index 8fcfd680e..a0ce07032 100644 --- a/test/unit/vlan_test.go +++ b/test/unit/vlan_test.go @@ -3,10 +3,11 @@ package unit import ( "context" "fmt" + "testing" + "github.com/linode/linodego" "github.com/stretchr/testify/assert" - "golang.org/x/exp/slices" - "testing" + "golang.org/x/exp/slices" ) func TestVLAN_List(t *testing.T) { From 4e33db51a2010a16ab91bf09c9d5912e0b1f5785 Mon Sep 17 00:00:00 2001 From: Zhiwei Liang Date: Fri, 7 Feb 2025 04:23:07 -0500 Subject: [PATCH 3/4] gofumpt --- test/unit/domain_test.go | 3 +- test/unit/domainrecord_test.go | 5 ++- test/unit/longview_subscriptions_test.go | 2 +- test/unit/longview_test.go | 2 +- test/unit/mysql_test.go | 3 +- test/unit/postgres_test.go | 3 +- test/unit/volume_test.go | 50 ++++++++++++------------ test/unit/volume_types_test.go | 2 +- 8 files changed, 37 insertions(+), 33 deletions(-) diff --git a/test/unit/domain_test.go b/test/unit/domain_test.go index ec35361e9..f39f9dac8 100644 --- a/test/unit/domain_test.go +++ b/test/unit/domain_test.go @@ -3,9 +3,10 @@ package unit import ( "context" "fmt" - "github.com/jarcoal/httpmock" "testing" + "github.com/jarcoal/httpmock" + "github.com/linode/linodego" "github.com/stretchr/testify/assert" ) diff --git a/test/unit/domainrecord_test.go b/test/unit/domainrecord_test.go index 5739dcbab..86063cfac 100644 --- a/test/unit/domainrecord_test.go +++ b/test/unit/domainrecord_test.go @@ -3,11 +3,12 @@ package unit import ( "context" "fmt" + "testing" + "time" + "github.com/jarcoal/httpmock" "github.com/linode/linodego" "github.com/stretchr/testify/assert" - "testing" - "time" ) func TestDomainRecord_List(t *testing.T) { diff --git a/test/unit/longview_subscriptions_test.go b/test/unit/longview_subscriptions_test.go index 84f305218..bbdf2d1b9 100644 --- a/test/unit/longview_subscriptions_test.go +++ b/test/unit/longview_subscriptions_test.go @@ -4,8 +4,8 @@ import ( "context" "testing" - "github.com/stretchr/testify/assert" "github.com/linode/linodego" + "github.com/stretchr/testify/assert" ) func TestListLongviewSubscriptions(t *testing.T) { diff --git a/test/unit/longview_test.go b/test/unit/longview_test.go index 5e8bd8315..75f51b7d9 100644 --- a/test/unit/longview_test.go +++ b/test/unit/longview_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" - "github.com/stretchr/testify/assert" "github.com/linode/linodego" + "github.com/stretchr/testify/assert" ) func TestListLongviewClients(t *testing.T) { diff --git a/test/unit/mysql_test.go b/test/unit/mysql_test.go index 844de0544..913800d90 100644 --- a/test/unit/mysql_test.go +++ b/test/unit/mysql_test.go @@ -2,9 +2,10 @@ package unit import ( "context" - "github.com/jarcoal/httpmock" "testing" + "github.com/jarcoal/httpmock" + "github.com/linode/linodego" "github.com/stretchr/testify/assert" ) diff --git a/test/unit/postgres_test.go b/test/unit/postgres_test.go index 011c45af5..6fdda8ce5 100644 --- a/test/unit/postgres_test.go +++ b/test/unit/postgres_test.go @@ -2,10 +2,11 @@ package unit import ( "context" + "testing" + "github.com/jarcoal/httpmock" "github.com/linode/linodego" "github.com/stretchr/testify/assert" - "testing" ) func TestListDatabasePostgreSQL_List(t *testing.T) { diff --git a/test/unit/volume_test.go b/test/unit/volume_test.go index 74fda3441..2b1641f8e 100644 --- a/test/unit/volume_test.go +++ b/test/unit/volume_test.go @@ -5,8 +5,8 @@ import ( "fmt" "testing" - "github.com/stretchr/testify/assert" "github.com/linode/linodego" + "github.com/stretchr/testify/assert" ) func TestListVolumes(t *testing.T) { @@ -128,30 +128,30 @@ func TestDeleteVolume(t *testing.T) { } func TestAttachVolume(t *testing.T) { - // Mock the API response for attaching a volume - fixtureData, err := fixtures.GetFixture("volume_attach") - assert.NoError(t, err) - - var base ClientBaseCase - base.SetUp(t) - defer base.TearDown(t) - - volumeID := 123 - base.MockPost(fmt.Sprintf("volumes/%d/attach", volumeID), fixtureData) - - // Use direct pointer assignment for PersistAcrossBoots - persistAcrossBoots := true - opts := &linodego.VolumeAttachOptions{ - LinodeID: 456, - PersistAcrossBoots: &persistAcrossBoots, - } - - attachedVolume, err := base.Client.AttachVolume(context.Background(), volumeID, opts) - assert.NoError(t, err, "Expected no error when attaching volume") - - // Verify the attached volume's LinodeID and filesystem path - assert.Equal(t, 456, *attachedVolume.LinodeID, "Expected LinodeID to match input") - assert.Equal(t, "/dev/disk/by-id/volume-123", attachedVolume.FilesystemPath, "Expected filesystem path to match fixture") + // Mock the API response for attaching a volume + fixtureData, err := fixtures.GetFixture("volume_attach") + assert.NoError(t, err) + + var base ClientBaseCase + base.SetUp(t) + defer base.TearDown(t) + + volumeID := 123 + base.MockPost(fmt.Sprintf("volumes/%d/attach", volumeID), fixtureData) + + // Use direct pointer assignment for PersistAcrossBoots + persistAcrossBoots := true + opts := &linodego.VolumeAttachOptions{ + LinodeID: 456, + PersistAcrossBoots: &persistAcrossBoots, + } + + attachedVolume, err := base.Client.AttachVolume(context.Background(), volumeID, opts) + assert.NoError(t, err, "Expected no error when attaching volume") + + // Verify the attached volume's LinodeID and filesystem path + assert.Equal(t, 456, *attachedVolume.LinodeID, "Expected LinodeID to match input") + assert.Equal(t, "/dev/disk/by-id/volume-123", attachedVolume.FilesystemPath, "Expected filesystem path to match fixture") } func TestDetachVolume(t *testing.T) { diff --git a/test/unit/volume_types_test.go b/test/unit/volume_types_test.go index 13240d6f9..da2b88b1c 100644 --- a/test/unit/volume_types_test.go +++ b/test/unit/volume_types_test.go @@ -4,8 +4,8 @@ import ( "context" "testing" - "github.com/stretchr/testify/assert" "github.com/linode/linodego" + "github.com/stretchr/testify/assert" ) func TestListVolumeTypes(t *testing.T) { From e3168986e2ebf9fe4d904dd1964d3933332e688c Mon Sep 17 00:00:00 2001 From: Zhiwei Liang Date: Mon, 10 Feb 2025 13:54:10 -0500 Subject: [PATCH 4/4] gofumpt --- test/integration/lke_clusters_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/integration/lke_clusters_test.go b/test/integration/lke_clusters_test.go index d2c0537db..24d8ca935 100644 --- a/test/integration/lke_clusters_test.go +++ b/test/integration/lke_clusters_test.go @@ -343,7 +343,8 @@ func TestLKECluster_APLEnabled_smoke(t *testing.T) { func(createOpts *linodego.LKEClusterCreateOptions) { // NOTE: g6-dedicated-4 is the minimum APL-compatible Linode type createOpts.NodePools = []linodego.LKENodePoolCreateOptions{{Count: 3, Type: "g6-dedicated-4", Tags: []string{"test"}}} - }}, + }, + }, "fixtures/TestLKECluster_APLEnabled") defer teardown()