|
5 | 5 | "testing" |
6 | 6 |
|
7 | 7 | "github.com/hashicorp/terraform-plugin-sdk/helper/schema" |
| 8 | + "github.com/rancher/norman/types" |
8 | 9 | managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" |
9 | 10 | ) |
10 | 11 |
|
@@ -650,3 +651,114 @@ func TestReadPreservedClusterTemplateAnswers(t *testing.T) { |
650 | 651 | expectedOutput, result) |
651 | 652 | } |
652 | 653 | } |
| 654 | + |
| 655 | +func TestFlattenClusterNodes(t *testing.T) { |
| 656 | + |
| 657 | + testClusterNodes := []managementClient.Node{ |
| 658 | + { |
| 659 | + Resource: types.Resource{ |
| 660 | + ID: "id", |
| 661 | + }, |
| 662 | + Annotations: map[string]string{ |
| 663 | + "node_one": "one", |
| 664 | + "node_two": "two", |
| 665 | + }, |
| 666 | + ClusterID: "cluster_id", |
| 667 | + Capacity: map[string]string{ |
| 668 | + "cpu": "4", |
| 669 | + "memory": "8156056Ki", |
| 670 | + "pods": "110", |
| 671 | + }, |
| 672 | + ControlPlane: true, |
| 673 | + Etcd: true, |
| 674 | + ExternalIPAddress: "172.18.0.5", |
| 675 | + Hostname: "hostname", |
| 676 | + IPAddress: "172.18.0.5", |
| 677 | + Info: &managementClient.NodeInfo{ |
| 678 | + CPU: &managementClient.CPUInfo{ |
| 679 | + Count: 4, |
| 680 | + }, |
| 681 | + Kubernetes: &managementClient.KubernetesInfo{ |
| 682 | + KubeProxyVersion: "v1.19.7", |
| 683 | + KubeletVersion: "v1.19.7", |
| 684 | + }, |
| 685 | + Memory: &managementClient.MemoryInfo{ |
| 686 | + MemTotalKiB: 8156056, |
| 687 | + }, |
| 688 | + OS: &managementClient.OSInfo{ |
| 689 | + DockerVersion: "containerd://1.4.3", |
| 690 | + KernelVersion: "4.19.121", |
| 691 | + OperatingSystem: "Unknown", |
| 692 | + }, |
| 693 | + }, |
| 694 | + Labels: map[string]string{ |
| 695 | + "option1": "value1", |
| 696 | + "option2": "value2", |
| 697 | + }, |
| 698 | + Name: "name", |
| 699 | + NodeName: "node_name", |
| 700 | + NodePoolID: "node_pool_id", |
| 701 | + NodeTemplateID: "node_template_id", |
| 702 | + ProviderId: "provider_id", |
| 703 | + RequestedHostname: "requested_hostname", |
| 704 | + SshUser: "ssh_user", |
| 705 | + Worker: true, |
| 706 | + }, |
| 707 | + } |
| 708 | + |
| 709 | + testClusterNodesInterface := []interface{}{ |
| 710 | + map[string]interface{}{ |
| 711 | + "id": "id", |
| 712 | + "annotations": map[string]interface{}{ |
| 713 | + "node_one": "one", |
| 714 | + "node_two": "two", |
| 715 | + }, |
| 716 | + "capacity": map[string]interface{}{ |
| 717 | + "cpu": "4", |
| 718 | + "memory": "8156056Ki", |
| 719 | + "pods": "110", |
| 720 | + }, |
| 721 | + "cluster_id": "cluster_id", |
| 722 | + "external_ip_address": "172.18.0.5", |
| 723 | + "hostname": "hostname", |
| 724 | + "ip_address": "172.18.0.5", |
| 725 | + "system_info": map[string]string{ |
| 726 | + "kube_proxy_version": "v1.19.7", |
| 727 | + "kubelet_version": "v1.19.7", |
| 728 | + "container_runtime_version": "containerd://1.4.3", |
| 729 | + "kernel_version": "4.19.121", |
| 730 | + "operating_system": "Unknown", |
| 731 | + }, |
| 732 | + "labels": map[string]interface{}{ |
| 733 | + "option1": "value1", |
| 734 | + "option2": "value2", |
| 735 | + }, |
| 736 | + "name": "node_name", |
| 737 | + "node_pool_id": "node_pool_id", |
| 738 | + "node_template_id": "node_template_id", |
| 739 | + "provider_id": "provider_id", |
| 740 | + "roles": []string{"control_plane", "etcd", "worker"}, |
| 741 | + "requested_hostname": "requested_hostname", |
| 742 | + "ssh_user": "ssh_user", |
| 743 | + }, |
| 744 | + } |
| 745 | + |
| 746 | + cases := []struct { |
| 747 | + Input []managementClient.Node |
| 748 | + ExpectedOutput []interface{} |
| 749 | + }{ |
| 750 | + { |
| 751 | + Input: testClusterNodes, |
| 752 | + ExpectedOutput: testClusterNodesInterface, |
| 753 | + }, |
| 754 | + } |
| 755 | + |
| 756 | + for _, tc := range cases { |
| 757 | + output := flattenClusterNodes(tc.Input) |
| 758 | + if !reflect.DeepEqual(output, tc.ExpectedOutput) { |
| 759 | + t.Fatalf("Unexpected output from flattener.\nExpected: %#v\nGiven: %#v", |
| 760 | + tc.ExpectedOutput, output) |
| 761 | + } |
| 762 | + } |
| 763 | + |
| 764 | +} |
0 commit comments