Skip to content

Commit

Permalink
Enforce code format for tests (#660)
Browse files Browse the repository at this point in the history
* Enforce code format including tests

* Format existing tests

* gofumpt

* gofumpt
  • Loading branch information
zliang-akamai authored Feb 10, 2025
1 parent c5cc32a commit a35570e
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 59 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion test/integration/lke_clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
3 changes: 2 additions & 1 deletion test/unit/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
5 changes: 3 additions & 2 deletions test/unit/domainrecord_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/longview_subscriptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/longview_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion test/unit/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
3 changes: 2 additions & 1 deletion test/unit/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
34 changes: 17 additions & 17 deletions test/unit/stackscripts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 0 additions & 3 deletions test/unit/tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions test/unit/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions test/unit/vlan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
50 changes: 25 additions & 25 deletions test/unit/volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/volume_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit a35570e

Please sign in to comment.