Skip to content

Commit

Permalink
Add ci job for unit tests (#1532)
Browse files Browse the repository at this point in the history
Rename all unit tests to contain `Unit` and add a ci job
that runs all unit tests.
  • Loading branch information
nikParasyr committed Apr 13, 2023
1 parent b39cfc5 commit 38087d5
Show file tree
Hide file tree
Showing 39 changed files with 172 additions and 99 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Unit Testing
on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go-version:
- "1.20"

env:
GO111MODULE: "on"

steps:
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}

- uses: actions/checkout@v3

- name: Run go vet
run: |
go vet ./...
- name: Run unit tests
run: |
./scripts/unittest.sh
4 changes: 2 additions & 2 deletions openstack/blockstorage_extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func blockStorageExtensionsSchedulerHints() schedulerhints.SchedulerHints {
}
}

func TestFlattenBlockStorageExtensionsSchedulerHints(t *testing.T) {
func TestUnitFlattenBlockStorageExtensionsSchedulerHints(t *testing.T) {
expectedSchedulerHints := map[string]interface{}{
"same_host": []interface{}{"83ec2e3b-4321-422b-8706-a84185f52a0a"},
"different_host": []interface{}{"83ec2e3b-4321-422b-8706-a84185f52a0a"},
Expand All @@ -31,7 +31,7 @@ func TestFlattenBlockStorageExtensionsSchedulerHints(t *testing.T) {
assert.Equal(t, expectedSchedulerHints, actualSchedulerHints)
}

func TestBlockStorageExtensionsSchedulerHintsHash(t *testing.T) {
func TestUnitBlockStorageExtensionsSchedulerHintsHash(t *testing.T) {
s := expandBlockStorageExtensionsSchedulerHints(blockStorageExtensionsSchedulerHints())

expectedHashcode := 1530836638
Expand Down
6 changes: 3 additions & 3 deletions openstack/blockstorage_quotaset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
)

func TestBlockStorageVolumeTypeQuotaConversion(t *testing.T) {
func TestUnitBlockStorageVolumeTypeQuotaConversion(t *testing.T) {
raw := map[string]interface{}{
"foo": "42",
"bar": "43",
Expand All @@ -27,7 +27,7 @@ func TestBlockStorageVolumeTypeQuotaConversion(t *testing.T) {
}
}

func TestBlockStorageVolumeTypeQuotaConversion_err(t *testing.T) {
func TestUnitBlockStorageVolumeTypeQuotaConversion_err(t *testing.T) {
raw := map[string]interface{}{
"foo": 100,
"bar": 200,
Expand All @@ -40,7 +40,7 @@ func TestBlockStorageVolumeTypeQuotaConversion_err(t *testing.T) {
}
}

func TestBlockStorageVolumeTypeQuotaConversion_err2(t *testing.T) {
func TestUnitBlockStorageVolumeTypeQuotaConversion_err2(t *testing.T) {
raw := map[string]interface{}{
"foo": "foo",
"bar": "bar",
Expand Down
4 changes: 2 additions & 2 deletions openstack/blockstorage_volume_attach_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import (
"github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/volumeactions"
)

func TestExpandBlockStorageV2AttachMode(t *testing.T) {
func TestUnitExpandBlockStorageV2AttachMode(t *testing.T) {
expected := volumeactions.ReadWrite

actual, err := expandBlockStorageV2AttachMode("rw")
assert.Equal(t, err, nil)
assert.Equal(t, expected, actual)
}

func TestBlockStorageVolumeAttachV2ParseID(t *testing.T) {
func TestUnitBlockStorageVolumeAttachV2ParseID(t *testing.T) {
id := "foo/bar"

expectedVolumeID := "foo"
Expand Down
4 changes: 2 additions & 2 deletions openstack/blockstorage_volume_attach_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import (
"github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/volumeactions"
)

func TestExpandBlockStorageV3AttachMode(t *testing.T) {
func TestUnitExpandBlockStorageV3AttachMode(t *testing.T) {
expected := volumeactions.ReadWrite

actual, err := expandBlockStorageV3AttachMode("rw")
assert.Equal(t, err, nil)
assert.Equal(t, expected, actual)
}

func TestBlockStorageVolumeAttachV3ParseID(t *testing.T) {
func TestUnitBlockStorageVolumeAttachV3ParseID(t *testing.T) {
id := "foo/bar"

expectedVolumeID := "foo"
Expand Down
2 changes: 1 addition & 1 deletion openstack/blockstorage_volume_type_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumetypes"
)

func TestExpandBlockStorageVolumeTypeV3ExtraSpecs(t *testing.T) {
func TestUnitExpandBlockStorageVolumeTypeV3ExtraSpecs(t *testing.T) {
raw := map[string]interface{}{
"foo": "foo",
"bar": "bar",
Expand Down
4 changes: 2 additions & 2 deletions openstack/blockstorage_volume_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func blockStorageVolumeV1VolumeFixture() *volumes.Volume {
}
}

func TestFlattenBlockStorageVolumeV1Attachments(t *testing.T) {
func TestUnitFlattenBlockStorageVolumeV1Attachments(t *testing.T) {
expectedAttachments := []map[string]interface{}{
{
"id": "47e9ecc5-4045-4ee3-9a4b-d859d546a0cf",
Expand All @@ -51,7 +51,7 @@ func TestFlattenBlockStorageVolumeV1Attachments(t *testing.T) {
assert.Equal(t, expectedAttachments, actualAttachments)
}

func TestBlockStorageVolumeV1AttachmentHash(t *testing.T) {
func TestUnitBlockStorageVolumeV1AttachmentHash(t *testing.T) {
attachments := flattenBlockStorageVolumeV1Attachments(blockStorageVolumeV1VolumeFixture().Attachments)

expectedHashcode := 258823884
Expand Down
4 changes: 2 additions & 2 deletions openstack/blockstorage_volume_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func blockStorageVolumeV2VolumeFixture() volumes.Volume {
}
}

func TestFlattenBlockStorageVolumeV2Attachments(t *testing.T) {
func TestUnitFlattenBlockStorageVolumeV2Attachments(t *testing.T) {
expectedAttachments := []map[string]interface{}{
{
"id": "d6cacb1a-8b59-4c88-ad90-d70ebb82bb75",
Expand All @@ -53,7 +53,7 @@ func TestFlattenBlockStorageVolumeV2Attachments(t *testing.T) {
assert.Equal(t, expectedAttachments, actualAttachments)
}

func TestBlockStorageVolumeV2AttachmentHash(t *testing.T) {
func TestUnitBlockStorageVolumeV2AttachmentHash(t *testing.T) {
attachments := flattenBlockStorageVolumeV2Attachments(blockStorageVolumeV2VolumeFixture().Attachments)

expectedHashcode := 236219624
Expand Down
4 changes: 2 additions & 2 deletions openstack/blockstorage_volume_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func blockStorageVolumeV3VolumeFixture() volumes.Volume {
}
}

func TestFlattenBlockStorageVolumeV3Attachments(t *testing.T) {
func TestUnitFlattenBlockStorageVolumeV3Attachments(t *testing.T) {
expectedAttachments := []map[string]interface{}{
{
"id": "d6cacb1a-8b59-4c88-ad90-d70ebb82bb75",
Expand All @@ -53,7 +53,7 @@ func TestFlattenBlockStorageVolumeV3Attachments(t *testing.T) {
assert.Equal(t, expectedAttachments, actualAttachments)
}

func TestBlockStorageVolumeV3AttachmentHash(t *testing.T) {
func TestUnitBlockStorageVolumeV3AttachmentHash(t *testing.T) {
attachments := flattenBlockStorageVolumeV3Attachments(blockStorageVolumeV3VolumeFixture().Attachments)

expectedHashcode := 236219624
Expand Down
2 changes: 1 addition & 1 deletion openstack/compute_flavor_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/gophercloud/gophercloud/openstack/compute/v2/flavors"
)

func TestExpandComputeFlavorV2ExtraSpecs(t *testing.T) {
func TestUnitExpandComputeFlavorV2ExtraSpecs(t *testing.T) {
raw := map[string]interface{}{
"foo": "bar",
"bar": "baz",
Expand Down
2 changes: 1 addition & 1 deletion openstack/compute_interface_attach_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/assert"
)

func TestComputeInterfaceAttachV2ParseID(t *testing.T) {
func TestUnitComputeInterfaceAttachV2ParseID(t *testing.T) {
id := "foo/bar"

expectedInstanceID := "foo"
Expand Down
2 changes: 1 addition & 1 deletion openstack/compute_keypair_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs"
)

func TestComputeKeyPairV2CreateOpts(t *testing.T) {
func TestUnitComputeKeyPairV2CreateOpts(t *testing.T) {
createOpts := ComputeKeyPairV2CreateOpts{
keypairs.CreateOpts{
Name: "kp_1",
Expand Down
4 changes: 2 additions & 2 deletions openstack/compute_secgroup_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups"
)

func TestExpandComputeSecGroupV2CreateRules(t *testing.T) {
func TestUnitExpandComputeSecGroupV2CreateRules(t *testing.T) {
r := resourceComputeSecGroupV2()
d := r.TestResourceData()
d.SetId("1")
Expand Down Expand Up @@ -69,7 +69,7 @@ func TestExpandComputeSecGroupV2CreateRules(t *testing.T) {
}
}

func TestExpandComputeSecGroupV2Rule(t *testing.T) {
func TestUnitExpandComputeSecGroupV2Rule(t *testing.T) {
r := resourceComputeSecGroupV2()
d := r.TestResourceData()
d.SetId("1")
Expand Down
6 changes: 3 additions & 3 deletions openstack/compute_servergroup_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
thclient "github.com/gophercloud/gophercloud/testhelper/client"
)

func TestComputeServerGroupV2CreateOpts(t *testing.T) {
func TestUnitComputeServerGroupV2CreateOpts(t *testing.T) {
createOpts := ComputeServerGroupV2CreateOpts{
servergroups.CreateOpts{
Name: "foo",
Expand All @@ -35,7 +35,7 @@ func TestComputeServerGroupV2CreateOpts(t *testing.T) {
assert.Equal(t, expected, actual)
}

func TestExpandComputeServerGroupV2PoliciesMicroversions(t *testing.T) {
func TestUnitExpandComputeServerGroupV2PoliciesMicroversions(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
raw := []interface{}{
Expand All @@ -61,7 +61,7 @@ func TestExpandComputeServerGroupV2PoliciesMicroversions(t *testing.T) {
assert.Equal(t, expectedPolicies, actualPolicies)
}

func TestExpandComputeServerGroupV2PoliciesMicroversionsLegacy(t *testing.T) {
func TestUnitExpandComputeServerGroupV2PoliciesMicroversionsLegacy(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
raw := []interface{}{
Expand Down
2 changes: 1 addition & 1 deletion openstack/compute_volume_attach_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package openstack

import "testing"

func TestComputeVolumeAttachV2ParseID(t *testing.T) {
func TestUnitComputeVolumeAttachV2ParseID(t *testing.T) {
id := "foo/bar"

expectedInstanceID := "foo"
Expand Down
6 changes: 3 additions & 3 deletions openstack/containerinfra_shared_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates"
)

func TestExpandContainerInfraV1LabelsMap(t *testing.T) {
func TestUnitExpandContainerInfraV1LabelsMap(t *testing.T) {
labels := map[string]interface{}{
"foo": "bar",
"bar": "baz",
Expand All @@ -24,7 +24,7 @@ func TestExpandContainerInfraV1LabelsMap(t *testing.T) {
assert.Equal(t, expectedLabels, actualLabels)
}

func TestExpandContainerInfraV1LabelsString(t *testing.T) {
func TestUnitExpandContainerInfraV1LabelsString(t *testing.T) {
labels := map[string]interface{}{
"foo": "bar",
"bar": "baz",
Expand All @@ -42,7 +42,7 @@ func TestExpandContainerInfraV1LabelsString(t *testing.T) {
}
}

func TestContainerInfraClusterTemplateV1AppendUpdateOpts(t *testing.T) {
func TestUnitContainerInfraClusterTemplateV1AppendUpdateOpts(t *testing.T) {
actualUpdateOpts := []clustertemplates.UpdateOptsBuilder{}

expectedUpdateOpts := []clustertemplates.UpdateOptsBuilder{
Expand Down
4 changes: 2 additions & 2 deletions openstack/db_configuration_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/gophercloud/gophercloud/openstack/db/v1/configurations"
)

func TestExpandDatabaseConfigurationV1Datastore(t *testing.T) {
func TestUnitExpandDatabaseConfigurationV1Datastore(t *testing.T) {
datastore := []interface{}{
map[string]interface{}{
"version": "foo",
Expand All @@ -25,7 +25,7 @@ func TestExpandDatabaseConfigurationV1Datastore(t *testing.T) {
assert.Equal(t, expected, actual)
}

func TestExpandDatabaseConfigurationV1Values(t *testing.T) {
func TestUnitExpandDatabaseConfigurationV1Values(t *testing.T) {
values := []interface{}{
map[string]interface{}{
"name": "collation_server",
Expand Down
8 changes: 4 additions & 4 deletions openstack/db_instance_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/gophercloud/gophercloud/openstack/db/v1/users"
)

func TestExpandDatabaseInstanceV1Datastore(t *testing.T) {
func TestUnitExpandDatabaseInstanceV1Datastore(t *testing.T) {
datastore := []interface{}{
map[string]interface{}{
"version": "foo",
Expand All @@ -28,7 +28,7 @@ func TestExpandDatabaseInstanceV1Datastore(t *testing.T) {
assert.Equal(t, expected, actual)
}

func TestExpandDatabaseInstanceV1Networks(t *testing.T) {
func TestUnitExpandDatabaseInstanceV1Networks(t *testing.T) {
network := []interface{}{
map[string]interface{}{
"uuid": "foobar",
Expand All @@ -48,7 +48,7 @@ func TestExpandDatabaseInstanceV1Networks(t *testing.T) {
assert.Equal(t, expected, actual)
}

func TestExpandDatabaseInstanceV1Databases(t *testing.T) {
func TestUnitExpandDatabaseInstanceV1Databases(t *testing.T) {
dbs := []interface{}{
map[string]interface{}{
"name": "testdb1",
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestExpandDatabaseInstanceV1Databases(t *testing.T) {
assert.Equal(t, expected, actual)
}

func TestExpandDatabaseInstanceV1Users(t *testing.T) {
func TestUnitExpandDatabaseInstanceV1Users(t *testing.T) {
userList := []interface{}{
map[string]interface{}{
"name": "testuser",
Expand Down
4 changes: 2 additions & 2 deletions openstack/db_user_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/gophercloud/gophercloud/openstack/db/v1/databases"
)

func TestExpandDatabaseUserV1Databases(t *testing.T) {
func TestUnitExpandDatabaseUserV1Databases(t *testing.T) {
dbs := []interface{}{"db1", "db2"}

expected := databases.BatchCreateOpts{
Expand All @@ -24,7 +24,7 @@ func TestExpandDatabaseUserV1Databases(t *testing.T) {
assert.Equal(t, expected, actual)
}

func TestFlattenDatabaseUserV1Databases(t *testing.T) {
func TestUnitFlattenDatabaseUserV1Databases(t *testing.T) {
dbs := []databases.Database{
{
Name: "db1",
Expand Down
4 changes: 2 additions & 2 deletions openstack/dns_recordset_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/assert"
)

func TestDNSRecordSetV2ParseID(t *testing.T) {
func TestUnitDNSRecordSetV2ParseID(t *testing.T) {
id := "foo/bar"
expectedZoneID := "foo"
expectedRecordSetID := "bar"
Expand All @@ -17,7 +17,7 @@ func TestDNSRecordSetV2ParseID(t *testing.T) {
assert.Equal(t, expectedRecordSetID, actualRecordSetID)
}

func TestDNSRecordSetV2RecordsStateFunc(t *testing.T) {
func TestUnitDNSRecordSetV2RecordsStateFunc(t *testing.T) {
data := []interface{}{"foo", "[bar]", "baz"}
expected := []string{"foo", "bar", "baz"}

Expand Down
4 changes: 2 additions & 2 deletions openstack/fw_rule_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/rules"
)

func TestExpandFWRuleV1IPVersion(t *testing.T) {
func TestUnitExpandFWRuleV1IPVersion(t *testing.T) {
ipv := 4

expected := gophercloud.IPv4
actual := expandFWRuleV1IPVersion(ipv)
assert.Equal(t, expected, actual)
}

func TestExpandFWRuleV1Protocol(t *testing.T) {
func TestUnitExpandFWRuleV1Protocol(t *testing.T) {
proto := "tcp"

expected := rules.ProtocolTCP
Expand Down
Loading

0 comments on commit 38087d5

Please sign in to comment.