github.com/chenbh/concourse/v6@v6.4.2/atc/integration/archiving_test.go (about)

     1  package integration_test
     2  
     3  import (
     4  	"github.com/chenbh/concourse/v6/atc"
     5  	concourse "github.com/chenbh/concourse/v6/go-concourse/concourse"
     6  	. "github.com/onsi/ginkgo"
     7  	. "github.com/onsi/gomega"
     8  )
     9  
    10  var basicPipelineConfig = []byte(`
    11  ---
    12  jobs:
    13  - name: simple
    14  `)
    15  
    16  var _ = Describe("ATC Integration Test", func() {
    17  	var (
    18  		client concourse.Client
    19  	)
    20  
    21  	JustBeforeEach(func() {
    22  		client = login(atcURL, "test", "test")
    23  	})
    24  
    25  	It("can archive pipelines", func() {
    26  		givenAPipeline(client, "pipeline")
    27  
    28  		whenIArchiveIt(client, "pipeline")
    29  
    30  		pipeline := getPipeline(client, "pipeline")
    31  		Expect(pipeline.Archived).To(BeTrue(), "pipeline was not archived")
    32  		Expect(pipeline.Paused).To(BeTrue(), "pipeline was not paused")
    33  	})
    34  
    35  	It("fails when unpausing an archived pipeline", func() {
    36  		givenAPipeline(client, "pipeline")
    37  		whenIArchiveIt(client, "pipeline")
    38  
    39  		_, err := client.Team("main").UnpausePipeline("pipeline")
    40  
    41  		Expect(err).To(HaveOccurred())
    42  		Expect(err.Error()).To(ContainSubstring("action not allowed for an archived pipeline"))
    43  	})
    44  
    45  	It("archived pipelines can have their name re-used", func() {
    46  		givenAPipeline(client, "pipeline")
    47  		whenIArchiveIt(client, "pipeline")
    48  
    49  		_, version, _, _ := client.Team("main").PipelineConfig("pipeline")
    50  		client.Team("main").CreateOrUpdatePipelineConfig("pipeline", version, basicPipelineConfig, false)
    51  
    52  		pipeline := getPipeline(client, "pipeline")
    53  		Expect(pipeline.Archived).To(BeFalse(), "pipeline is still archived")
    54  		Expect(pipeline.Paused).To(BeTrue(), "pipeline was not paused")
    55  	})
    56  
    57  	It("archiving a pipeline results in it being paused", func() {
    58  		givenAPipeline(client, "pipeline")
    59  		whenIUnpauseIt(client, "pipeline")
    60  
    61  		whenIArchiveIt(client, "pipeline")
    62  
    63  		pipeline := getPipeline(client, "pipeline")
    64  		Expect(pipeline.Paused).To(BeTrue(), "pipeline was not paused")
    65  	})
    66  
    67  	It("archiving a pipeline purges its config", func() {
    68  		givenAPipeline(client, "pipeline")
    69  
    70  		whenIArchiveIt(client, "pipeline")
    71  
    72  		_, hasConfig := getPipelineConfig(client, "pipeline")
    73  		Expect(hasConfig).To(BeFalse())
    74  	})
    75  })
    76  
    77  func givenAPipeline(client concourse.Client, pipelineName string) {
    78  	_, _, _, err := client.Team("main").CreateOrUpdatePipelineConfig(pipelineName, "0", basicPipelineConfig, false)
    79  	Expect(err).NotTo(HaveOccurred())
    80  }
    81  
    82  func whenIUnpauseIt(client concourse.Client, pipelineName string) {
    83  	_, err := client.Team("main").UnpausePipeline(pipelineName)
    84  	Expect(err).ToNot(HaveOccurred())
    85  }
    86  
    87  func whenIArchiveIt(client concourse.Client, pipelineName string) {
    88  	_, err := client.Team("main").ArchivePipeline(pipelineName)
    89  	Expect(err).ToNot(HaveOccurred())
    90  }
    91  
    92  func getPipeline(client concourse.Client, pipelineName string) atc.Pipeline {
    93  	pipeline, _, err := client.Team("main").Pipeline(pipelineName)
    94  	Expect(err).ToNot(HaveOccurred())
    95  	return pipeline
    96  }
    97  
    98  func getPipelineConfig(client concourse.Client, pipelineName string) (atc.Config, bool) {
    99  	config, _, ok, err := client.Team("main").PipelineConfig(pipelineName)
   100  	Expect(err).ToNot(HaveOccurred())
   101  	return config, ok
   102  }