diff --git a/internal/cloud/aws_dto_test.go b/internal/cloud/aws_dto_test.go index 9cbf241e..5bcd29c0 100644 --- a/internal/cloud/aws_dto_test.go +++ b/internal/cloud/aws_dto_test.go @@ -3,10 +3,18 @@ package cloud import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" ) -func TestNewAwsMetadataDto(t *testing.T) { +type AwsMetadataDtoTestSuite struct { + suite.Suite +} + +func TestAwsMetadataDtoTestSuite(t *testing.T) { + suite.Run(t, new(AwsMetadataDtoTestSuite)) +} + +func (suite *AwsMetadataDtoTestSuite) TestNewAwsMetadataDto() { awsMetadata := &AwsMetadata{ //nolint AmiID: "some-ami", @@ -41,5 +49,5 @@ func TestNewAwsMetadataDto(t *testing.T) { Region: "some-region", VpcID: "some-vpc-id", } - assert.Equal(t, expectedDto, awsMetadataDto) + suite.Equal(expectedDto, awsMetadataDto) } diff --git a/internal/cloud/aws_test.go b/internal/cloud/aws_test.go index 2345aded..9bda88fd 100644 --- a/internal/cloud/aws_test.go +++ b/internal/cloud/aws_test.go @@ -8,12 +8,20 @@ import ( "path" "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/suite" "github.com/trento-project/agent/internal/cloud/mocks" ) -func TestNewAwsMetadata(t *testing.T) { +type AwsMetadataTestSuite struct { + suite.Suite +} + +func TestAwsMetadataTestSuite(t *testing.T) { + suite.Run(t, new(AwsMetadataTestSuite)) +} + +func (suite *AwsMetadataTestSuite) TestNewAwsMetadata() { clientMock := new(mocks.HTTPClient) fixtures := []string{ @@ -59,18 +67,18 @@ func TestNewAwsMetadata(t *testing.T) { m, err := NewAwsMetadata() - assert.NoError(t, err) + suite.NoError(err) - assert.Equal(t, "some-ami-id", m.AmiID) - assert.Equal(t, map[string]string{ + suite.Equal("some-ami-id", m.AmiID) + suite.Equal(map[string]string{ "root": "/dev/sda", "ebs1": "/dev/sdb1", "ebs2": "/dev/sdb2", }, m.BlockDeviceMapping) - assert.Equal(t, "some-instance", m.InstanceID) - assert.Equal(t, "some-instance-type", m.InstanceType) - assert.Equal(t, "some-account-id", m.IdentityCredentials.EC2.Info.AccountID) - assert.Equal(t, "some-vpc-id", m.Network.Interfaces.Macs["some-mac"].VpcID) - assert.Equal(t, "some-availability-zone", m.Placement.AvailabilityZone) - assert.Equal(t, "some-region", m.Placement.Region) + suite.Equal("some-instance", m.InstanceID) + suite.Equal("some-instance-type", m.InstanceType) + suite.Equal("some-account-id", m.IdentityCredentials.EC2.Info.AccountID) + suite.Equal("some-vpc-id", m.Network.Interfaces.Macs["some-mac"].VpcID) + suite.Equal("some-availability-zone", m.Placement.AvailabilityZone) + suite.Equal("some-region", m.Placement.Region) } diff --git a/internal/cloud/azure_test.go b/internal/cloud/azure_test.go index 7c42df3e..be146433 100644 --- a/internal/cloud/azure_test.go +++ b/internal/cloud/azure_test.go @@ -8,12 +8,20 @@ import ( "os" "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/suite" "github.com/trento-project/agent/internal/cloud/mocks" ) -func TestNewAzureMetadata(t *testing.T) { +type AzureMetadataTestSuite struct { + suite.Suite +} + +func TestAzureMetadataTestSuite(t *testing.T) { + suite.Run(t, new(AzureMetadataTestSuite)) +} + +func (suite *AzureMetadataTestSuite) TestNewAzureMetadata() { clientMock := new(mocks.HTTPClient) aFile, _ := os.Open("../../test/fixtures/discovery/azure/azure_metadata.json") @@ -187,21 +195,21 @@ func TestNewAzureMetadata(t *testing.T) { }, } - assert.Equal(t, expectedMeta, m) - assert.NoError(t, err) + suite.Equal(expectedMeta, m) + suite.NoError(err) } -func TestGetVmUrl(t *testing.T) { +func (suite *AzureMetadataTestSuite) TestGetVmUrl() { meta := &AzureMetadata{ //nolint Compute: Compute{ //nolint ResourceID: "myresourceid", }, } - assert.Equal(t, "https:/portal.azure.com/#@SUSERDBillingsuse.onmicrosoft.com/resource/myresourceid", meta.GetVMURL()) + suite.Equal("https:/portal.azure.com/#@SUSERDBillingsuse.onmicrosoft.com/resource/myresourceid", meta.GetVMURL()) } -func TestGetResourceGroupUrl(t *testing.T) { +func (suite *AzureMetadataTestSuite) TestGetResourceGroupUrl() { meta := &AzureMetadata{ //nolint Compute: Compute{ //nolint SubscriptionID: "xxx", @@ -209,5 +217,5 @@ func TestGetResourceGroupUrl(t *testing.T) { }, } - assert.Equal(t, "https:/portal.azure.com/#@SUSERDBillingsuse.onmicrosoft.com/resource/subscriptions/xxx/resourceGroups/myresourcegroupname/overview", meta.GetResourceGroupURL()) + suite.Equal("https:/portal.azure.com/#@SUSERDBillingsuse.onmicrosoft.com/resource/subscriptions/xxx/resourceGroups/myresourcegroupname/overview", meta.GetResourceGroupURL()) } diff --git a/internal/cloud/gcp_dto_test.go b/internal/cloud/gcp_dto_test.go index 6dc805d5..aabc8aac 100644 --- a/internal/cloud/gcp_dto_test.go +++ b/internal/cloud/gcp_dto_test.go @@ -3,10 +3,18 @@ package cloud import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" ) -func TestNewGcpMetadataDto(t *testing.T) { +type GcpMetadataDtoTestSuite struct { + suite.Suite +} + +func TestGcpMetadataDtoTestSuite(t *testing.T) { + suite.Run(t, new(GcpMetadataDtoTestSuite)) +} + +func (suite *GcpMetadataDtoTestSuite) TestNewGcpMetadataDto() { gcpMetadata := &GcpMetadata{ Instance: GcpInstance{ @@ -54,5 +62,5 @@ func TestNewGcpMetadataDto(t *testing.T) { ProjectID: "some-project-id", Zone: "europe-west1-b", } - assert.Equal(t, expectedDto, gcpMetadataDto) + suite.Equal(expectedDto, gcpMetadataDto) } diff --git a/internal/cloud/gcp_test.go b/internal/cloud/gcp_test.go index 2d7ac8e0..e6ee6262 100644 --- a/internal/cloud/gcp_test.go +++ b/internal/cloud/gcp_test.go @@ -7,12 +7,20 @@ import ( "os" "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/suite" "github.com/trento-project/agent/internal/cloud/mocks" ) -func TestNewGcpMetadata(t *testing.T) { +type GcpMetadataTestSuite struct { + suite.Suite +} + +func TestGcpMetadataTestSuite(t *testing.T) { + suite.Run(t, new(GcpMetadataTestSuite)) +} + +func (suite *GcpMetadataTestSuite) TestNewGcpMetadata() { clientMock := new(mocks.HTTPClient) aFile, _ := os.Open("../../test/fixtures/discovery/gcp/gcp_metadata.json") @@ -67,6 +75,6 @@ func TestNewGcpMetadata(t *testing.T) { }, } - assert.Equal(t, expectedMeta, m) - assert.NoError(t, err) + suite.Equal(expectedMeta, m) + suite.NoError(err) } diff --git a/internal/cloud/metadata_test.go b/internal/cloud/metadata_test.go index d0031b4d..6da970b2 100644 --- a/internal/cloud/metadata_test.go +++ b/internal/cloud/metadata_test.go @@ -7,16 +7,24 @@ import ( "os/exec" "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/suite" "github.com/trento-project/agent/internal/cloud/mocks" ) +type CloudMetadataTestSuite struct { + suite.Suite +} + +func TestCloudMetadataTestSuite(t *testing.T) { + suite.Run(t, new(CloudMetadataTestSuite)) +} + func mockDmidecodeErr() *exec.Cmd { return exec.Command("error") } -func TestIdentifyCloudProviderErr(t *testing.T) { +func (suite *CloudMetadataTestSuite) TestIdentifyCloudProviderErr() { mockCommand := new(mocks.CustomCommand) customExecCommand = mockCommand.Execute @@ -27,15 +35,15 @@ func TestIdentifyCloudProviderErr(t *testing.T) { provider, err := IdentifyCloudProvider() - assert.Equal(t, "", provider) - assert.EqualError(t, err, "exec: \"error\": executable file not found in $PATH") + suite.Equal("", provider) + suite.EqualError(err, "exec: \"error\": executable file not found in $PATH") } func mockDmidecodeAzure() *exec.Cmd { return exec.Command("echo", "7783-7084-3265-9085-8269-3286-77") } -func TestIdentifyCloudProviderAzure(t *testing.T) { +func (suite *CloudMetadataTestSuite) TestIdentifyCloudProviderAzure() { mockCommand := new(mocks.CustomCommand) customExecCommand = mockCommand.Execute @@ -46,8 +54,8 @@ func TestIdentifyCloudProviderAzure(t *testing.T) { provider, err := IdentifyCloudProvider() - assert.Equal(t, "azure", provider) - assert.NoError(t, err) + suite.Equal("azure", provider) + suite.NoError(err) } func mockDmidecodeAwsSystem() *exec.Cmd { @@ -58,7 +66,7 @@ func mockDmidecodeAwsManufacturer() *exec.Cmd { return exec.Command("echo", "Amazon EC2") } -func TestIdentifyCloudProviderAwsUsingSystemVersion(t *testing.T) { +func (suite *CloudMetadataTestSuite) TestIdentifyCloudProviderAwsUsingSystemVersion() { mockCommand := new(mocks.CustomCommand) customExecCommand = mockCommand.Execute @@ -73,11 +81,11 @@ func TestIdentifyCloudProviderAwsUsingSystemVersion(t *testing.T) { provider, err := IdentifyCloudProvider() - assert.Equal(t, "aws", provider) - assert.NoError(t, err) + suite.Equal("aws", provider) + suite.NoError(err) } -func TestIdentifyCloudProviderAwsUsingManufacturer(t *testing.T) { +func (suite *CloudMetadataTestSuite) TestIdentifyCloudProviderAwsUsingManufacturer() { mockCommand := new(mocks.CustomCommand) customExecCommand = mockCommand.Execute @@ -96,15 +104,15 @@ func TestIdentifyCloudProviderAwsUsingManufacturer(t *testing.T) { provider, err := IdentifyCloudProvider() - assert.Equal(t, "aws", provider) - assert.NoError(t, err) + suite.Equal("aws", provider) + suite.NoError(err) } func mockDmidecodeGcp() *exec.Cmd { return exec.Command("echo", "Google") } -func TestIdentifyCloudProviderGcp(t *testing.T) { +func (suite *CloudMetadataTestSuite) TestIdentifyCloudProviderGcp() { mockCommand := new(mocks.CustomCommand) customExecCommand = mockCommand.Execute @@ -127,15 +135,15 @@ func TestIdentifyCloudProviderGcp(t *testing.T) { provider, err := IdentifyCloudProvider() - assert.Equal(t, "gcp", provider) - assert.NoError(t, err) + suite.Equal("gcp", provider) + suite.NoError(err) } func mockDmidecodeNoCloud() *exec.Cmd { return exec.Command("echo", "") } -func TestIdentifyCloudProviderNoCloud(t *testing.T) { +func (suite *CloudMetadataTestSuite) TestIdentifyCloudProviderNoCloud() { mockCommand := new(mocks.CustomCommand) customExecCommand = mockCommand.Execute @@ -158,11 +166,11 @@ func TestIdentifyCloudProviderNoCloud(t *testing.T) { provider, err := IdentifyCloudProvider() - assert.Equal(t, "", provider) - assert.NoError(t, err) + suite.Equal("", provider) + suite.NoError(err) } -func TestNewCloudInstanceAzure(t *testing.T) { +func (suite *CloudMetadataTestSuite) TestNewCloudInstanceAzure() { mockCommand := new(mocks.CustomCommand) customExecCommand = mockCommand.Execute @@ -188,14 +196,14 @@ func TestNewCloudInstanceAzure(t *testing.T) { c, err := NewCloudInstance() - assert.NoError(t, err) - assert.Equal(t, "azure", c.Provider) + suite.NoError(err) + suite.Equal("azure", c.Provider) meta, ok := c.Metadata.(*AzureMetadata) - assert.True(t, ok) - assert.Equal(t, "test", meta.Compute.Name) + suite.True(ok) + suite.Equal("test", meta.Compute.Name) } -func TestNewCloudInstanceAws(t *testing.T) { +func (suite *CloudMetadataTestSuite) TestNewCloudInstanceAws() { mockCommand := new(mocks.CustomCommand) customExecCommand = mockCommand.Execute @@ -235,14 +243,14 @@ func TestNewCloudInstanceAws(t *testing.T) { c, err := NewCloudInstance() - assert.NoError(t, err) - assert.Equal(t, "aws", c.Provider) + suite.NoError(err) + suite.Equal("aws", c.Provider) meta, ok := c.Metadata.(*AwsMetadataDto) - assert.True(t, ok) - assert.Equal(t, "some-id", meta.InstanceID) + suite.True(ok) + suite.Equal("some-id", meta.InstanceID) } -func TestNewCloudInstanceNoCloud(t *testing.T) { +func (suite *CloudMetadataTestSuite) TestNewCloudInstanceNoCloud() { mockCommand := new(mocks.CustomCommand) customExecCommand = mockCommand.Execute @@ -265,7 +273,7 @@ func TestNewCloudInstanceNoCloud(t *testing.T) { c, err := NewCloudInstance() - assert.NoError(t, err) - assert.Equal(t, "", c.Provider) - assert.Equal(t, interface{}(nil), c.Metadata) + suite.NoError(err) + suite.Equal("", c.Provider) + suite.Equal(interface{}(nil), c.Metadata) } diff --git a/internal/cluster/cib/parser_test.go b/internal/cluster/cib/parser_test.go index c42204e4..3c114364 100644 --- a/internal/cluster/cib/parser_test.go +++ b/internal/cluster/cib/parser_test.go @@ -4,72 +4,80 @@ package cib import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" ) -func TestConstructor(t *testing.T) { +type ParserTestSuite struct { + suite.Suite +} + +func TestParserTestSuite(t *testing.T) { + suite.Run(t, new(ParserTestSuite)) +} + +func (suite *ParserTestSuite) TestConstructor() { p := NewCibAdminParser("foo") - assert.Equal(t, "foo", p.cibAdminPath) + suite.Equal("foo", p.cibAdminPath) } -func TestParse(t *testing.T) { +func (suite *ParserTestSuite) TestParse() { p := NewCibAdminParser("../../../test/fake_cibadmin.sh") data, err := p.Parse() - assert.NoError(t, err) - assert.Equal(t, 2, len(data.Configuration.Nodes)) - assert.Equal(t, "cib-bootstrap-options-cluster-name", data.Configuration.CrmConfig.ClusterProperties[3].ID) - assert.Equal(t, "hana_cluster", data.Configuration.CrmConfig.ClusterProperties[3].Value) - assert.Equal(t, "node01", data.Configuration.Nodes[0].Uname) - assert.Equal(t, "node02", data.Configuration.Nodes[1].Uname) - assert.Equal(t, 4, len(data.Configuration.Resources.Primitives)) - assert.Equal(t, 1, len(data.Configuration.Resources.Masters)) - assert.Equal(t, 1, len(data.Configuration.Resources.Clones)) - assert.Equal(t, "stonith-sbd", data.Configuration.Resources.Primitives[0].ID) - assert.Equal(t, "stonith", data.Configuration.Resources.Primitives[0].Class) - assert.Equal(t, "external/sbd", data.Configuration.Resources.Primitives[0].Type) - assert.Equal(t, 1, len(data.Configuration.Resources.Primitives[0].InstanceAttributes)) - assert.Equal(t, "pcmk_delay_max", data.Configuration.Resources.Primitives[0].InstanceAttributes[0].Name) - assert.Equal(t, "stonith-sbd-instance_attributes-pcmk_delay_max", data.Configuration.Resources.Primitives[0].InstanceAttributes[0].ID) - assert.Equal(t, "30s", data.Configuration.Resources.Primitives[0].InstanceAttributes[0].Value) - assert.Equal(t, 1, len(data.Configuration.Resources.Groups)) - assert.Equal(t, "g_ip_PRD_HDB00", data.Configuration.Resources.Groups[0].ID) - assert.Equal(t, 1, len(data.Configuration.Resources.Groups[0].Primitives)) - assert.Equal(t, "rsc_ip_PRD_HDB00", data.Configuration.Resources.Groups[0].Primitives[0].ID) - assert.Equal(t, "ocf", data.Configuration.Resources.Groups[0].Primitives[0].Class) - assert.Equal(t, "heartbeat", data.Configuration.Resources.Groups[0].Primitives[0].Provider) - assert.Equal(t, "IPaddr2", data.Configuration.Resources.Groups[0].Primitives[0].Type) - assert.Equal(t, 1, len(data.Configuration.Resources.Groups[0].Primitives[0].InstanceAttributes)) - assert.Equal(t, "rsc_ip_PRD_HDB00-instance_attributes-ip", data.Configuration.Resources.Groups[0].Primitives[0].InstanceAttributes[0].ID) - assert.Equal(t, "ip", data.Configuration.Resources.Groups[0].Primitives[0].InstanceAttributes[0].Name) - assert.Equal(t, "10.74.1.12", data.Configuration.Resources.Groups[0].Primitives[0].InstanceAttributes[0].Value) - assert.Equal(t, "msl_SAPHana_PRD_HDB00", data.Configuration.Resources.Masters[0].ID) - assert.Equal(t, 3, len(data.Configuration.Resources.Masters[0].MetaAttributes)) - assert.Equal(t, "rsc_SAPHana_PRD_HDB00", data.Configuration.Resources.Masters[0].Primitive.ID) - assert.Equal(t, 5, len(data.Configuration.Resources.Masters[0].Primitive.Operations)) - assert.Equal(t, "rsc_SAPHana_PRD_HDB00-start-0", data.Configuration.Resources.Masters[0].Primitive.Operations[0].ID) - assert.Equal(t, "start", data.Configuration.Resources.Masters[0].Primitive.Operations[0].Name) - assert.Equal(t, "0", data.Configuration.Resources.Masters[0].Primitive.Operations[0].Interval) - assert.Equal(t, "3600", data.Configuration.Resources.Masters[0].Primitive.Operations[0].Timeout) - assert.Equal(t, "rsc_SAPHana_PRD_HDB00-stop-0", data.Configuration.Resources.Masters[0].Primitive.Operations[1].ID) - assert.Equal(t, "stop", data.Configuration.Resources.Masters[0].Primitive.Operations[1].Name) - assert.Equal(t, "0", data.Configuration.Resources.Masters[0].Primitive.Operations[1].Interval) - assert.Equal(t, "3600", data.Configuration.Resources.Masters[0].Primitive.Operations[1].Timeout) - assert.Equal(t, "rsc_SAPHana_PRD_HDB00-promote-0", data.Configuration.Resources.Masters[0].Primitive.Operations[2].ID) - assert.Equal(t, "promote", data.Configuration.Resources.Masters[0].Primitive.Operations[2].Name) - assert.Equal(t, "0", data.Configuration.Resources.Masters[0].Primitive.Operations[2].Interval) - assert.Equal(t, "3600", data.Configuration.Resources.Masters[0].Primitive.Operations[2].Timeout) - assert.Equal(t, "rsc_SAPHana_PRD_HDB00-monitor-60", data.Configuration.Resources.Masters[0].Primitive.Operations[3].ID) - assert.Equal(t, "monitor", data.Configuration.Resources.Masters[0].Primitive.Operations[3].Name) - assert.Equal(t, "Master", data.Configuration.Resources.Masters[0].Primitive.Operations[3].Role) - assert.Equal(t, "60", data.Configuration.Resources.Masters[0].Primitive.Operations[3].Interval) - assert.Equal(t, "700", data.Configuration.Resources.Masters[0].Primitive.Operations[3].Timeout) - assert.Equal(t, "rsc_SAPHana_PRD_HDB00-monitor-61", data.Configuration.Resources.Masters[0].Primitive.Operations[4].ID) - assert.Equal(t, "monitor", data.Configuration.Resources.Masters[0].Primitive.Operations[4].Name) - assert.Equal(t, "Slave", data.Configuration.Resources.Masters[0].Primitive.Operations[4].Role) - assert.Equal(t, "61", data.Configuration.Resources.Masters[0].Primitive.Operations[4].Interval) - assert.Equal(t, "700", data.Configuration.Resources.Masters[0].Primitive.Operations[4].Timeout) - assert.Equal(t, "test", data.Configuration.Resources.Primitives[2].ID) - assert.Equal(t, "ocf", data.Configuration.Resources.Primitives[2].Class) - assert.Equal(t, "heartbeat", data.Configuration.Resources.Primitives[2].Provider) - assert.Equal(t, "Dummy", data.Configuration.Resources.Primitives[2].Type) + suite.NoError(err) + suite.Equal(2, len(data.Configuration.Nodes)) + suite.Equal("cib-bootstrap-options-cluster-name", data.Configuration.CrmConfig.ClusterProperties[3].ID) + suite.Equal("hana_cluster", data.Configuration.CrmConfig.ClusterProperties[3].Value) + suite.Equal("node01", data.Configuration.Nodes[0].Uname) + suite.Equal("node02", data.Configuration.Nodes[1].Uname) + suite.Equal(4, len(data.Configuration.Resources.Primitives)) + suite.Equal(1, len(data.Configuration.Resources.Masters)) + suite.Equal(1, len(data.Configuration.Resources.Clones)) + suite.Equal("stonith-sbd", data.Configuration.Resources.Primitives[0].ID) + suite.Equal("stonith", data.Configuration.Resources.Primitives[0].Class) + suite.Equal("external/sbd", data.Configuration.Resources.Primitives[0].Type) + suite.Equal(1, len(data.Configuration.Resources.Primitives[0].InstanceAttributes)) + suite.Equal("pcmk_delay_max", data.Configuration.Resources.Primitives[0].InstanceAttributes[0].Name) + suite.Equal("stonith-sbd-instance_attributes-pcmk_delay_max", data.Configuration.Resources.Primitives[0].InstanceAttributes[0].ID) + suite.Equal("30s", data.Configuration.Resources.Primitives[0].InstanceAttributes[0].Value) + suite.Equal(1, len(data.Configuration.Resources.Groups)) + suite.Equal("g_ip_PRD_HDB00", data.Configuration.Resources.Groups[0].ID) + suite.Equal(1, len(data.Configuration.Resources.Groups[0].Primitives)) + suite.Equal("rsc_ip_PRD_HDB00", data.Configuration.Resources.Groups[0].Primitives[0].ID) + suite.Equal("ocf", data.Configuration.Resources.Groups[0].Primitives[0].Class) + suite.Equal("heartbeat", data.Configuration.Resources.Groups[0].Primitives[0].Provider) + suite.Equal("IPaddr2", data.Configuration.Resources.Groups[0].Primitives[0].Type) + suite.Equal(1, len(data.Configuration.Resources.Groups[0].Primitives[0].InstanceAttributes)) + suite.Equal("rsc_ip_PRD_HDB00-instance_attributes-ip", data.Configuration.Resources.Groups[0].Primitives[0].InstanceAttributes[0].ID) + suite.Equal("ip", data.Configuration.Resources.Groups[0].Primitives[0].InstanceAttributes[0].Name) + suite.Equal("10.74.1.12", data.Configuration.Resources.Groups[0].Primitives[0].InstanceAttributes[0].Value) + suite.Equal("msl_SAPHana_PRD_HDB00", data.Configuration.Resources.Masters[0].ID) + suite.Equal(3, len(data.Configuration.Resources.Masters[0].MetaAttributes)) + suite.Equal("rsc_SAPHana_PRD_HDB00", data.Configuration.Resources.Masters[0].Primitive.ID) + suite.Equal(5, len(data.Configuration.Resources.Masters[0].Primitive.Operations)) + suite.Equal("rsc_SAPHana_PRD_HDB00-start-0", data.Configuration.Resources.Masters[0].Primitive.Operations[0].ID) + suite.Equal("start", data.Configuration.Resources.Masters[0].Primitive.Operations[0].Name) + suite.Equal("0", data.Configuration.Resources.Masters[0].Primitive.Operations[0].Interval) + suite.Equal("3600", data.Configuration.Resources.Masters[0].Primitive.Operations[0].Timeout) + suite.Equal("rsc_SAPHana_PRD_HDB00-stop-0", data.Configuration.Resources.Masters[0].Primitive.Operations[1].ID) + suite.Equal("stop", data.Configuration.Resources.Masters[0].Primitive.Operations[1].Name) + suite.Equal("0", data.Configuration.Resources.Masters[0].Primitive.Operations[1].Interval) + suite.Equal("3600", data.Configuration.Resources.Masters[0].Primitive.Operations[1].Timeout) + suite.Equal("rsc_SAPHana_PRD_HDB00-promote-0", data.Configuration.Resources.Masters[0].Primitive.Operations[2].ID) + suite.Equal("promote", data.Configuration.Resources.Masters[0].Primitive.Operations[2].Name) + suite.Equal("0", data.Configuration.Resources.Masters[0].Primitive.Operations[2].Interval) + suite.Equal("3600", data.Configuration.Resources.Masters[0].Primitive.Operations[2].Timeout) + suite.Equal("rsc_SAPHana_PRD_HDB00-monitor-60", data.Configuration.Resources.Masters[0].Primitive.Operations[3].ID) + suite.Equal("monitor", data.Configuration.Resources.Masters[0].Primitive.Operations[3].Name) + suite.Equal("Master", data.Configuration.Resources.Masters[0].Primitive.Operations[3].Role) + suite.Equal("60", data.Configuration.Resources.Masters[0].Primitive.Operations[3].Interval) + suite.Equal("700", data.Configuration.Resources.Masters[0].Primitive.Operations[3].Timeout) + suite.Equal("rsc_SAPHana_PRD_HDB00-monitor-61", data.Configuration.Resources.Masters[0].Primitive.Operations[4].ID) + suite.Equal("monitor", data.Configuration.Resources.Masters[0].Primitive.Operations[4].Name) + suite.Equal("Slave", data.Configuration.Resources.Masters[0].Primitive.Operations[4].Role) + suite.Equal("61", data.Configuration.Resources.Masters[0].Primitive.Operations[4].Interval) + suite.Equal("700", data.Configuration.Resources.Masters[0].Primitive.Operations[4].Timeout) + suite.Equal("test", data.Configuration.Resources.Primitives[2].ID) + suite.Equal("ocf", data.Configuration.Resources.Primitives[2].Class) + suite.Equal("heartbeat", data.Configuration.Resources.Primitives[2].Provider) + suite.Equal("Dummy", data.Configuration.Resources.Primitives[2].Type) } diff --git a/internal/cluster/cluster_test.go b/internal/cluster/cluster_test.go index 89cbaf46..0c5c93f0 100644 --- a/internal/cluster/cluster_test.go +++ b/internal/cluster/cluster_test.go @@ -5,13 +5,20 @@ import ( "os" "testing" + "github.com/stretchr/testify/suite" "github.com/trento-project/agent/internal/cluster/cib" "github.com/trento-project/agent/internal/cluster/crmmon" - - "github.com/stretchr/testify/assert" ) -func TestClusterId(t *testing.T) { +type ClusterTestSuite struct { + suite.Suite +} + +func TestClusterTestSuite(t *testing.T) { + suite.Run(t, new(ClusterTestSuite)) +} + +func (suite *ClusterTestSuite) TestClusterId() { root := new(cib.Root) c := Cluster{ @@ -22,10 +29,10 @@ func TestClusterId(t *testing.T) { authkey, _ := getCorosyncAuthkeyMd5("../../test/authkey") - assert.Equal(t, c.ID, authkey) + suite.Equal(c.ID, authkey) } -func TestClusterName(t *testing.T) { +func (suite *ClusterTestSuite) TestClusterName() { root := new(cib.Root) crmConfig := struct { @@ -59,10 +66,10 @@ func TestClusterName(t *testing.T) { Name: "cluster_name", } - assert.Equal(t, "cluster_name", c.Name) + suite.Equal("cluster_name", c.Name) } -func TestIsDC(t *testing.T) { +func (suite *ClusterTestSuite) TestIsDC() { host, _ := os.Hostname() root := new(cib.Root) @@ -96,7 +103,7 @@ func TestIsDC(t *testing.T) { }, } - assert.Equal(t, true, isDC(c)) + suite.Equal(true, isDC(c)) c = &Cluster{ Cib: *root, @@ -115,10 +122,10 @@ func TestIsDC(t *testing.T) { }, } - assert.Equal(t, false, isDC(c)) + suite.Equal(false, isDC(c)) } -func TestIsFencingEnabled(t *testing.T) { +func (suite *ClusterTestSuite) TestIsFencingEnabled() { root := new(cib.Root) crmConfig := struct { @@ -138,7 +145,7 @@ func TestIsFencingEnabled(t *testing.T) { Cib: *root, } - assert.Equal(t, true, c.IsFencingEnabled()) + suite.Equal(true, c.IsFencingEnabled()) crmConfig = struct { ClusterProperties []cib.Attribute `xml:"cluster_property_set>nvpair"` @@ -157,10 +164,10 @@ func TestIsFencingEnabled(t *testing.T) { Cib: *root, } - assert.Equal(t, false, c.IsFencingEnabled()) + suite.Equal(false, c.IsFencingEnabled()) } -func TestFencingType(t *testing.T) { +func (suite *ClusterTestSuite) TestFencingType() { c := Cluster{ Crmmon: crmmon.Root{ Version: "1.2.3", @@ -172,7 +179,7 @@ func TestFencingType(t *testing.T) { }, } - assert.Equal(t, "myfencing", c.FencingType()) + suite.Equal("myfencing", c.FencingType()) c = Cluster{ Crmmon: crmmon.Root{ @@ -185,10 +192,10 @@ func TestFencingType(t *testing.T) { }, } - assert.Equal(t, "notconfigured", c.FencingType()) + suite.Equal("notconfigured", c.FencingType()) } -func TestFencingResourceExists(t *testing.T) { +func (suite *ClusterTestSuite) TestFencingResourceExists() { c := Cluster{ Crmmon: crmmon.Root{ Version: "1.2.3", @@ -200,7 +207,7 @@ func TestFencingResourceExists(t *testing.T) { }, } - assert.Equal(t, true, c.FencingResourceExists()) + suite.Equal(true, c.FencingResourceExists()) c = Cluster{ Crmmon: crmmon.Root{ @@ -213,10 +220,10 @@ func TestFencingResourceExists(t *testing.T) { }, } - assert.Equal(t, false, c.FencingResourceExists()) + suite.Equal(false, c.FencingResourceExists()) } -func TestIsFencingSBD(t *testing.T) { +func (suite *ClusterTestSuite) TestIsFencingSBD() { c := Cluster{ Crmmon: crmmon.Root{ Version: "1.2.3", @@ -228,7 +235,7 @@ func TestIsFencingSBD(t *testing.T) { }, } - assert.Equal(t, true, c.IsFencingSBD()) + suite.Equal(true, c.IsFencingSBD()) c = Cluster{ Crmmon: crmmon.Root{ @@ -241,5 +248,5 @@ func TestIsFencingSBD(t *testing.T) { }, } - assert.Equal(t, false, c.IsFencingSBD()) + suite.Equal(false, c.IsFencingSBD()) } diff --git a/internal/cluster/crmmon/parser_test.go b/internal/cluster/crmmon/parser_test.go index 7bd7f6c9..4aea976c 100644 --- a/internal/cluster/crmmon/parser_test.go +++ b/internal/cluster/crmmon/parser_test.go @@ -3,146 +3,154 @@ package crmmon import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" ) -func TestConstructor(t *testing.T) { +type ParserTestSuite struct { + suite.Suite +} + +func TestParserTestSuite(t *testing.T) { + suite.Run(t, new(ParserTestSuite)) +} + +func (suite *ParserTestSuite) TestConstructor() { p := NewCrmMonParser("foo") - assert.Equal(t, "foo", p.crmMonPath) + suite.Equal("foo", p.crmMonPath) } -func TestParse(t *testing.T) { +func (suite *ParserTestSuite) TestParse() { p := NewCrmMonParser("../../../test/fake_crm_mon.sh") data, err := p.Parse() - assert.NoError(t, err) - assert.Equal(t, "2.0.0", data.Version) - assert.Equal(t, 8, data.Summary.Resources.Number) - assert.Equal(t, 1, data.Summary.Resources.Disabled) - assert.Equal(t, 0, data.Summary.Resources.Blocked) - assert.Equal(t, "Fri Oct 18 11:48:22 2019", data.Summary.LastChange.Time) - assert.Equal(t, 2, data.Summary.Nodes.Number) - assert.Equal(t, "node01", data.Nodes[0].Name) - assert.Equal(t, "1084783375", data.Nodes[0].ID) - assert.Equal(t, true, data.Nodes[0].Online) - assert.Equal(t, true, data.Nodes[0].ExpectedUp) - assert.Equal(t, true, data.Nodes[0].DC) - assert.Equal(t, false, data.Nodes[0].Unclean) - assert.Equal(t, false, data.Nodes[0].Shutdown) - assert.Equal(t, false, data.Nodes[0].StandbyOnFail) - assert.Equal(t, false, data.Nodes[0].Maintenance) - assert.Equal(t, false, data.Nodes[0].Pending) - assert.Equal(t, false, data.Nodes[0].Standby) - assert.Equal(t, "node02", data.Nodes[1].Name) - assert.Equal(t, "1084783376", data.Nodes[1].ID) - assert.Equal(t, true, data.Nodes[1].Online) - assert.Equal(t, true, data.Nodes[1].ExpectedUp) - assert.Equal(t, false, data.Nodes[1].DC) - assert.Equal(t, false, data.Nodes[1].Unclean) - assert.Equal(t, false, data.Nodes[1].Shutdown) - assert.Equal(t, false, data.Nodes[1].StandbyOnFail) - assert.Equal(t, false, data.Nodes[1].Maintenance) - assert.Equal(t, false, data.Nodes[1].Pending) - assert.Equal(t, false, data.Nodes[1].Standby) - assert.Equal(t, "node01", data.NodeHistory.Nodes[0].Name) - assert.Equal(t, 5000, data.NodeHistory.Nodes[0].ResourceHistory[0].MigrationThreshold) - assert.Equal(t, 2, data.NodeHistory.Nodes[0].ResourceHistory[1].FailCount) - assert.Equal(t, "rsc_SAPHana_PRD_HDB00", data.NodeHistory.Nodes[0].ResourceHistory[0].Name) - assert.Equal(t, 4, len(data.Resources)) - assert.Equal(t, "test-stop", data.Resources[0].ID) - assert.Equal(t, false, data.Resources[0].Active) - assert.Equal(t, "Stopped", data.Resources[0].Role) + suite.NoError(err) + suite.Equal("2.0.0", data.Version) + suite.Equal(8, data.Summary.Resources.Number) + suite.Equal(1, data.Summary.Resources.Disabled) + suite.Equal(0, data.Summary.Resources.Blocked) + suite.Equal("Fri Oct 18 11:48:22 2019", data.Summary.LastChange.Time) + suite.Equal(2, data.Summary.Nodes.Number) + suite.Equal("node01", data.Nodes[0].Name) + suite.Equal("1084783375", data.Nodes[0].ID) + suite.Equal(true, data.Nodes[0].Online) + suite.Equal(true, data.Nodes[0].ExpectedUp) + suite.Equal(true, data.Nodes[0].DC) + suite.Equal(false, data.Nodes[0].Unclean) + suite.Equal(false, data.Nodes[0].Shutdown) + suite.Equal(false, data.Nodes[0].StandbyOnFail) + suite.Equal(false, data.Nodes[0].Maintenance) + suite.Equal(false, data.Nodes[0].Pending) + suite.Equal(false, data.Nodes[0].Standby) + suite.Equal("node02", data.Nodes[1].Name) + suite.Equal("1084783376", data.Nodes[1].ID) + suite.Equal(true, data.Nodes[1].Online) + suite.Equal(true, data.Nodes[1].ExpectedUp) + suite.Equal(false, data.Nodes[1].DC) + suite.Equal(false, data.Nodes[1].Unclean) + suite.Equal(false, data.Nodes[1].Shutdown) + suite.Equal(false, data.Nodes[1].StandbyOnFail) + suite.Equal(false, data.Nodes[1].Maintenance) + suite.Equal(false, data.Nodes[1].Pending) + suite.Equal(false, data.Nodes[1].Standby) + suite.Equal("node01", data.NodeHistory.Nodes[0].Name) + suite.Equal(5000, data.NodeHistory.Nodes[0].ResourceHistory[0].MigrationThreshold) + suite.Equal(2, data.NodeHistory.Nodes[0].ResourceHistory[1].FailCount) + suite.Equal("rsc_SAPHana_PRD_HDB00", data.NodeHistory.Nodes[0].ResourceHistory[0].Name) + suite.Equal(4, len(data.Resources)) + suite.Equal("test-stop", data.Resources[0].ID) + suite.Equal(false, data.Resources[0].Active) + suite.Equal("Stopped", data.Resources[0].Role) } -func TestParseClones(t *testing.T) { +func (suite *ParserTestSuite) TestParseClones() { p := NewCrmMonParser("../../../test/fake_crm_mon.sh") data, err := p.Parse() - assert.NoError(t, err) - assert.Equal(t, 3, len(data.Clones)) - assert.Equal(t, "msl_SAPHana_PRD_HDB00", data.Clones[0].ID) - assert.Equal(t, "cln_SAPHanaTopology_PRD_HDB00", data.Clones[1].ID) - assert.Equal(t, "c-clusterfs", data.Clones[2].ID) - assert.Equal(t, 2, len(data.Clones[0].Resources)) - assert.Equal(t, 2, len(data.Clones[1].Resources)) - assert.Equal(t, "rsc_SAPHana_PRD_HDB00", data.Clones[0].Resources[0].ID) - assert.Equal(t, "Master", data.Clones[0].Resources[0].Role) - assert.Equal(t, "rsc_SAPHana_PRD_HDB00", data.Clones[0].Resources[1].ID) - assert.Equal(t, "Slave", data.Clones[0].Resources[1].Role) + suite.NoError(err) + suite.Equal(3, len(data.Clones)) + suite.Equal("msl_SAPHana_PRD_HDB00", data.Clones[0].ID) + suite.Equal("cln_SAPHanaTopology_PRD_HDB00", data.Clones[1].ID) + suite.Equal("c-clusterfs", data.Clones[2].ID) + suite.Equal(2, len(data.Clones[0].Resources)) + suite.Equal(2, len(data.Clones[1].Resources)) + suite.Equal("rsc_SAPHana_PRD_HDB00", data.Clones[0].Resources[0].ID) + suite.Equal("Master", data.Clones[0].Resources[0].Role) + suite.Equal("rsc_SAPHana_PRD_HDB00", data.Clones[0].Resources[1].ID) + suite.Equal("Slave", data.Clones[0].Resources[1].Role) } -func TestParseGroups(t *testing.T) { +func (suite *ParserTestSuite) TestParseGroups() { p := NewCrmMonParser("../../../test/fake_crm_mon.sh") data, err := p.Parse() - assert.NoError(t, err) - assert.Equal(t, 2, len(data.Groups)) + suite.NoError(err) + suite.Equal(2, len(data.Groups)) - assert.Equal(t, "grp_HA1_ASCS00", data.Groups[0].ID) - assert.Equal(t, 3, len(data.Groups[0].Resources)) - assert.Equal(t, "rsc_ip_HA1_ASCS00", data.Groups[0].Resources[0].ID) - assert.Equal(t, "rsc_fs_HA1_ASCS00", data.Groups[0].Resources[1].ID) - assert.Equal(t, "rsc_sap_HA1_ASCS00", data.Groups[0].Resources[2].ID) + suite.Equal("grp_HA1_ASCS00", data.Groups[0].ID) + suite.Equal(3, len(data.Groups[0].Resources)) + suite.Equal("rsc_ip_HA1_ASCS00", data.Groups[0].Resources[0].ID) + suite.Equal("rsc_fs_HA1_ASCS00", data.Groups[0].Resources[1].ID) + suite.Equal("rsc_sap_HA1_ASCS00", data.Groups[0].Resources[2].ID) - assert.Equal(t, "grp_HA1_ERS10", data.Groups[1].ID) - assert.Equal(t, 3, len(data.Groups[1].Resources)) - assert.Equal(t, "rsc_ip_HA1_ERS10", data.Groups[1].Resources[0].ID) - assert.Equal(t, "rsc_fs_HA1_ERS10", data.Groups[1].Resources[1].ID) - assert.Equal(t, "rsc_sap_HA1_ERS10", data.Groups[1].Resources[2].ID) + suite.Equal("grp_HA1_ERS10", data.Groups[1].ID) + suite.Equal(3, len(data.Groups[1].Resources)) + suite.Equal("rsc_ip_HA1_ERS10", data.Groups[1].Resources[0].ID) + suite.Equal("rsc_fs_HA1_ERS10", data.Groups[1].Resources[1].ID) + suite.Equal("rsc_sap_HA1_ERS10", data.Groups[1].Resources[2].ID) } -func TestParseNodeAttributes(t *testing.T) { +func (suite *ParserTestSuite) TestParseNodeAttributes() { p := NewCrmMonParser("../../../test/fake_crm_mon.sh") data, err := p.Parse() - assert.NoError(t, err) - assert.Len(t, data.NodeAttributes.Nodes, 2) - assert.Equal(t, "node01", data.NodeAttributes.Nodes[0].Name) - assert.Equal(t, "node02", data.NodeAttributes.Nodes[1].Name) + suite.NoError(err) + suite.Len(data.NodeAttributes.Nodes, 2) + suite.Equal("node01", data.NodeAttributes.Nodes[0].Name) + suite.Equal("node02", data.NodeAttributes.Nodes[1].Name) - assert.Len(t, data.NodeAttributes.Nodes[0].Attributes, 11) - assert.Equal(t, "hana_prd_clone_state", data.NodeAttributes.Nodes[0].Attributes[0].Name) - assert.Equal(t, "hana_prd_op_mode", data.NodeAttributes.Nodes[0].Attributes[1].Name) - assert.Equal(t, "hana_prd_remoteHost", data.NodeAttributes.Nodes[0].Attributes[2].Name) - assert.Equal(t, "hana_prd_roles", data.NodeAttributes.Nodes[0].Attributes[3].Name) - assert.Equal(t, "hana_prd_site", data.NodeAttributes.Nodes[0].Attributes[4].Name) - assert.Equal(t, "hana_prd_srmode", data.NodeAttributes.Nodes[0].Attributes[5].Name) - assert.Equal(t, "hana_prd_sync_state", data.NodeAttributes.Nodes[0].Attributes[6].Name) - assert.Equal(t, "hana_prd_version", data.NodeAttributes.Nodes[0].Attributes[7].Name) - assert.Equal(t, "hana_prd_vhost", data.NodeAttributes.Nodes[0].Attributes[8].Name) - assert.Equal(t, "lpa_prd_lpt", data.NodeAttributes.Nodes[0].Attributes[9].Name) - assert.Equal(t, "master-rsc_SAPHana_PRD_HDB00", data.NodeAttributes.Nodes[0].Attributes[10].Name) + suite.Len(data.NodeAttributes.Nodes[0].Attributes, 11) + suite.Equal("hana_prd_clone_state", data.NodeAttributes.Nodes[0].Attributes[0].Name) + suite.Equal("hana_prd_op_mode", data.NodeAttributes.Nodes[0].Attributes[1].Name) + suite.Equal("hana_prd_remoteHost", data.NodeAttributes.Nodes[0].Attributes[2].Name) + suite.Equal("hana_prd_roles", data.NodeAttributes.Nodes[0].Attributes[3].Name) + suite.Equal("hana_prd_site", data.NodeAttributes.Nodes[0].Attributes[4].Name) + suite.Equal("hana_prd_srmode", data.NodeAttributes.Nodes[0].Attributes[5].Name) + suite.Equal("hana_prd_sync_state", data.NodeAttributes.Nodes[0].Attributes[6].Name) + suite.Equal("hana_prd_version", data.NodeAttributes.Nodes[0].Attributes[7].Name) + suite.Equal("hana_prd_vhost", data.NodeAttributes.Nodes[0].Attributes[8].Name) + suite.Equal("lpa_prd_lpt", data.NodeAttributes.Nodes[0].Attributes[9].Name) + suite.Equal("master-rsc_SAPHana_PRD_HDB00", data.NodeAttributes.Nodes[0].Attributes[10].Name) - assert.Equal(t, "PROMOTED", data.NodeAttributes.Nodes[0].Attributes[0].Value) - assert.Equal(t, "logreplay", data.NodeAttributes.Nodes[0].Attributes[1].Value) - assert.Equal(t, "node02", data.NodeAttributes.Nodes[0].Attributes[2].Value) - assert.Equal(t, "4:P:master1:master:worker:master", data.NodeAttributes.Nodes[0].Attributes[3].Value) - assert.Equal(t, "PRIMARY_SITE_NAME", data.NodeAttributes.Nodes[0].Attributes[4].Value) - assert.Equal(t, "sync", data.NodeAttributes.Nodes[0].Attributes[5].Value) - assert.Equal(t, "PRIM", data.NodeAttributes.Nodes[0].Attributes[6].Value) - assert.Equal(t, "2.00.040.00.1553674765", data.NodeAttributes.Nodes[0].Attributes[7].Value) - assert.Equal(t, "node01", data.NodeAttributes.Nodes[0].Attributes[8].Value) - assert.Equal(t, "1571392102", data.NodeAttributes.Nodes[0].Attributes[9].Value) - assert.Equal(t, "150", data.NodeAttributes.Nodes[0].Attributes[10].Value) + suite.Equal("PROMOTED", data.NodeAttributes.Nodes[0].Attributes[0].Value) + suite.Equal("logreplay", data.NodeAttributes.Nodes[0].Attributes[1].Value) + suite.Equal("node02", data.NodeAttributes.Nodes[0].Attributes[2].Value) + suite.Equal("4:P:master1:master:worker:master", data.NodeAttributes.Nodes[0].Attributes[3].Value) + suite.Equal("PRIMARY_SITE_NAME", data.NodeAttributes.Nodes[0].Attributes[4].Value) + suite.Equal("sync", data.NodeAttributes.Nodes[0].Attributes[5].Value) + suite.Equal("PRIM", data.NodeAttributes.Nodes[0].Attributes[6].Value) + suite.Equal("2.00.040.00.1553674765", data.NodeAttributes.Nodes[0].Attributes[7].Value) + suite.Equal("node01", data.NodeAttributes.Nodes[0].Attributes[8].Value) + suite.Equal("1571392102", data.NodeAttributes.Nodes[0].Attributes[9].Value) + suite.Equal("150", data.NodeAttributes.Nodes[0].Attributes[10].Value) - assert.Len(t, data.NodeAttributes.Nodes[1].Attributes, 11) - assert.Equal(t, "hana_prd_clone_state", data.NodeAttributes.Nodes[0].Attributes[0].Name) - assert.Equal(t, "hana_prd_op_mode", data.NodeAttributes.Nodes[0].Attributes[1].Name) - assert.Equal(t, "hana_prd_remoteHost", data.NodeAttributes.Nodes[0].Attributes[2].Name) - assert.Equal(t, "hana_prd_roles", data.NodeAttributes.Nodes[0].Attributes[3].Name) - assert.Equal(t, "hana_prd_site", data.NodeAttributes.Nodes[0].Attributes[4].Name) - assert.Equal(t, "hana_prd_srmode", data.NodeAttributes.Nodes[0].Attributes[5].Name) - assert.Equal(t, "hana_prd_sync_state", data.NodeAttributes.Nodes[0].Attributes[6].Name) - assert.Equal(t, "hana_prd_version", data.NodeAttributes.Nodes[0].Attributes[7].Name) - assert.Equal(t, "hana_prd_vhost", data.NodeAttributes.Nodes[0].Attributes[8].Name) - assert.Equal(t, "lpa_prd_lpt", data.NodeAttributes.Nodes[0].Attributes[9].Name) - assert.Equal(t, "master-rsc_SAPHana_PRD_HDB00", data.NodeAttributes.Nodes[0].Attributes[10].Name) + suite.Len(data.NodeAttributes.Nodes[1].Attributes, 11) + suite.Equal("hana_prd_clone_state", data.NodeAttributes.Nodes[0].Attributes[0].Name) + suite.Equal("hana_prd_op_mode", data.NodeAttributes.Nodes[0].Attributes[1].Name) + suite.Equal("hana_prd_remoteHost", data.NodeAttributes.Nodes[0].Attributes[2].Name) + suite.Equal("hana_prd_roles", data.NodeAttributes.Nodes[0].Attributes[3].Name) + suite.Equal("hana_prd_site", data.NodeAttributes.Nodes[0].Attributes[4].Name) + suite.Equal("hana_prd_srmode", data.NodeAttributes.Nodes[0].Attributes[5].Name) + suite.Equal("hana_prd_sync_state", data.NodeAttributes.Nodes[0].Attributes[6].Name) + suite.Equal("hana_prd_version", data.NodeAttributes.Nodes[0].Attributes[7].Name) + suite.Equal("hana_prd_vhost", data.NodeAttributes.Nodes[0].Attributes[8].Name) + suite.Equal("lpa_prd_lpt", data.NodeAttributes.Nodes[0].Attributes[9].Name) + suite.Equal("master-rsc_SAPHana_PRD_HDB00", data.NodeAttributes.Nodes[0].Attributes[10].Name) - assert.Equal(t, "DEMOTED", data.NodeAttributes.Nodes[1].Attributes[0].Value) - assert.Equal(t, "logreplay", data.NodeAttributes.Nodes[1].Attributes[1].Value) - assert.Equal(t, "node01", data.NodeAttributes.Nodes[1].Attributes[2].Value) - assert.Equal(t, "4:S:master1:master:worker:master", data.NodeAttributes.Nodes[1].Attributes[3].Value) - assert.Equal(t, "SECONDARY_SITE_NAME", data.NodeAttributes.Nodes[1].Attributes[4].Value) - assert.Equal(t, "sync", data.NodeAttributes.Nodes[1].Attributes[5].Value) - assert.Equal(t, "SOK", data.NodeAttributes.Nodes[1].Attributes[6].Value) - assert.Equal(t, "2.00.040.00.1553674765", data.NodeAttributes.Nodes[1].Attributes[7].Value) - assert.Equal(t, "node02", data.NodeAttributes.Nodes[1].Attributes[8].Value) - assert.Equal(t, "30", data.NodeAttributes.Nodes[1].Attributes[9].Value) - assert.Equal(t, "100", data.NodeAttributes.Nodes[1].Attributes[10].Value) + suite.Equal("DEMOTED", data.NodeAttributes.Nodes[1].Attributes[0].Value) + suite.Equal("logreplay", data.NodeAttributes.Nodes[1].Attributes[1].Value) + suite.Equal("node01", data.NodeAttributes.Nodes[1].Attributes[2].Value) + suite.Equal("4:S:master1:master:worker:master", data.NodeAttributes.Nodes[1].Attributes[3].Value) + suite.Equal("SECONDARY_SITE_NAME", data.NodeAttributes.Nodes[1].Attributes[4].Value) + suite.Equal("sync", data.NodeAttributes.Nodes[1].Attributes[5].Value) + suite.Equal("SOK", data.NodeAttributes.Nodes[1].Attributes[6].Value) + suite.Equal("2.00.040.00.1553674765", data.NodeAttributes.Nodes[1].Attributes[7].Value) + suite.Equal("node02", data.NodeAttributes.Nodes[1].Attributes[8].Value) + suite.Equal("30", data.NodeAttributes.Nodes[1].Attributes[9].Value) + suite.Equal("100", data.NodeAttributes.Nodes[1].Attributes[10].Value) } diff --git a/internal/cluster/sbd_test.go b/internal/cluster/sbd_test.go index 4aff92ca..3e68f87b 100644 --- a/internal/cluster/sbd_test.go +++ b/internal/cluster/sbd_test.go @@ -5,9 +5,17 @@ import ( "os/exec" "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" ) +type SbdTestSuite struct { + suite.Suite +} + +func TestSbdTestSuite(t *testing.T) { + suite.Run(t, new(SbdTestSuite)) +} + func mockSbdDump(command string, args ...string) *exec.Cmd { cmd := `==Dumping header on disk /dev/vdc Header version : 2.1 @@ -49,7 +57,7 @@ sbd failed; please check the logs.` return exec.Command("bash", "-c", script) } -func TestSbdDump(t *testing.T) { +func (suite *SbdTestSuite) TestSbdDump() { sbdDumpExecCommand = mockSbdDump dump, err := sbdDump("/bin/sbd", "/dev/vdc") @@ -65,11 +73,11 @@ func TestSbdDump(t *testing.T) { TimeoutMsgwait: 10, } - assert.Equal(t, expectedDump, dump) - assert.NoError(t, err) + suite.Equal(expectedDump, dump) + suite.NoError(err) } -func TestSbdDumpError(t *testing.T) { +func (suite *SbdTestSuite) TestSbdDumpError() { sbdDumpExecCommand = mockSbdDumpErr dump, err := sbdDump("/bin/sbd", "/dev/vdc") @@ -85,11 +93,11 @@ func TestSbdDumpError(t *testing.T) { TimeoutMsgwait: 0, } - assert.Equal(t, expectedDump, dump) - assert.EqualError(t, err, "sbd dump command error: exit status 1") + suite.Equal(expectedDump, dump) + suite.EqualError(err, "sbd dump command error: exit status 1") } -func TestSbdList(t *testing.T) { +func (suite *SbdTestSuite) TestSbdList() { sbdListExecCommand = mockSbdList list, err := sbdList("/bin/sbd", "/dev/vdc") @@ -107,22 +115,22 @@ func TestSbdList(t *testing.T) { }, } - assert.Equal(t, expectedList, list) - assert.NoError(t, err) + suite.Equal(expectedList, list) + suite.NoError(err) } -func TestSbdListError(t *testing.T) { +func (suite *SbdTestSuite) TestSbdListError() { sbdListExecCommand = mockSbdListErr list, err := sbdList("/bin/sbd", "/dev/vdc") expectedList := []*SBDNode{} - assert.Equal(t, expectedList, list) - assert.EqualError(t, err, "sbd list command error: exit status 1") + suite.Equal(expectedList, list) + suite.EqualError(err, "sbd list command error: exit status 1") } -func TestLoadDeviceData(t *testing.T) { +func (suite *SbdTestSuite) TestLoadDeviceData() { s := NewSBDDevice("/bin/sbd", "/dev/vdc") sbdDumpExecCommand = mockSbdDump @@ -155,11 +163,11 @@ func TestLoadDeviceData(t *testing.T) { }, } - assert.Equal(t, expectedDevice, s) - assert.NoError(t, err) + suite.Equal(expectedDevice, s) + suite.NoError(err) } -func TestLoadDeviceDataDumpError(t *testing.T) { +func (suite *SbdTestSuite) TestLoadDeviceDataDumpError() { s := NewSBDDevice("/bin/sbdErr", "/dev/vdc") sbdDumpExecCommand = mockSbdDumpErr @@ -193,11 +201,11 @@ func TestLoadDeviceDataDumpError(t *testing.T) { }, } - assert.Equal(t, expectedDevice, s) - assert.EqualError(t, err, "sbd dump command error: exit status 1") + suite.Equal(expectedDevice, s) + suite.EqualError(err, "sbd dump command error: exit status 1") } -func TestLoadDeviceDataListError(t *testing.T) { +func (suite *SbdTestSuite) TestLoadDeviceDataListError() { s := NewSBDDevice("/bin/sbdErr", "/dev/vdc") sbdDumpExecCommand = mockSbdDump @@ -220,11 +228,11 @@ func TestLoadDeviceDataListError(t *testing.T) { expectedDevice.List = []*SBDNode{} - assert.Equal(t, expectedDevice, s) - assert.EqualError(t, err, "sbd list command error: exit status 1") + suite.Equal(expectedDevice, s) + suite.EqualError(err, "sbd list command error: exit status 1") } -func TestLoadDeviceDataError(t *testing.T) { +func (suite *SbdTestSuite) TestLoadDeviceDataError() { s := NewSBDDevice("/bin/sbdErr", "/dev/vdc") sbdDumpExecCommand = mockSbdDumpErr @@ -248,11 +256,11 @@ func TestLoadDeviceDataError(t *testing.T) { expectedDevice.List = []*SBDNode{} - assert.Equal(t, expectedDevice, s) - assert.EqualError(t, err, "sbd dump command error: exit status 1;sbd list command error: exit status 1") + suite.Equal(expectedDevice, s) + suite.EqualError(err, "sbd dump command error: exit status 1;sbd list command error: exit status 1") } -func TestGetSBDConfig(t *testing.T) { +func (suite *SbdTestSuite) TestGetSBDConfig() { sbdConfig, err := getSBDConfig("../../test/sbd_config") expectedConfig := map[string]interface{}{ @@ -268,20 +276,20 @@ func TestGetSBDConfig(t *testing.T) { "TEST2": "Value2", } - assert.Equal(t, expectedConfig, sbdConfig) - assert.NoError(t, err) + suite.Equal(expectedConfig, sbdConfig) + suite.NoError(err) } -func TestGetSBDConfigError(t *testing.T) { +func (suite *SbdTestSuite) TestGetSBDConfigError() { sbdConfig, err := getSBDConfig("notexist") expectedConfig := map[string]interface{}(nil) - assert.Equal(t, expectedConfig, sbdConfig) - assert.EqualError(t, err, "could not open sbd config file: open notexist: no such file or directory") + suite.Equal(expectedConfig, sbdConfig) + suite.EqualError(err, "could not open sbd config file: open notexist: no such file or directory") } -func TestNewSBD(t *testing.T) { +func (suite *SbdTestSuite) TestNewSBD() { sbdDumpExecCommand = mockSbdDump sbdListExecCommand = mockSbdList @@ -359,11 +367,11 @@ func TestNewSBD(t *testing.T) { }, } - assert.Equal(t, expectedSbd, s) - assert.NoError(t, err) + suite.Equal(expectedSbd, s) + suite.NoError(err) } -func TestNewSBDError(t *testing.T) { +func (suite *SbdTestSuite) TestNewSBDError() { s, err := NewSBD("mycluster", "/bin/sbd", "../../test/sbd_config_no_device") expectedSbd := SBD{ //nolint @@ -379,11 +387,11 @@ func TestNewSBDError(t *testing.T) { }, } - assert.Equal(t, expectedSbd, s) - assert.EqualError(t, err, "could not find SBD_DEVICE entry in sbd config file") + suite.Equal(expectedSbd, s) + suite.EqualError(err, "could not find SBD_DEVICE entry in sbd config file") } -func TestNewSBDUnhealthyDevices(t *testing.T) { +func (suite *SbdTestSuite) TestNewSBDUnhealthyDevices() { sbdDumpExecCommand = mockSbdDumpErr sbdListExecCommand = mockSbdListErr @@ -439,18 +447,18 @@ func TestNewSBDUnhealthyDevices(t *testing.T) { }, } - assert.Equal(t, expectedSbd, s) - assert.NoError(t, err) + suite.Equal(expectedSbd, s) + suite.NoError(err) } -func TestNewSBDQuotedDevices(t *testing.T) { +func (suite *SbdTestSuite) TestNewSBDQuotedDevices() { sbdDumpExecCommand = mockSbdDump sbdListExecCommand = mockSbdList s, err := NewSBD("mycluster", "/bin/sbd", "../../test/sbd_config_quoted_devices") - assert.Equal(t, len(s.Devices), 2) - assert.Equal(t, "/dev/vdc", s.Devices[0].Device) - assert.Equal(t, "/dev/vdb", s.Devices[1].Device) - assert.NoError(t, err) + suite.Equal(len(s.Devices), 2) + suite.Equal("/dev/vdc", s.Devices[0].Device) + suite.Equal("/dev/vdb", s.Devices[1].Device) + suite.NoError(err) } diff --git a/internal/discovery/collector/client_test.go b/internal/discovery/collector/client_test.go index fc716dac..474abbd4 100644 --- a/internal/discovery/collector/client_test.go +++ b/internal/discovery/collector/client_test.go @@ -7,7 +7,6 @@ import ( "net/http" "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" _ "github.com/trento-project/agent/test" "github.com/trento-project/agent/test/helpers" @@ -48,7 +47,7 @@ func (suite *CollectorClientTestSuite) TestCollectorClientPublishingSuccess() { "payload": discoveredDataPayload, }) - assert.NoError(suite.T(), err) + suite.NoError(err) bodyBytes, _ := io.ReadAll(req.Body) suite.EqualValues(requestBody, bodyBytes) diff --git a/internal/discovery/collector/publishing_test.go b/internal/discovery/collector/publishing_test.go index ac97628f..13b30744 100644 --- a/internal/discovery/collector/publishing_test.go +++ b/internal/discovery/collector/publishing_test.go @@ -8,7 +8,6 @@ import ( "os" "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" "github.com/trento-project/agent/internal/discovery/mocks" _ "github.com/trento-project/agent/test" @@ -112,7 +111,7 @@ func (suite *PublishingTestSuite) runDiscoveryScenario(discoveryType string, pay "payload": payload, }) - assert.NoError(suite.T(), err) + suite.NoError(err) outgoingRequestBody, _ := io.ReadAll(req.Body) diff --git a/internal/subscription/subscription_test.go b/internal/subscription/subscription_test.go index bbc7bdd6..033bfbd9 100644 --- a/internal/subscription/subscription_test.go +++ b/internal/subscription/subscription_test.go @@ -4,11 +4,19 @@ import ( "os/exec" "testing" - "github.com/stretchr/testify/assert" - // "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/suite" + "github.com/trento-project/agent/internal/subscription/mocks" ) +type SubscriptionTestSuite struct { + suite.Suite +} + +func TestSubscriptionTestSuite(t *testing.T) { + suite.Run(t, new(SubscriptionTestSuite)) +} + func mockSUSEConnect() *exec.Cmd { return exec.Command("echo", `[{"identifier":"SLES_SAP","version":"15.2","arch":"x86_64", "status":"Registered","name":"SUSE Employee subscription for SUSE Linux Enterprise Server for SAP Applications", @@ -22,7 +30,7 @@ func mockSUSEConnectErr() *exec.Cmd { return exec.Command("error") } -func TestNewSubscriptions(t *testing.T) { +func (suite *SubscriptionTestSuite) TestNewSubscriptions() { mockCommand := new(mocks.CustomCommand) customExecCommand = mockCommand.Execute @@ -52,11 +60,11 @@ func TestNewSubscriptions(t *testing.T) { }, } - assert.NoError(t, err) - assert.ElementsMatch(t, expectedSubs, subs) + suite.NoError(err) + suite.ElementsMatch(expectedSubs, subs) } -func TestNewSubscriptionsErr(t *testing.T) { +func (suite *SubscriptionTestSuite) TestNewSubscriptionsErr() { mockCommand := new(mocks.CustomCommand) customExecCommand = mockCommand.Execute @@ -67,6 +75,6 @@ func TestNewSubscriptionsErr(t *testing.T) { subs, err := NewSubscriptions() - assert.Equal(t, Subscriptions(nil), subs) - assert.EqualError(t, err, "exec: \"error\": executable file not found in $PATH") + suite.Equal(Subscriptions(nil), subs) + suite.EqualError(err, "exec: \"error\": executable file not found in $PATH") }