File: environment_tests.rb

package info (click to toggle)
ruby-fog-aws 3.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,140 kB
  • sloc: ruby: 73,328; javascript: 14; makefile: 9; sh: 4
file content (131 lines) | stat: -rw-r--r-- 3,378 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
Shindo.tests("Fog::AWS[:beanstalk] | environment", ['aws', 'beanstalk']) do

  pending if Fog.mocking?

  @beanstalk = Fog::AWS[:beanstalk]

  @application_name = uniq_id('fog-test-app')
  @environment_name = uniq_id('fog-test-env')
  @version_names = []
  # Create two unique version names
  2.times {
    @version_names << uniq_id('fog-test-version')
  }

  @application = @beanstalk.applications.create({:name => @application_name})

  @versions = []
  @version_names.each { |name|
    @versions << @beanstalk.versions.create({
                                                :label => name,
                                                :application_name => @application_name,
                                            })
  }

  @environment_opts = {
      :application_name => @application_name,
      :name => @environment_name,
      :version_label => @version_names[0],
      :solution_stack_name => '32bit Amazon Linux running Tomcat 7'
  }

  # Note: These model tests can take quite a bit of time to run, about 10 minutes typically.
  model_tests(@beanstalk.environments, @environment_opts, false) do
    # Wait for initial ready before next tests.
    tests("#ready?").succeeds do
      @instance.wait_for { ready? }
    end

    tests("#healthy?").succeeds do
      @instance.wait_for { healthy? }
    end

    test("#events") do
      # There should be some events now.
      @instance.events.length > 0
    end

    test("#version") do
      @instance.version.label == @version_names[0]
    end

    test("#version= string") do
      # Set to version 2
      @instance.version = @version_names[1]

      count = 0
      if @instance.version.label == @version_names[1]
        @instance.events.each { |event|
          if event.message == "Environment update is starting."
            count = count + 1
          end
        }
      end

      count == 1
    end

    tests("#ready? after version= string").succeeds do
      @instance.wait_for { ready? }
    end

    test("#version= version object") do
      # reset back to first version using version object
      @instance.version = @versions[0]

      count = 0
      if @instance.version.label == @version_names[0]
        @instance.events.each { |event|
          if event.message == "Environment update is starting."
            count = count + 1
          end
        }
      end

      # Pass if we have two environment updating events
      count == 2
    end

    tests("#ready? after version= version object").succeeds do
      @instance.wait_for { ready? }
    end

    test('#restart_app_server') do
      @instance.restart_app_server

      passed = false
      @instance.events.each { |event|
        if event.message == "restartAppServer is starting."
          passed = true
        end
      }
      passed
    end

    test('#rebuild') do
      @instance.rebuild
      passed = false
      @instance.events.each { |event|
        if event.message == "rebuildEnvironment is starting."
          passed = true
        end
      }
      passed
    end

    # Wait for ready or next tests may fail
    tests("#ready? after rebuild").succeeds do
      @instance.wait_for { ready? }
    end

  end

  # Wait for instance to terminate before deleting application
  tests('#terminated?').succeeds do
    @instance.wait_for { terminated? }
  end

  # delete application
  @application.destroy

end