github.com/openshift/installer@v1.4.17/pkg/destroy/gcp/gcp_test.go (about)

     1  package gcp
     2  
     3  import "testing"
     4  
     5  func TestGetNameFromURL(t *testing.T) {
     6  	var testCases = []struct {
     7  		item, url, expected string
     8  	}{
     9  		{
    10  			item:     "zones",
    11  			url:      "https://www.googleapis.com/compute/v1/projects/ci-op-lk2ifbjc/zones/us-central1-a",
    12  			expected: "us-central1-a",
    13  		},
    14  		{
    15  			item:     "networks",
    16  			url:      "https://www.googleapis.com/compute/v1/projects/ci-op-lk2ifbjc/global/networks/ci-op-lk2ifbjc-15937-q68kj-network",
    17  			expected: "ci-op-lk2ifbjc-15937-q68kj-network",
    18  		},
    19  	}
    20  	for _, testCase := range testCases {
    21  		t.Run(testCase.item, func(t *testing.T) {
    22  			if actual, expected := getNameFromURL(testCase.item, testCase.url), testCase.expected; actual != expected {
    23  				t.Errorf("got incorrect name %s for item %s from url %s", actual, testCase.item, testCase.url)
    24  			}
    25  		})
    26  	}
    27  }
    28  
    29  func TestGetRegionFromZone(t *testing.T) {
    30  	if actual, expected := getRegionFromZone("us-central1-a"), "us-central1"; actual != expected {
    31  		t.Errorf("got %s, not %s", actual, expected)
    32  	}
    33  }
    34  
    35  func TestGetDiskLimit(t *testing.T) {
    36  	var testCases = []struct {
    37  		url, expected string
    38  	}{
    39  		{
    40  			url:      "https://www.googleapis.com/compute/v1/projects/ci-op-lk2ifbjc/zones/us-central1-a/diskTypes/pd-standard",
    41  			expected: "disks_total_storage",
    42  		},
    43  		{
    44  			url:      "https://www.googleapis.com/compute/v1/projects/ci-op-lk2ifbjc/zones/us-central1-a/diskTypes/pd-ssd",
    45  			expected: "ssd_total_storage",
    46  		},
    47  		{
    48  			url:      "https://www.googleapis.com/compute/v1/projects/ci-op-lk2ifbjc/zones/us-central1-a/diskTypes/pd-balanced",
    49  			expected: "ssd_total_storage",
    50  		},
    51  	}
    52  	for _, testCase := range testCases {
    53  		t.Run(testCase.url, func(t *testing.T) {
    54  			if actual, expected := getDiskLimit(testCase.url), testCase.expected; actual != expected {
    55  				t.Errorf("got incorrect limit %s for url %s", actual, testCase.url)
    56  			}
    57  		})
    58  	}
    59  }