version = "" }) Context("when the provided version is the newest", func() { var ( allVersions []string version string ) BeforeEach(func() { allVersions = []string{"1.2.3#abc", "1.3.2#def"} version = "1.2.3#abc" }) It("returns empty array", func() { versions, _ := versions.Since(allVersions, version) Expect(versions).To(HaveLen(0)) }) }) Context("when provided version is present but not the newest", func() { BeforeEach(func() { allVersions = []string{"newest version", "middle version", "older version", "last version"} version = "older version" }) It("returns new versions", func() { versions, _ := versions.Since(allVersions, version) Expect(versions).To(Equal([]string{"newest version", "middle version"}))
func (c *CheckCommand) Run(input concourse.CheckRequest) (concourse.CheckResponse, error) { c.logger.Info("Received input, starting Check CMD run") err := c.removeExistingLogFiles() if err != nil { return nil, err } releaseType := input.Source.ReleaseType err = c.validateReleaseType(releaseType) if err != nil { return nil, err } productSlug := input.Source.ProductSlug c.logger.Info("Getting all releases") releases, err := c.pivnetClient.ReleasesForProductSlug(productSlug) if err != nil { return nil, err } if releaseType != "" { c.logger.Info(fmt.Sprintf("Filtering all releases by release type: '%s'", releaseType)) releases, err = c.filter.ReleasesByReleaseType( releases, pivnet.ReleaseType(releaseType), ) if err != nil { return nil, err } } version := input.Source.ProductVersion if version != "" { c.logger.Info(fmt.Sprintf("Filtering all releases by product version: '%s'", version)) releases, err = c.filter.ReleasesByVersion(releases, version) if err != nil { return nil, err } } if input.Source.SortBy == concourse.SortBySemver { c.logger.Info("Sorting all releases by semver") releases, err = c.semverSorter.SortBySemver(releases) if err != nil { return nil, err } } vs, err := releaseVersions(releases) if err != nil { // Untested because versions.CombineVersionAndFingerprint cannot be forced to return an error. return concourse.CheckResponse{}, err } if len(vs) == 0 { return concourse.CheckResponse{}, nil } c.logger.Info("Gathering new versions") newVersions, err := versions.Since(vs, input.Version.ProductVersion) if err != nil { // Untested because versions.Since cannot be forced to return an error. return nil, err } reversedVersions, err := versions.Reverse(newVersions) if err != nil { // Untested because versions.Reverse cannot be forced to return an error. return nil, err } c.logger.Info(fmt.Sprintf("New versions: %v", reversedVersions)) var out concourse.CheckResponse for _, v := range reversedVersions { out = append(out, concourse.Version{ProductVersion: v}) } if len(out) == 0 { out = append(out, concourse.Version{ProductVersion: vs[0]}) } c.logger.Info("Finishing check and returning ouput") return out, nil }