github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/topgun/both/resource_check_test.go (about)

     1  package topgun_test
     2  
     3  import (
     4  	. "github.com/pf-qiu/concourse/v6/topgun/common"
     5  	_ "github.com/lib/pq"
     6  	. "github.com/onsi/ginkgo"
     7  	. "github.com/onsi/gomega"
     8  )
     9  
    10  var _ = Describe("Resource checking", func() {
    11  	Context("with a global worker and a tagged", func() {
    12  		BeforeEach(func() {
    13  			Deploy("deployments/concourse.yml",
    14  				"-o", "operations/add-other-worker.yml",
    15  				"-o", "operations/tagged-worker.yml")
    16  		})
    17  
    18  		Describe("tagged resources", func() {
    19  			BeforeEach(func() {
    20  				By("setting a pipeline that has a tagged resource")
    21  				Fly.Run("set-pipeline", "-n", "-c", "pipelines/tagged-resource.yml", "-p", "tagged-resource")
    22  
    23  				By("unpausing the pipeline pipeline")
    24  				Fly.Run("unpause-pipeline", "-p", "tagged-resource")
    25  			})
    26  
    27  			It("places and finds the checking container on the tagged worker", func() {
    28  				By("running the check")
    29  				Fly.Run("check-resource", "-r", "tagged-resource/some-resource")
    30  
    31  				By("getting the worker name")
    32  				workersTable := FlyTable("workers")
    33  				var taggedWorkerName string
    34  				for _, w := range workersTable {
    35  					if w["tags"] == "tagged" {
    36  						taggedWorkerName = w["name"]
    37  					}
    38  				}
    39  				Expect(taggedWorkerName).ToNot(BeEmpty())
    40  
    41  				By("checking that the container is on the tagged worker")
    42  				containerTable := FlyTable("containers")
    43  				Expect(containerTable).To(HaveLen(1))
    44  				Expect(containerTable[0]["type"]).To(Equal("check"))
    45  				Expect(containerTable[0]["worker"]).To(Equal(taggedWorkerName))
    46  
    47  				By("running the check")
    48  				Fly.Run("check-resource", "-r", "tagged-resource/some-resource")
    49  
    50  				By("checking that the container is on the tagged worker")
    51  				containerTable = FlyTable("containers")
    52  				Expect(containerTable).To(HaveLen(1))
    53  				Expect(containerTable[0]["type"]).To(Equal("check"))
    54  				Expect(containerTable[0]["worker"]).To(Equal(taggedWorkerName))
    55  			})
    56  		})
    57  	})
    58  
    59  	Context("with a global worker and a team worker", func() {
    60  		var teamWorkerName string
    61  		var globalWorkerName string
    62  
    63  		BeforeEach(func() {
    64  			Deploy(
    65  				"deployments/concourse.yml",
    66  				"-o", "operations/add-other-worker.yml",
    67  				"-o", "operations/other-worker-team.yml",
    68  			)
    69  
    70  			Eventually(func() []map[string]string {
    71  				workersTable := FlyTable("workers")
    72  
    73  				for _, w := range workersTable {
    74  					if w["team"] == "main" {
    75  						teamWorkerName = w["name"]
    76  					} else {
    77  						globalWorkerName = w["name"]
    78  					}
    79  				}
    80  
    81  				return workersTable
    82  			}).Should(HaveLen(2))
    83  
    84  			Expect(teamWorkerName).ToNot(BeEmpty(), "team worker not found")
    85  			Expect(globalWorkerName).ToNot(BeEmpty(), "global worker not found")
    86  		})
    87  
    88  		Context("when a team WITH its own worker checks first", func() {
    89  			BeforeEach(func() {
    90  				By("setting a pipeline that has a resource")
    91  				Fly.Run("set-pipeline", "-n", "-c", "pipelines/get-resource.yml", "-p", "get-resource")
    92  
    93  				By("unpausing the pipeline")
    94  				Fly.Run("unpause-pipeline", "-p", "get-resource")
    95  
    96  				By("running the check")
    97  				Fly.Run("check-resource", "-r", "get-resource/some-resource")
    98  			})
    99  
   100  			It("places the check container on the team worker", func() {
   101  				containerTable := FlyTable("containers")
   102  				Expect(containerTable).To(HaveLen(1))
   103  				Expect(containerTable[0]["type"]).To(Equal("check"))
   104  				Expect(containerTable[0]["worker"]).To(Equal(teamWorkerName))
   105  			})
   106  
   107  			Context("when another team WITHOUT its own worker sets the same resource", func() {
   108  				BeforeEach(func() {
   109  					By("creating another team")
   110  					Fly.Run(
   111  						"set-team",
   112  						"--non-interactive",
   113  						"--team-name", "some-team",
   114  						"--local-user", "guest",
   115  					)
   116  
   117  					By("logging into other team")
   118  					Fly.Run("login", "-n", "some-team", "-u", "guest", "-p", "guest")
   119  
   120  					By("setting a pipeline that has a resource")
   121  					Fly.Run("set-pipeline", "-n", "-c", "pipelines/get-resource.yml", "-p", "get-resource")
   122  
   123  					By("unpausing the pipeline")
   124  					Fly.Run("unpause-pipeline", "-p", "get-resource")
   125  				})
   126  
   127  				It("creates a new check container on the global worker", func() {
   128  					By("running the check")
   129  					Fly.Run("check-resource", "-r", "get-resource/some-resource")
   130  
   131  					By("checking that the container is on the global worker")
   132  					containerTable := FlyTable("containers")
   133  					Expect(containerTable).To(HaveLen(1))
   134  					Expect(containerTable[0]["type"]).To(Equal("check"))
   135  					Expect(containerTable[0]["worker"]).To(Equal(globalWorkerName))
   136  				})
   137  			})
   138  		})
   139  
   140  		Context("when a team WITHOUT its own worker checks first", func() {
   141  			BeforeEach(func() {
   142  				By("creating another team")
   143  				Fly.Run(
   144  					"set-team",
   145  					"--non-interactive",
   146  					"--team-name", "some-team",
   147  					"--local-user", "guest",
   148  				)
   149  
   150  				By("logging in to the other team")
   151  				Fly.Run("login", "-n", "some-team", "-u", "guest", "-p", "guest")
   152  
   153  				By("setting a pipeline that has a resource")
   154  				Fly.Run("set-pipeline", "-n", "-c", "pipelines/get-resource.yml", "-p", "get-resource")
   155  
   156  				By("unpausing the pipeline")
   157  				Fly.Run("unpause-pipeline", "-p", "get-resource")
   158  
   159  				By("running the check")
   160  				Fly.Run("check-resource", "-r", "get-resource/some-resource")
   161  			})
   162  
   163  			It("places the check container on the global worker", func() {
   164  				containerTable := FlyTable("containers")
   165  				Expect(containerTable).To(HaveLen(1))
   166  				Expect(containerTable[0]["type"]).To(Equal("check"))
   167  				Expect(containerTable[0]["worker"]).To(Equal(globalWorkerName))
   168  			})
   169  
   170  			Context("when another team WITH its own worker sets the same resource", func() {
   171  				var globalHandle string
   172  
   173  				BeforeEach(func() {
   174  					containerTable := FlyTable("containers")
   175  					Expect(containerTable).To(HaveLen(1))
   176  					Expect(containerTable[0]["type"]).To(Equal("check"))
   177  					Expect(containerTable[0]["worker"]).To(Equal(globalWorkerName))
   178  
   179  					globalHandle = containerTable[0]["handle"]
   180  
   181  					By("logging in to the other team")
   182  					Fly.Run("login", "-n", "main", "-u", "test", "-p", "test")
   183  
   184  					By("setting a pipeline that has a resource")
   185  					Fly.Run("set-pipeline", "-n", "-c", "pipelines/get-resource.yml", "-p", "get-resource")
   186  				})
   187  
   188  				It("creates a new check container on the team worker", func() {
   189  					By("unpausing the pipeline")
   190  					Fly.Run("unpause-pipeline", "-p", "get-resource")
   191  
   192  					By("running the check")
   193  					Fly.Run("check-resource", "-r", "get-resource/some-resource")
   194  
   195  					By("having created a new container on the team worker")
   196  					containerTable := FlyTable("containers")
   197  					Expect(containerTable).To(HaveLen(2))
   198  					for _, c := range containerTable {
   199  						if c["handle"] == globalHandle {
   200  							// this container is still visible since it's on a global worker
   201  							// and relates to the same resource config
   202  							continue
   203  						}
   204  
   205  						Expect(c["type"]).To(Equal("check"))
   206  						Expect(c["worker"]).To(Equal(teamWorkerName))
   207  					}
   208  				})
   209  			})
   210  		})
   211  	})
   212  })