cluster-api-provider-azure icon indicating copy to clipboard operation
cluster-api-provider-azure copied to clipboard

Show diff when spec and scope unit tests fail

Open Jont828 opened this issue 3 years ago • 2 comments

/kind feature

Describe the solution you'd like In the unit tests for scope functions, i.e. cluster_test.go, machine_test.go, and unit tests for the spec in async services, i.e. virtualmachines/spec_test.go, we try to match a generated struct with our expected values. When the values don't match, we produce an error message outputting both the expected and computed values like this.

Expected
    <network.PublicIPAddress>: {
        Response: {Response: nil},
        ExtendedLocation: nil,
        Sku: {Name: "Standard", Tier: ""},
        PublicIPAddressPropertiesFormat: {
            PublicIPAllocationMethod: "Static",
            PublicIPAddressVersion: "IPv4",
            IPConfiguration: nil,
            DNSSettings: {
                DomainNameLabel: "fakedns",
                Fqdn: "fakedns.mydomain.io",
                ReverseFqdn: nil,
            },
            DdosSettings: nil,
            IPTags: nil,
            IPAddress: nil,
            PublicIPPrefix: nil,
            IdleTimeoutInMinutes: nil,
            ResourceGUID: nil,
            ProvisioningState: "",
            ServicePublicIPAddress: nil,
            NatGateway: nil,
            MigrationPhase: "",
            LinkedPublicIPAddress: nil,
            DeleteOption: "",
        },
        Etag: nil,
        Zones: [
            "failure-domain-id-1",
            "failure-domain-id-2",
            "failure-domain-id-3",
        ],
        ID: nil,
        Name: "my-publicip",
        Type: nil,
        Location: "centralIndia",
        Tags: {
            "foo": "bar",
            "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": "owned",
            "Name": "my-publicip",
        },
    }
to equal
    <network.PublicIPAddress>: {
        Response: {Response: nil},
        ExtendedLocation: nil,
        Sku: {Name: "Standard", Tier: ""},
        PublicIPAddressPropertiesFormat: {
            PublicIPAllocationMethod: "Static",
            PublicIPAddressVersion: "IPv4",
            IPConfiguration: nil,
            DNSSettings: {
                DomainNameLabel: "fakedns",
                Fqdn: "fakedns.mydomain.io",
                ReverseFqdn: nil,
            },
            DdosSettings: nil,
            IPTags: nil,
            IPAddress: nil,
            PublicIPPrefix: nil,
            IdleTimeoutInMinutes: nil,
            ResourceGUID: nil,
            ProvisioningState: "",
            ServicePublicIPAddress: nil,
            NatGateway: nil,
            MigrationPhase: "",
            LinkedPublicIPAddress: nil,
            DeleteOption: "",
        },
        Etag: nil,
        Zones: [
            "failure-domain-id1",
            "failure-domain-id-2",
            "failure-domain-id-3",
        ],
        ID: nil,
        Name: "my-publicip",
        Type: nil,
        Location: "centralIndia",
        Tags: {
            "Name": "my-publicip",
            "sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": "owned",
            "foo": "bar",
        },
    }

However, this makes it difficult to tell which field(s) failed to match, and in the case where we compare arrays of pointers, it would just print out the address values. Instead, it would be better to show the diff between the expected and computed values using a function like cmp.Diff() which would produce a better output for the same test as follows. In this case it's easy to tell the failure is due to a typo in failure-domain-id-1.

Diff between expected result and actual result:
  network.PublicIPAddress{
      ... // 3 identical fields
      PublicIPAddressPropertiesFormat: &{PublicIPAllocationMethod: "Static", PublicIPAddressVersion: "IPv4", DNSSettings: &{DomainNameLabel: &"fakedns", Fqdn: &"fakedns.mydomain.io"}},
      Etag:                            nil,
      Zones: &[]string{
- 		"failure-domain-id1",
+ 		"failure-domain-id-1",
          "failure-domain-id-2",
          "failure-domain-id-3",
      },
      ID:   nil,
      Name: &"my-publicip",
      ... // 3 identical fields
  }

Jont828 avatar May 23 '22 22:05 Jont828

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Aug 21 '22 22:08 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

k8s-triage-robot avatar Sep 20 '22 22:09 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

k8s-triage-robot avatar Oct 20 '22 23:10 k8s-triage-robot

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

k8s-ci-robot avatar Oct 20 '22 23:10 k8s-ci-robot