github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/cf/api/resources/applications_test.go (about) 1 package resources_test 2 3 import ( 4 "encoding/json" 5 "time" 6 7 "code.cloudfoundry.org/cli/cf/api/resources" 8 "code.cloudfoundry.org/cli/cf/models" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 ) 12 13 var _ = Describe("Application resources", func() { 14 var resource *resources.ApplicationResource 15 16 Describe("New Application", func() { 17 BeforeEach(func() { 18 resource = new(resources.ApplicationResource) 19 }) 20 21 It("Adds a packageUpdatedAt timestamp", func() { 22 err := json.Unmarshal([]byte(` 23 { 24 "metadata": { 25 "guid":"application-1-guid" 26 }, 27 "entity": { 28 "package_updated_at": "2013-10-07T16:51:07+00:00" 29 } 30 }`), &resource) 31 32 Expect(err).NotTo(HaveOccurred()) 33 34 applicationModel := resource.ToModel() 35 timestamp, err := time.Parse(eventTimestampFormat, "2013-10-07T16:51:07+00:00") 36 Expect(err).ToNot(HaveOccurred()) 37 Expect(*applicationModel.PackageUpdatedAt).To(Equal(timestamp)) 38 }) 39 }) 40 41 Describe("NewApplicationEntityFromAppParams", func() { 42 var ( 43 appParams models.AppParams 44 45 diskQuota, memory int64 46 healthCheckTimeout, instanceCount int 47 healthCheckHTTPEndpoint string 48 enableSSH bool 49 packageUpdatedAt time.Time 50 environmentVars map[string]interface{} 51 52 buildpackURL, 53 command, 54 healthCheckType, 55 dockerImage, 56 dockerUsername, 57 dockerPassword, 58 name, 59 spaceGUID, 60 stackGUID, 61 state string 62 ) 63 64 BeforeEach(func() { 65 buildpackURL = "buildpack-url" 66 command = "command" 67 diskQuota = int64(1024) 68 environmentVars = map[string]interface{}{ 69 "foo": "bar", 70 "baz": "quux", 71 } 72 healthCheckType = "none" 73 healthCheckTimeout = 5 74 healthCheckHTTPEndpoint = "/some-endpoint" 75 dockerImage = "docker-image" 76 dockerUsername = "docker-user" 77 dockerPassword = "docker-pass" 78 enableSSH = true 79 instanceCount = 5 80 memory = int64(2048) 81 name = "app-name" 82 spaceGUID = "space-guid" 83 stackGUID = "stack-guid" 84 state = "state" 85 packageUpdatedAt = time.Now() 86 87 appParams = models.AppParams{ 88 BuildpackURL: &buildpackURL, 89 Command: &command, 90 DiskQuota: &diskQuota, 91 EnvironmentVars: &environmentVars, 92 HealthCheckType: &healthCheckType, 93 HealthCheckTimeout: &healthCheckTimeout, 94 HealthCheckHTTPEndpoint: &healthCheckHTTPEndpoint, 95 DockerImage: &dockerImage, 96 DockerUsername: &dockerUsername, 97 DockerPassword: &dockerPassword, 98 EnableSSH: &enableSSH, 99 InstanceCount: &instanceCount, 100 Memory: &memory, 101 Name: &name, 102 SpaceGUID: &spaceGUID, 103 StackGUID: &stackGUID, 104 State: &state, 105 PackageUpdatedAt: &packageUpdatedAt, 106 } 107 }) 108 109 It("directly assigns some attributes", func() { 110 entity := resources.NewApplicationEntityFromAppParams(appParams) 111 Expect(*entity.Buildpack).To(Equal(buildpackURL)) 112 Expect(*entity.Name).To(Equal(name)) 113 Expect(*entity.SpaceGUID).To(Equal(spaceGUID)) 114 Expect(*entity.Instances).To(Equal(instanceCount)) 115 Expect(*entity.Memory).To(Equal(memory)) 116 Expect(*entity.DiskQuota).To(Equal(diskQuota)) 117 Expect(*entity.StackGUID).To(Equal(stackGUID)) 118 Expect(*entity.Command).To(Equal(command)) 119 Expect(*entity.HealthCheckType).To(Equal(healthCheckType)) 120 Expect(*entity.HealthCheckTimeout).To(Equal(healthCheckTimeout)) 121 Expect(*entity.HealthCheckHTTPEndpoint).To(Equal(healthCheckHTTPEndpoint)) 122 Expect(*entity.DockerImage).To(Equal(dockerImage)) 123 Expect(entity.DockerCredentials.Username).To(Equal(dockerUsername)) 124 Expect(entity.DockerCredentials.Password).To(Equal(dockerPassword)) 125 Expect(*entity.EnableSSH).To(Equal(enableSSH)) 126 Expect(*entity.PackageUpdatedAt).To(Equal(packageUpdatedAt)) 127 }) 128 129 It("upcases the state", func() { 130 entity := resources.NewApplicationEntityFromAppParams(appParams) 131 Expect(*entity.State).To(Equal("STATE")) 132 }) 133 134 It("does not include environment vars when they do not exist in the params", func() { 135 appParams.EnvironmentVars = nil 136 entity := resources.NewApplicationEntityFromAppParams(appParams) 137 Expect(entity.EnvironmentJSON).To(BeNil()) 138 }) 139 }) 140 })