github.com/gophercloud/gophercloud@v1.11.0/openstack/containerinfra/v1/clustertemplates/testing/requests_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates"
     7  	"github.com/gophercloud/gophercloud/pagination"
     8  	th "github.com/gophercloud/gophercloud/testhelper"
     9  	fake "github.com/gophercloud/gophercloud/testhelper/client"
    10  )
    11  
    12  func TestCreateClusterTemplate(t *testing.T) {
    13  	th.SetupHTTP()
    14  	defer th.TeardownHTTP()
    15  
    16  	HandleCreateClusterTemplateSuccessfully(t)
    17  
    18  	boolFalse := false
    19  	boolTrue := true
    20  	dockerVolumeSize := 3
    21  	opts := clustertemplates.CreateOpts{
    22  		Name:                "kubernetes-dev",
    23  		Labels:              map[string]string{},
    24  		FixedSubnet:         "",
    25  		MasterFlavorID:      "",
    26  		NoProxy:             "10.0.0.0/8,172.0.0.0/8,192.0.0.0/8,localhost",
    27  		HTTPSProxy:          "http://10.164.177.169:8080",
    28  		TLSDisabled:         &boolFalse,
    29  		KeyPairID:           "kp",
    30  		Public:              &boolFalse,
    31  		HTTPProxy:           "http://10.164.177.169:8080",
    32  		DockerVolumeSize:    &dockerVolumeSize,
    33  		ServerType:          "vm",
    34  		ExternalNetworkID:   "public",
    35  		ImageID:             "Fedora-Atomic-27-20180212.2.x86_64",
    36  		VolumeDriver:        "cinder",
    37  		RegistryEnabled:     &boolFalse,
    38  		DockerStorageDriver: "devicemapper",
    39  		NetworkDriver:       "flannel",
    40  		FixedNetwork:        "",
    41  		COE:                 "kubernetes",
    42  		FlavorID:            "m1.small",
    43  		MasterLBEnabled:     &boolTrue,
    44  		DNSNameServer:       "8.8.8.8",
    45  		Hidden:              &boolTrue,
    46  	}
    47  
    48  	sc := fake.ServiceClient()
    49  	sc.Endpoint = sc.Endpoint + "v1/"
    50  	res := clustertemplates.Create(sc, opts)
    51  	th.AssertNoErr(t, res.Err)
    52  
    53  	requestID := res.Header.Get("X-OpenStack-Request-Id")
    54  	th.AssertEquals(t, "req-781e9bdc-4163-46eb-91c9-786c53188bbb", requestID)
    55  
    56  	actual, err := res.Extract()
    57  	th.AssertNoErr(t, err)
    58  
    59  	actual.CreatedAt = actual.CreatedAt.UTC()
    60  	th.AssertDeepEquals(t, ExpectedClusterTemplate, *actual)
    61  }
    62  
    63  func TestDeleteClusterTemplate(t *testing.T) {
    64  	th.SetupHTTP()
    65  	defer th.TeardownHTTP()
    66  
    67  	HandleDeleteClusterSuccessfully(t)
    68  
    69  	sc := fake.ServiceClient()
    70  	sc.Endpoint = sc.Endpoint + "v1/"
    71  	res := clustertemplates.Delete(sc, "6dc6d336e3fc4c0a951b5698cd1236ee")
    72  	th.AssertNoErr(t, res.Err)
    73  	requestID := res.Header["X-Openstack-Request-Id"][0]
    74  	th.AssertEquals(t, "req-781e9bdc-4163-46eb-91c9-786c53188bbb", requestID)
    75  }
    76  
    77  func TestListClusterTemplates(t *testing.T) {
    78  	th.SetupHTTP()
    79  	defer th.TeardownHTTP()
    80  
    81  	HandleListClusterTemplateSuccessfully(t)
    82  
    83  	count := 0
    84  
    85  	sc := fake.ServiceClient()
    86  	sc.Endpoint = sc.Endpoint + "v1/"
    87  	clustertemplates.List(sc, clustertemplates.ListOpts{Limit: 2}).EachPage(func(page pagination.Page) (bool, error) {
    88  		count++
    89  		actual, err := clustertemplates.ExtractClusterTemplates(page)
    90  		th.AssertNoErr(t, err)
    91  		for idx := range actual {
    92  			actual[idx].CreatedAt = actual[idx].CreatedAt.UTC()
    93  		}
    94  		th.AssertDeepEquals(t, ExpectedClusterTemplates, actual)
    95  
    96  		return true, nil
    97  	})
    98  
    99  	if count != 1 {
   100  		t.Errorf("Expected 1 page, got %d", count)
   101  	}
   102  }
   103  
   104  func TestGetClusterTemplate(t *testing.T) {
   105  	th.SetupHTTP()
   106  	defer th.TeardownHTTP()
   107  
   108  	HandleGetClusterTemplateSuccessfully(t)
   109  
   110  	sc := fake.ServiceClient()
   111  	sc.Endpoint = sc.Endpoint + "v1/"
   112  	actual, err := clustertemplates.Get(sc, "7d85f602-a948-4a30-afd4-e84f47471c15").Extract()
   113  	th.AssertNoErr(t, err)
   114  	actual.CreatedAt = actual.CreatedAt.UTC()
   115  	th.AssertDeepEquals(t, ExpectedClusterTemplate, *actual)
   116  }
   117  
   118  func TestGetClusterTemplateEmptyTime(t *testing.T) {
   119  	th.SetupHTTP()
   120  	defer th.TeardownHTTP()
   121  
   122  	HandleGetClusterTemplateEmptyTimeSuccessfully(t)
   123  
   124  	sc := fake.ServiceClient()
   125  	sc.Endpoint = sc.Endpoint + "v1/"
   126  	actual, err := clustertemplates.Get(sc, "7d85f602-a948-4a30-afd4-e84f47471c15").Extract()
   127  	th.AssertNoErr(t, err)
   128  	actual.CreatedAt = actual.CreatedAt.UTC()
   129  	th.AssertDeepEquals(t, ExpectedClusterTemplate_EmptyTime, *actual)
   130  }
   131  
   132  func TestUpdateClusterTemplate(t *testing.T) {
   133  	th.SetupHTTP()
   134  	defer th.TeardownHTTP()
   135  
   136  	HandleUpdateClusterTemplateSuccessfully(t)
   137  
   138  	updateOpts := []clustertemplates.UpdateOptsBuilder{
   139  		clustertemplates.UpdateOpts{
   140  			Path:  "/master_lb_enabled",
   141  			Value: "True",
   142  			Op:    clustertemplates.ReplaceOp,
   143  		},
   144  		clustertemplates.UpdateOpts{
   145  			Path:  "/registry_enabled",
   146  			Value: "True",
   147  			Op:    clustertemplates.ReplaceOp,
   148  		},
   149  	}
   150  
   151  	sc := fake.ServiceClient()
   152  	sc.Endpoint = sc.Endpoint + "v1/"
   153  	res := clustertemplates.Update(sc, "7d85f602-a948-4a30-afd4-e84f47471c15", updateOpts)
   154  	th.AssertNoErr(t, res.Err)
   155  
   156  	actual, err := res.Extract()
   157  	th.AssertNoErr(t, err)
   158  	actual.CreatedAt = actual.CreatedAt.UTC()
   159  	th.AssertDeepEquals(t, ExpectedUpdateClusterTemplate, *actual)
   160  }
   161  
   162  func TestUpdateClusterTemplateEmptyTime(t *testing.T) {
   163  	th.SetupHTTP()
   164  	defer th.TeardownHTTP()
   165  
   166  	HandleUpdateClusterTemplateEmptyTimeSuccessfully(t)
   167  
   168  	updateOpts := []clustertemplates.UpdateOptsBuilder{
   169  		clustertemplates.UpdateOpts{
   170  			Op:    clustertemplates.ReplaceOp,
   171  			Path:  "/master_lb_enabled",
   172  			Value: "True",
   173  		},
   174  		clustertemplates.UpdateOpts{
   175  			Op:    clustertemplates.ReplaceOp,
   176  			Path:  "/registry_enabled",
   177  			Value: "True",
   178  		},
   179  	}
   180  
   181  	sc := fake.ServiceClient()
   182  	sc.Endpoint = sc.Endpoint + "v1/"
   183  	actual, err := clustertemplates.Update(sc, "7d85f602-a948-4a30-afd4-e84f47471c15", updateOpts).Extract()
   184  	th.AssertNoErr(t, err)
   185  	th.AssertDeepEquals(t, ExpectedUpdateClusterTemplate_EmptyTime, *actual)
   186  }
   187  
   188  func TestUpdateClusterTemplateInvalidUpdate(t *testing.T) {
   189  	th.SetupHTTP()
   190  	defer th.TeardownHTTP()
   191  
   192  	HandleUpdateClusterTemplateInvalidUpdate(t)
   193  
   194  	updateOpts := []clustertemplates.UpdateOptsBuilder{
   195  		clustertemplates.UpdateOpts{
   196  			Op:   clustertemplates.ReplaceOp,
   197  			Path: "/master_lb_enabled",
   198  		},
   199  		clustertemplates.UpdateOpts{
   200  			Op:   clustertemplates.RemoveOp,
   201  			Path: "/master_lb_enabled",
   202  		},
   203  		clustertemplates.UpdateOpts{
   204  			Op:   clustertemplates.AddOp,
   205  			Path: "/master_lb_enabled",
   206  		},
   207  	}
   208  
   209  	sc := fake.ServiceClient()
   210  	sc.Endpoint = sc.Endpoint + "v1/"
   211  	_, err := clustertemplates.Update(sc, "7d85f602-a948-4a30-afd4-e84f47471c15", updateOpts).Extract()
   212  	th.AssertEquals(t, true, err != nil)
   213  }