github.com/gophercloud/gophercloud@v1.11.0/openstack/networking/v2/extensions/trunks/testing/fixtures_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/trunks"
     7  )
     8  
     9  const CreateRequest = `
    10  {
    11    "trunk": {
    12      "admin_state_up": true,
    13      "description": "Trunk created by gophercloud",
    14      "name": "gophertrunk",
    15      "port_id": "c373d2fa-3d3b-4492-924c-aff54dea19b6",
    16      "sub_ports": [
    17        {
    18          "port_id": "28e452d7-4f8a-4be4-b1e6-7f3db4c0430b",
    19          "segmentation_id": 1,
    20          "segmentation_type": "vlan"
    21        },
    22        {
    23          "port_id": "4c8b2bff-9824-4d4c-9b60-b3f6621b2bab",
    24          "segmentation_id": 2,
    25          "segmentation_type": "vlan"
    26        }
    27      ]
    28    }
    29  }`
    30  
    31  const CreateResponse = `
    32  {
    33    "trunk": {
    34      "admin_state_up": true,
    35      "created_at": "2018-10-03T13:57:24Z",
    36      "description": "Trunk created by gophercloud",
    37      "id": "f6a9718c-5a64-43e3-944f-4deccad8e78c",
    38      "name": "gophertrunk",
    39      "port_id": "c373d2fa-3d3b-4492-924c-aff54dea19b6",
    40      "project_id": "e153f3f9082240a5974f667cfe1036e3",
    41      "revision_number": 1,
    42      "status": "ACTIVE",
    43      "sub_ports": [
    44        {
    45          "port_id": "28e452d7-4f8a-4be4-b1e6-7f3db4c0430b",
    46          "segmentation_id": 1,
    47          "segmentation_type": "vlan"
    48        },
    49        {
    50          "port_id": "4c8b2bff-9824-4d4c-9b60-b3f6621b2bab",
    51          "segmentation_id": 2,
    52          "segmentation_type": "vlan"
    53        }
    54      ],
    55      "tags": [],
    56      "tenant_id": "e153f3f9082240a5974f667cfe1036e3",
    57      "updated_at": "2018-10-03T13:57:26Z"
    58    }
    59  }`
    60  
    61  const CreateNoSubportsRequest = `
    62  {
    63    "trunk": {
    64      "admin_state_up": true,
    65      "description": "Trunk created by gophercloud",
    66      "name": "gophertrunk",
    67      "port_id": "c373d2fa-3d3b-4492-924c-aff54dea19b6",
    68      "sub_ports": []
    69    }
    70  }`
    71  
    72  const CreateNoSubportsResponse = `
    73  {
    74    "trunk": {
    75      "admin_state_up": true,
    76      "created_at": "2018-10-03T13:57:24Z",
    77      "description": "Trunk created by gophercloud",
    78      "id": "f6a9718c-5a64-43e3-944f-4deccad8e78c",
    79      "name": "gophertrunk",
    80      "port_id": "c373d2fa-3d3b-4492-924c-aff54dea19b6",
    81      "project_id": "e153f3f9082240a5974f667cfe1036e3",
    82      "revision_number": 1,
    83      "status": "ACTIVE",
    84      "sub_ports": [],
    85      "tags": [],
    86      "tenant_id": "e153f3f9082240a5974f667cfe1036e3",
    87      "updated_at": "2018-10-03T13:57:26Z"
    88    }
    89  }`
    90  
    91  const ListResponse = `
    92  {
    93    "trunks": [
    94      {
    95        "admin_state_up": true,
    96        "created_at": "2018-10-01T15:29:39Z",
    97        "description": "",
    98        "id": "3e72aa1b-d0da-48f2-831a-fd1c5f3f99c2",
    99        "name": "mytrunk",
   100        "port_id": "16c425d3-d7fc-40b8-b94c-cc95da45b270",
   101        "project_id": "e153f3f9082240a5974f667cfe1036e3",
   102        "revision_number": 3,
   103        "status": "ACTIVE",
   104        "sub_ports": [
   105          {
   106            "port_id": "424da4b7-7868-4db2-bb71-05155601c6e4",
   107            "segmentation_id": 11,
   108            "segmentation_type": "vlan"
   109          }
   110        ],
   111        "tags": [],
   112        "tenant_id": "e153f3f9082240a5974f667cfe1036e3",
   113        "updated_at": "2018-10-01T15:43:04Z"
   114      },
   115      {
   116        "admin_state_up": true,
   117        "created_at": "2018-10-03T13:57:24Z",
   118        "description": "Trunk created by gophercloud",
   119        "id": "f6a9718c-5a64-43e3-944f-4deccad8e78c",
   120        "name": "gophertrunk",
   121        "port_id": "c373d2fa-3d3b-4492-924c-aff54dea19b6",
   122        "project_id": "e153f3f9082240a5974f667cfe1036e3",
   123        "revision_number": 1,
   124        "status": "ACTIVE",
   125        "sub_ports": [
   126          {
   127            "port_id": "28e452d7-4f8a-4be4-b1e6-7f3db4c0430b",
   128            "segmentation_id": 1,
   129            "segmentation_type": "vlan"
   130          },
   131          {
   132            "port_id": "4c8b2bff-9824-4d4c-9b60-b3f6621b2bab",
   133            "segmentation_id": 2,
   134            "segmentation_type": "vlan"
   135          }
   136        ],
   137        "tags": [],
   138        "tenant_id": "e153f3f9082240a5974f667cfe1036e3",
   139        "updated_at": "2018-10-03T13:57:26Z"
   140      }
   141    ]
   142  }`
   143  
   144  const GetResponse = `
   145  {
   146    "trunk": {
   147      "admin_state_up": true,
   148      "created_at": "2018-10-03T13:57:24Z",
   149      "description": "Trunk created by gophercloud",
   150      "id": "f6a9718c-5a64-43e3-944f-4deccad8e78c",
   151      "name": "gophertrunk",
   152      "port_id": "c373d2fa-3d3b-4492-924c-aff54dea19b6",
   153      "project_id": "e153f3f9082240a5974f667cfe1036e3",
   154      "revision_number": 1,
   155      "status": "ACTIVE",
   156      "sub_ports": [
   157        {
   158          "port_id": "28e452d7-4f8a-4be4-b1e6-7f3db4c0430b",
   159          "segmentation_id": 1,
   160          "segmentation_type": "vlan"
   161        },
   162        {
   163          "port_id": "4c8b2bff-9824-4d4c-9b60-b3f6621b2bab",
   164          "segmentation_id": 2,
   165          "segmentation_type": "vlan"
   166        }
   167      ],
   168      "tags": [],
   169      "tenant_id": "e153f3f9082240a5974f667cfe1036e3",
   170      "updated_at": "2018-10-03T13:57:26Z"
   171    }
   172  }`
   173  
   174  const UpdateRequest = `
   175  {
   176    "trunk": {
   177      "admin_state_up": false,
   178      "description": "gophertrunk updated by gophercloud",
   179      "name": "updated_gophertrunk"
   180    }
   181  }`
   182  
   183  const UpdateResponse = `
   184  {
   185    "trunk": {
   186      "admin_state_up": false,
   187      "created_at": "2018-10-03T13:57:24Z",
   188      "description": "gophertrunk updated by gophercloud",
   189      "id": "f6a9718c-5a64-43e3-944f-4deccad8e78c",
   190      "name": "updated_gophertrunk",
   191      "port_id": "c373d2fa-3d3b-4492-924c-aff54dea19b6",
   192      "project_id": "e153f3f9082240a5974f667cfe1036e3",
   193      "revision_number": 6,
   194      "status": "ACTIVE",
   195      "sub_ports": [
   196        {
   197          "port_id": "28e452d7-4f8a-4be4-b1e6-7f3db4c0430b",
   198          "segmentation_id": 1,
   199          "segmentation_type": "vlan"
   200        },
   201        {
   202          "port_id": "4c8b2bff-9824-4d4c-9b60-b3f6621b2bab",
   203          "segmentation_id": 2,
   204          "segmentation_type": "vlan"
   205        }
   206      ],
   207      "tags": [],
   208      "tenant_id": "e153f3f9082240a5974f667cfe1036e3",
   209      "updated_at": "2018-10-03T13:57:33Z"
   210    }
   211  }`
   212  
   213  const ListSubportsResponse = `
   214  {
   215    "sub_ports": [
   216      {
   217        "port_id": "28e452d7-4f8a-4be4-b1e6-7f3db4c0430b",
   218        "segmentation_id": 1,
   219        "segmentation_type": "vlan"
   220      },
   221      {
   222        "port_id": "4c8b2bff-9824-4d4c-9b60-b3f6621b2bab",
   223        "segmentation_id": 2,
   224        "segmentation_type": "vlan"
   225      }
   226    ]
   227  }`
   228  
   229  const AddSubportsRequest = ListSubportsResponse
   230  
   231  const AddSubportsResponse = `
   232  {
   233    "admin_state_up": true,
   234    "created_at": "2018-10-03T13:57:24Z",
   235    "description": "Trunk created by gophercloud",
   236    "id": "f6a9718c-5a64-43e3-944f-4deccad8e78c",
   237    "name": "gophertrunk",
   238    "port_id": "c373d2fa-3d3b-4492-924c-aff54dea19b6",
   239    "project_id": "e153f3f9082240a5974f667cfe1036e3",
   240    "revision_number": 2,
   241    "status": "ACTIVE",
   242    "sub_ports": [
   243      {
   244        "port_id": "28e452d7-4f8a-4be4-b1e6-7f3db4c0430b",
   245        "segmentation_id": 1,
   246        "segmentation_type": "vlan"
   247      },
   248      {
   249        "port_id": "4c8b2bff-9824-4d4c-9b60-b3f6621b2bab",
   250        "segmentation_id": 2,
   251        "segmentation_type": "vlan"
   252      }
   253    ],
   254    "tags": [],
   255    "tenant_id": "e153f3f9082240a5974f667cfe1036e3",
   256    "updated_at": "2018-10-03T13:57:30Z"
   257  }`
   258  
   259  const RemoveSubportsRequest = `
   260  {
   261    "sub_ports": [
   262      {
   263        "port_id": "28e452d7-4f8a-4be4-b1e6-7f3db4c0430b"
   264      },
   265      {
   266        "port_id": "4c8b2bff-9824-4d4c-9b60-b3f6621b2bab"
   267      }
   268    ]
   269  }`
   270  
   271  const RemoveSubportsResponse = `
   272  {
   273    "admin_state_up": true,
   274    "created_at": "2018-10-03T13:57:24Z",
   275    "description": "Trunk created by gophercloud",
   276    "id": "f6a9718c-5a64-43e3-944f-4deccad8e78c",
   277    "name": "gophertrunk",
   278    "port_id": "c373d2fa-3d3b-4492-924c-aff54dea19b6",
   279    "project_id": "e153f3f9082240a5974f667cfe1036e3",
   280    "revision_number": 2,
   281    "status": "ACTIVE",
   282    "sub_ports": [],
   283    "tags": [],
   284    "tenant_id": "e153f3f9082240a5974f667cfe1036e3",
   285    "updated_at": "2018-10-03T13:57:27Z"
   286  }`
   287  
   288  var ExpectedSubports = []trunks.Subport{
   289  	{
   290  		PortID:           "28e452d7-4f8a-4be4-b1e6-7f3db4c0430b",
   291  		SegmentationID:   1,
   292  		SegmentationType: "vlan",
   293  	},
   294  	{
   295  		PortID:           "4c8b2bff-9824-4d4c-9b60-b3f6621b2bab",
   296  		SegmentationID:   2,
   297  		SegmentationType: "vlan",
   298  	},
   299  }
   300  
   301  func ExpectedTrunkSlice() (exp []trunks.Trunk, err error) {
   302  	trunk1CreatedAt, err := time.Parse(time.RFC3339, "2018-10-01T15:29:39Z")
   303  	if err != nil {
   304  		return nil, err
   305  	}
   306  
   307  	trunk1UpdatedAt, err := time.Parse(time.RFC3339, "2018-10-01T15:43:04Z")
   308  	if err != nil {
   309  		return nil, err
   310  	}
   311  	exp = make([]trunks.Trunk, 2)
   312  	exp[0] = trunks.Trunk{
   313  		AdminStateUp:   true,
   314  		Description:    "",
   315  		ID:             "3e72aa1b-d0da-48f2-831a-fd1c5f3f99c2",
   316  		Name:           "mytrunk",
   317  		PortID:         "16c425d3-d7fc-40b8-b94c-cc95da45b270",
   318  		ProjectID:      "e153f3f9082240a5974f667cfe1036e3",
   319  		TenantID:       "e153f3f9082240a5974f667cfe1036e3",
   320  		RevisionNumber: 3,
   321  		Status:         "ACTIVE",
   322  		Subports: []trunks.Subport{
   323  			{
   324  				PortID:           "424da4b7-7868-4db2-bb71-05155601c6e4",
   325  				SegmentationID:   11,
   326  				SegmentationType: "vlan",
   327  			},
   328  		},
   329  		Tags:      []string{},
   330  		CreatedAt: trunk1CreatedAt,
   331  		UpdatedAt: trunk1UpdatedAt,
   332  	}
   333  
   334  	trunk2CreatedAt, err := time.Parse(time.RFC3339, "2018-10-03T13:57:24Z")
   335  	if err != nil {
   336  		return nil, err
   337  	}
   338  
   339  	trunk2UpdatedAt, err := time.Parse(time.RFC3339, "2018-10-03T13:57:26Z")
   340  	if err != nil {
   341  		return nil, err
   342  	}
   343  	exp[1] = trunks.Trunk{
   344  		AdminStateUp:   true,
   345  		Description:    "Trunk created by gophercloud",
   346  		ID:             "f6a9718c-5a64-43e3-944f-4deccad8e78c",
   347  		Name:           "gophertrunk",
   348  		PortID:         "c373d2fa-3d3b-4492-924c-aff54dea19b6",
   349  		ProjectID:      "e153f3f9082240a5974f667cfe1036e3",
   350  		TenantID:       "e153f3f9082240a5974f667cfe1036e3",
   351  		RevisionNumber: 1,
   352  		Status:         "ACTIVE",
   353  		Subports:       ExpectedSubports,
   354  		Tags:           []string{},
   355  		CreatedAt:      trunk2CreatedAt,
   356  		UpdatedAt:      trunk2UpdatedAt,
   357  	}
   358  	return
   359  }
   360  
   361  func ExpectedSubportsAddedTrunk() (exp trunks.Trunk, err error) {
   362  	trunkUpdatedAt, err := time.Parse(time.RFC3339, "2018-10-03T13:57:30Z")
   363  	if err != nil {
   364  		return
   365  	}
   366  	expectedTrunks, err := ExpectedTrunkSlice()
   367  	if err != nil {
   368  		return
   369  	}
   370  	exp = expectedTrunks[1]
   371  	exp.RevisionNumber += 1
   372  	exp.UpdatedAt = trunkUpdatedAt
   373  	return
   374  }
   375  
   376  func ExpectedSubportsRemovedTrunk() (exp trunks.Trunk, err error) {
   377  	trunkUpdatedAt, err := time.Parse(time.RFC3339, "2018-10-03T13:57:27Z")
   378  	if err != nil {
   379  		return
   380  	}
   381  	expectedTrunks, err := ExpectedTrunkSlice()
   382  	if err != nil {
   383  		return
   384  	}
   385  	exp = expectedTrunks[1]
   386  	exp.RevisionNumber += 1
   387  	exp.UpdatedAt = trunkUpdatedAt
   388  	exp.Subports = []trunks.Subport{}
   389  	return
   390  }