Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(bundles): test remote to remote bundle copy
Signed-off-by: Timofey Kirillov <timofey.kirillov@flant.com>
- Loading branch information
1 parent
bdc1721
commit eaa6d58
Showing
5 changed files
with
182 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package bundles | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/Masterminds/semver" | ||
|
||
"github.com/werf/logboek" | ||
"github.com/werf/werf/pkg/slug" | ||
) | ||
|
||
func BundleTagToChartVersion(ctx context.Context, tag string, now time.Time) (*semver.Version, error) { | ||
sv, err := semver.NewVersion(tag) | ||
if err == nil { | ||
return sv, nil | ||
} | ||
|
||
// TODO: come up with a better idea for generating reproducible, consistent and monotonously increasing semver | ||
|
||
tsWithTagVersion := fmt.Sprintf("0.0.0-%d-%s", now.Unix(), slug.Slug(tag)) | ||
sv, err = semver.NewVersion(tsWithTagVersion) | ||
if err == nil { | ||
return sv, nil | ||
} | ||
|
||
fallbackVersion := fmt.Sprintf("0.0.0-%d", now.Unix()) | ||
logboek.Context(ctx).Warn().LogF("Unable to use %q as chart version, will fallback on chart version %q\n", tsWithTagVersion, fallbackVersion) | ||
|
||
sv, err = semver.NewVersion(fallbackVersion) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to use fallback chart version %q: %w", fallbackVersion, err) | ||
} | ||
|
||
return sv, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package bundles | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("BundleTagToSemver", func() { | ||
It("converts arbitrary tag to semver if tag not already semver", func() { | ||
ctx := context.Background() | ||
now := time.Now() | ||
|
||
{ | ||
sv, err := BundleTagToChartVersion(ctx, "latest", now) | ||
Expect(err).To(BeNil()) | ||
Expect(sv.String()).To(Equal(fmt.Sprintf("0.0.0-%d-latest", now.Unix()))) | ||
} | ||
|
||
{ | ||
sv, err := BundleTagToChartVersion(ctx, "my-branch/ABC", now) | ||
Expect(err).To(BeNil()) | ||
Expect(sv.String()).To(Equal(fmt.Sprintf("0.0.0-%d-my-branch-abc", now.Unix()))) | ||
} | ||
|
||
{ | ||
sv, err := BundleTagToChartVersion(ctx, "1.24.425-prerelease11", now) | ||
Expect(err).To(BeNil()) | ||
Expect(sv.String()).To(Equal("1.24.425-prerelease11")) | ||
} | ||
|
||
{ | ||
sv, err := BundleTagToChartVersion(ctx, "0.2.10", now) | ||
Expect(err).To(BeNil()) | ||
Expect(sv.String()).To(Equal("0.2.10")) | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters