@@ -5,11 +5,13 @@ import (
55 "strconv"
66
77 "code.cloudfoundry.org/cli/actor/actionerror"
8+ "code.cloudfoundry.org/cli/actor/v7action"
89 . "code.cloudfoundry.org/cli/actor/v7action"
910 "code.cloudfoundry.org/cli/actor/v7action/v7actionfakes"
1011 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
1112 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
1213 "code.cloudfoundry.org/cli/resources"
14+ "code.cloudfoundry.org/cli/types"
1315 . "github.com/onsi/ginkgo/v2"
1416 . "github.com/onsi/gomega"
1517)
@@ -397,4 +399,81 @@ var _ = Describe("Revisions Actions", func() {
397399 })
398400 })
399401 })
402+
403+ Describe ("GetEnvironmentVariableGroupByRevision" , func () {
404+ var (
405+ actor * Actor
406+ environmentVariablesGroup v7action.EnvironmentVariableGroup
407+ executeErr error
408+ fakeCloudControllerClient * v7actionfakes.FakeCloudControllerClient
409+ fakeConfig * v7actionfakes.FakeConfig
410+ isPresent bool
411+ revision resources.Revision
412+ warnings Warnings
413+ )
414+
415+ BeforeEach (func () {
416+ fakeCloudControllerClient = new (v7actionfakes.FakeCloudControllerClient )
417+ fakeConfig = new (v7actionfakes.FakeConfig )
418+ actor = NewActor (fakeCloudControllerClient , fakeConfig , nil , nil , nil , nil )
419+ revision = resources.Revision {
420+ Links : resources.APILinks {
421+ "environment_variables" : resources.APILink {
422+ HREF : "url" ,
423+ },
424+ },
425+ }
426+ fakeConfig .APIVersionReturns ("3.86.0" )
427+ })
428+
429+ JustBeforeEach (func () {
430+ environmentVariablesGroup , isPresent , warnings , executeErr = actor .GetEnvironmentVariableGroupByRevision (revision )
431+ })
432+
433+ When ("the revision does not provide HREF" , func () {
434+ BeforeEach (func () {
435+ revision = resources.Revision {}
436+ })
437+
438+ It ("returns as not present" , func () {
439+ Expect (executeErr ).To (Not (HaveOccurred ()))
440+ Expect (warnings ).To (ConsistOf ("Unable to retrieve environment variables for revision." ))
441+ Expect (isPresent ).To (Equal (false ))
442+ })
443+ })
444+
445+ When ("finding the environment variables fails" , func () {
446+ BeforeEach (func () {
447+ fakeCloudControllerClient .GetEnvironmentVariablesByURLReturns (
448+ nil ,
449+ ccv3.Warnings {"get-env-vars-warning-1" },
450+ errors .New ("get-env-vars-error-1" ),
451+ )
452+ })
453+
454+ It ("returns an error and warnings" , func () {
455+ Expect (executeErr ).To (MatchError ("get-env-vars-error-1" ))
456+ Expect (warnings ).To (ConsistOf ("get-env-vars-warning-1" ))
457+ })
458+ })
459+
460+ When ("finding the environment variables succeeds" , func () {
461+ BeforeEach (func () {
462+ fakeCloudControllerClient .GetEnvironmentVariablesByURLReturns (
463+ resources.EnvironmentVariables {"foo" : * types .NewFilteredString ("bar" )},
464+ ccv3.Warnings {"get-env-vars-warning-1" },
465+ nil ,
466+ )
467+ })
468+
469+ It ("returns the environment variables and warnings" , func () {
470+ Expect (executeErr ).ToNot (HaveOccurred ())
471+ Expect (fakeCloudControllerClient .GetEnvironmentVariablesByURLCallCount ()).To (Equal (1 ))
472+ Expect (fakeCloudControllerClient .GetEnvironmentVariablesByURLArgsForCall (0 )).To (Equal ("url" ))
473+ Expect (warnings ).To (ConsistOf ("get-env-vars-warning-1" ))
474+ Expect (len (environmentVariablesGroup )).To (Equal (1 ))
475+ Expect (environmentVariablesGroup ["foo" ].Value ).To (Equal ("bar" ))
476+ })
477+ })
478+ })
400479})
0 commit comments