1
1
import http from "k6/http" ;
2
2
import { check } from "k6" ;
3
- import names from "./names.js" ;
4
3
5
- const baseUri = `http://petclinic:9966/petclinic/api ` ;
4
+ const baseUri = `http://vehicle-service:8001/vehicle-inventory/ ` ;
6
5
7
6
export default function ( ) {
8
- const specialtiesUrl = `${ baseUri } /specialties` ;
9
- const specialtiesResponse = http . get ( specialtiesUrl ) ;
10
- const specialties = JSON . parse ( specialtiesResponse . body ) ;
11
-
12
- // Add a new vet to the list
13
- const newVet = names . randomVet ( specialties ) ;
14
- const response = http . post ( `${ baseUri } /vets` , JSON . stringify ( newVet ) ,
15
- { headers : { 'Content-Type' : 'application/json' } } ) ;
16
- // we don't guard against dupes, so this could fail on occasion
17
- check ( response , { "create vet status 201" : ( r ) => r . status === 201 } ) ;
18
-
19
- // make sure we can fetch that vet back out
20
- const vetId = JSON . parse ( response . body ) . id ;
21
- const vetUrl = `${ baseUri } /vets/${ vetId } `
22
- const vetResponse = http . get ( vetUrl ) ;
23
- check ( vetResponse , { "fetch vet status 200" : r => r . status === 200 } ) ;
24
-
25
- // add a new owner
26
- const newOwner = names . randomOwner ( ) ;
27
- const newOwnerResponse = http . post ( `${ baseUri } /owners` , JSON . stringify ( newOwner ) ,
28
- { headers : { 'Content-Type' : 'application/json' } } ) ;
29
- check ( newOwnerResponse , { "new owner status 201" : r => r . status === 201 } ) ;
30
-
31
- // make sure we can fetch that owner back out
32
- const ownerId = JSON . parse ( newOwnerResponse . body ) . id ;
33
- const ownerResponse = http . get ( `${ baseUri } /owners/${ ownerId } ` ) ;
34
- check ( ownerResponse , { "fetch new owner status 200" : r => r . status === 200 } ) ;
35
- const owner = JSON . parse ( ownerResponse . body ) ;
36
-
37
- // get the list of all pet types
38
- const petTypes = JSON . parse ( http . get ( `${ baseUri } /pettypes` ) . body ) ;
39
- const owners = JSON . parse ( http . get ( `${ baseUri } /owners` ) . body ) ;
40
-
41
- // create a 3 new random pets
42
- const pet1 = names . randomPet ( petTypes , owner ) ;
43
- const pet2 = names . randomPet ( petTypes , owner ) ;
44
- const pet3 = names . randomPet ( petTypes , owner ) ;
45
-
46
- const petsUrl = `${ baseUri } /pets` ;
47
- const newPetResponses = http . batch ( [
48
- [ "POST" , petsUrl , JSON . stringify ( pet1 ) , { headers : { 'Content-Type' : 'application/json' } } ] ,
49
- [ "POST" , petsUrl , JSON . stringify ( pet2 ) , { headers : { 'Content-Type' : 'application/json' } } ] ,
50
- [ "POST" , petsUrl , JSON . stringify ( pet3 ) , { headers : { 'Content-Type' : 'application/json' } } ] ,
51
- ] ) ;
52
- check ( newPetResponses [ 0 ] , { "pet status 201" : r => r . status === 201 } ) ;
53
- check ( newPetResponses [ 1 ] , { "pet status 201" : r => r . status === 201 } ) ;
54
- check ( newPetResponses [ 2 ] , { "pet status 201" : r => r . status === 201 } ) ;
55
-
56
- const responses = http . batch ( [
57
- [ "GET" , `${ baseUri } /pets/${ JSON . parse ( newPetResponses [ 0 ] . body ) . id } ` ] ,
58
- [ "GET" , `${ baseUri } /pets/${ JSON . parse ( newPetResponses [ 1 ] . body ) . id } ` ] ,
59
- [ "GET" , `${ baseUri } /pets/${ JSON . parse ( newPetResponses [ 2 ] . body ) . id } ` ]
60
- ] ) ;
61
- check ( responses [ 0 ] , { "pet exists 200" : r => r . status === 200 } ) ;
62
- check ( responses [ 1 ] , { "pet exists 200" : r => r . status === 200 } ) ;
63
- check ( responses [ 2 ] , { "pet exists 200" : r => r . status === 200 } ) ;
64
-
65
- // Clean up after ourselves.
66
- // Delete pets
67
- const petDeletes = http . batch ( [
68
- [ "DELETE" , `${ baseUri } /pets/${ JSON . parse ( newPetResponses [ 0 ] . body ) . id } ` ] ,
69
- [ "DELETE" , `${ baseUri } /pets/${ JSON . parse ( newPetResponses [ 1 ] . body ) . id } ` ] ,
70
- [ "DELETE" , `${ baseUri } /pets/${ JSON . parse ( newPetResponses [ 2 ] . body ) . id } ` ]
71
- ] ) ;
72
-
73
- check ( petDeletes [ 0 ] , { "pet deleted 204" : r => r . status === 204 } ) ;
74
- check ( petDeletes [ 1 ] , { "pet deleted 204" : r => r . status === 204 } ) ;
75
- check ( petDeletes [ 2 ] , { "pet deleted 204" : r => r . status === 204 } ) ;
76
-
77
- // Delete owner
78
- const delOwner = http . del ( `${ baseUri } /owners/${ ownerId } ` ) ;
79
- check ( delOwner , { "owner deleted 204" : r => r . status === 204 } ) ;
80
-
81
- // Delete vet
82
- const delVet = http . del ( `${ baseUri } /vets/${ vetId } ` ) ;
83
- check ( delVet , { "owner deleted 204" : r => r . status === 204 } ) ;
84
-
85
- //TODO: Set up a visit or two
86
- //TODO: Fetch out the owner again because their model has been updated.
87
7
8
+ /**
9
+ * TODO: Test all APIs
10
+ * * Some invalid API
11
+ * * GET /vehicle-inventory/
12
+ * * POST /vehicle-inventory/
13
+ * * GET /vehicle-inventory/<int>
14
+ * * DELETE /vehicle-inventory/<int>
15
+ * * GET /vehicle-inventory/name/<str>
16
+ * * GET /vehicle-inventory/<int>/image
17
+ * * GET /vehicle-inventory/image/<image_name>
18
+ * * POST /vehicle-inventory/image/<image_name>
19
+ * * GET /vehicle-inventory/history/
20
+ * * POST /vehicle-inventory/history/
21
+ * * GET /vehicle-inventory/history/<int>
22
+ * * DELETE /vehicle-inventory/history/<int>
23
+ * * GET /vehicle-inventory/history/<int>/vehicle
24
+ *
25
+ * Below tests are basic and non-comprehensive.
26
+ */
27
+
28
+ const inventoryUrl = `${ baseUri } ` ;
29
+ const inventoryResponse = http . get ( inventoryUrl ) ;
30
+ check ( inventoryResponse , { "getInventory 2XX" : r => isStatus2XX ( r ) } ) ;
31
+
32
+ const imageUrl = `${ baseUri } image/fake-image` ;
33
+ const imageResponse = http . get ( imageUrl ) ;
34
+ check ( imageResponse , { "getImage 4XX" : r => isStatus4XX ( r ) } ) ;
35
+
36
+ function isStatus2XX ( response ) {
37
+ return response . status >= 200 && response . status <= 399
38
+ }
39
+
40
+ function isStatus4XX ( response ) {
41
+ return response . status >= 400 && response . status <= 499
42
+ }
88
43
} ;
0 commit comments