github.com/aserto-dev/calc-version@v1.1.4/docker_test.go (about)

     1  package main
     2  
     3  import (
     4  	. "github.com/onsi/ginkgo"
     5  	. "github.com/onsi/gomega"
     6  )
     7  
     8  var _ = Describe("registry-versions", func() {
     9  
    10  	Context("when it's a development release", func() {
    11  		It("only returns the full version tag", func() {
    12  			version := "1.0.0-dev"
    13  			existringTags := []string{}
    14  
    15  			tags, err := calculateTagsForVersion(version, existringTags)
    16  			Expect(err).ToNot(HaveOccurred())
    17  
    18  			Expect(tags).To(HaveLen(1))
    19  			Expect(tags).To(ContainElement(version))
    20  		})
    21  	})
    22  
    23  	Context("when it's not a development release", func() {
    24  		Context("there are no remote tags", func() {
    25  			It("returns the full version, major, minor and latest tags", func() {
    26  				version := "1.0.1"
    27  				existringTags := []string{}
    28  
    29  				tags, err := calculateTagsForVersion(version, existringTags)
    30  				Expect(err).ToNot(HaveOccurred())
    31  
    32  				Expect(tags).To(HaveLen(4))
    33  				Expect(tags).To(ContainElement("1.0.1"))
    34  				Expect(tags).To(ContainElement("1.0"))
    35  				Expect(tags).To(ContainElement("1"))
    36  				Expect(tags).To(ContainElement("latest"))
    37  			})
    38  		})
    39  
    40  		Context("if it's not the latest version", func() {
    41  			It("only returns the full version, and major and minor versions", func() {
    42  				version := "1.3.1"
    43  				existringTags := []string{"0.9.0", "1.2.0", "1.0.0", "2.0.0"}
    44  
    45  				tags, err := calculateTagsForVersion(version, existringTags)
    46  				Expect(err).ToNot(HaveOccurred())
    47  
    48  				Expect(tags).To(HaveLen(3))
    49  				Expect(tags).To(ContainElement("1.3.1"))
    50  				Expect(tags).To(ContainElement("1.3"))
    51  				Expect(tags).To(ContainElement("1"))
    52  			})
    53  
    54  			Context("if it's not the latest in the major series", func() {
    55  				It("only returns the full version, and minor versions", func() {
    56  					version := "1.3.1"
    57  					existringTags := []string{"1.2.0", "1.4.0"}
    58  
    59  					tags, err := calculateTagsForVersion(version, existringTags)
    60  					Expect(err).ToNot(HaveOccurred())
    61  
    62  					Expect(tags).To(HaveLen(2))
    63  					Expect(tags).To(ContainElement("1.3.1"))
    64  					Expect(tags).To(ContainElement("1.3"))
    65  				})
    66  
    67  				Context("but if it's the only one in the major series", func() {
    68  					It("it returns the full version, major and minor versions", func() {
    69  						version := "0.3.1"
    70  						existringTags := []string{"1.2.0", "1.4.0"}
    71  
    72  						tags, err := calculateTagsForVersion(version, existringTags)
    73  						Expect(err).ToNot(HaveOccurred())
    74  
    75  						Expect(tags).To(HaveLen(3))
    76  						Expect(tags).To(ContainElement("0.3.1"))
    77  						Expect(tags).To(ContainElement("0.3"))
    78  						Expect(tags).To(ContainElement("0"))
    79  					})
    80  				})
    81  			})
    82  
    83  			Context("if it's not the latest in the minor series", func() {
    84  				It("only returns the full version", func() {
    85  					version := "1.2.1"
    86  					existringTags := []string{"1.2.2", "1.4.0"}
    87  
    88  					tags, err := calculateTagsForVersion(version, existringTags)
    89  					Expect(err).ToNot(HaveOccurred())
    90  
    91  					Expect(tags).To(HaveLen(1))
    92  					Expect(tags).To(ContainElement("1.2.1"))
    93  				})
    94  			})
    95  		})
    96  
    97  		Context("if it's the latest version", func() {
    98  			It("returns the full version, major, minor and latest tags", func() {
    99  				version := "2.1.1"
   100  				existringTags := []string{"2.1.0", "1.2.0", "2.0.0"}
   101  
   102  				tags, err := calculateTagsForVersion(version, existringTags)
   103  				Expect(err).ToNot(HaveOccurred())
   104  
   105  				Expect(tags).To(HaveLen(4))
   106  				Expect(tags).To(ContainElement("2.1.1"))
   107  				Expect(tags).To(ContainElement("2.1"))
   108  				Expect(tags).To(ContainElement("2"))
   109  				Expect(tags).To(ContainElement("latest"))
   110  			})
   111  		})
   112  	})
   113  })