Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terraform_azure_example_test.go Type Issue #522

Open
neal-shah opened this issue May 16, 2020 · 7 comments
Open

terraform_azure_example_test.go Type Issue #522

neal-shah opened this issue May 16, 2020 · 7 comments
Labels
Azure bug Something isn't working

Comments

@neal-shah
Copy link

I am running the example test in terraform_azure_example_test.go, however I'm getting the following test failure:

--- FAIL: TestAzVirtualMachine (28.83s)
    virtual_machine_test.go:51: 
        	Error Trace:	virtual_machine_test.go:51
        	Error:      	Not equal: 
        	            	expected: compute.VirtualMachineSizeTypes("Standard_D2s_v3")
        	            	actual  : compute.VirtualMachineSizeTypes("Standard_D2s_v3")
        	Test:       	TestAzVirtualMachine
FAIL
import (
	"os"
	"testing"

	"github.com/Azure/azure-sdk-for-go/profiles/latest/compute/mgmt/compute"
	"github.com/gruntwork-io/terratest/modules/azure"
	"github.com/gruntwork-io/terratest/modules/terraform"
	"github.com/stretchr/testify/assert"
)

func TestAzVirtualMachine(t *testing.T) {
	t.Parallel()

	subscriptionID := getTargetAzureSubscription("")

	terraformOptions := &terraform.Options{
		TerraformDir: "../fixtures/az-virtual-machine",
	}

	// defer terraform.Destroy(t, terraformOptions)

	terraform.InitAndApply(t, terraformOptions)

	vmName := terraform.OutputList(t, terraformOptions, "vm_name")[0]
	resourceGroupName := terraform.Output(t, terraformOptions, "resource_group_name")

	actualVMSize := azure.GetSizeOfVirtualMachine(t, vmName, resourceGroupName, subscriptionID)
	expectedVMSize := compute.VirtualMachineSizeTypes(compute.VirtualMachineSizeTypesStandardD2sV3)

	assert.Equal(t, expectedVMSize, actualVMSize)
}

Go: 1.14.2 darwin/amd64
Terraform: v0.12.24

Any idea's?

@yorinasub17 yorinasub17 added bug Something isn't working help wanted labels May 21, 2020
@brikis98
Copy link
Member

Definitely looks like a bug in the test!

Could you use the reflect library to print out the types of the expected and actual vars? Perhaps one is wrapped in some struct that is causing the equal check to fail (even though the string versions look identical).

@brikis98 brikis98 added the Azure label Jun 26, 2020
@brikis98
Copy link
Member

Please see #89 for the status on Terratest with Azure. In particular, we're starting some work around it, and when that work is done, we'll be able to come back to this question!

@davesee
Copy link
Contributor

davesee commented Feb 6, 2021

Hi @neal-shah,

Are you still having the problem with the assert failing?

There have been several updates to the Azure compute module since then and I would like to help if needed.

@neal-shah
Copy link
Author

Hey @davesee,

Apologies it's been a while since I looked at this! I'll try and find some time hopefully in the next week or so, and let you know! I've been working on AWS and GCP recently so have left Azure on the back-burner.

Cheers!

@mjooz
Copy link

mjooz commented Mar 25, 2021

Hi @davesee,

I just run into above problem with the virtual machine example test. Names are the same but comparison fails.
I addition, "DiskStorageAccountTypes" test fails with the same behavior :

Error: Not equal:
expected: compute.DiskStorageAccountTypes("StandardSSD_LRS")
actual : compute.DiskStorageAccountTypes("StandardSSD_LRS")

Both errors come from the compute library from azure-sdk-for-go.
While upstream packages are on v52.6.0 version, version in Terratest is still v46.0.0.

Can this be the reason?

@davesee
Copy link
Contributor

davesee commented Mar 25, 2021

Hey @mjooz

The sdk package version should not matter since both module and test use the same version. You can update them and try of course.

I ran both _example and _vm_example and was not able to reproduce the error. I added this to see the types, perhaps see if you get something other than string. Also you can try the assert.EqualValues to be less strict.

a := reflect.ValueOf(actualVMSize)
fmt.Println("Actual VM Size is of type:", a.Kind())

e := reflect.ValueOf(expectedVMSize)
fmt.Println("Expected VM Size is of type:", e.Kind())

assert.EqualValues(t, expectedVMSize, actualVMSize)

results

Actual VM Size is of type: string
Expected VM Size is of type: string
--- PASS: TestTerraformAzureExample 

Hope this helps!

@mjooz
Copy link

mjooz commented Mar 30, 2021

Hi @davesee,

issue was (and still is) with Go version and stretchr/testify package - errors from above are present if Go 1.16.2 is used.
It works fine with Go 1.14.15 or 1.15.10. That's good enough for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants