|
@@ -4,44 +4,98 @@ import "testing"
|
|
|
|
|
|
|
|
func TestPreparingReleaseFromRemote(t *testing.T) {
|
|
func TestPreparingReleaseFromRemote(t *testing.T) {
|
|
|
|
|
|
|
|
- var builder releaseBuilder
|
|
|
|
|
-
|
|
|
|
|
- versionIn := "v5.2.0-beta1"
|
|
|
|
|
- expectedVersion := "5.2.0-beta1"
|
|
|
|
|
- whatsNewUrl := "https://whatsnews.foo/"
|
|
|
|
|
- relNotesUrl := "https://relnotes.foo/"
|
|
|
|
|
- expectedArch := "amd64"
|
|
|
|
|
- expectedOs := "linux"
|
|
|
|
|
- buildArtifacts := []buildArtifact{{expectedOs, expectedArch, ".linux-amd64.tar.gz"}}
|
|
|
|
|
-
|
|
|
|
|
- builder = releaseFromExternalContent{
|
|
|
|
|
- getter: mockHttpGetter{},
|
|
|
|
|
- rawVersion: versionIn,
|
|
|
|
|
- artifactConfigurations: buildArtifactConfigurations,
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- rel, _ := builder.prepareRelease("https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana", whatsNewUrl, relNotesUrl, false)
|
|
|
|
|
-
|
|
|
|
|
- if !rel.Beta || rel.Stable {
|
|
|
|
|
- t.Errorf("%s should have been tagged as beta (not stable), but wasn't .", versionIn)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if rel.Version != expectedVersion {
|
|
|
|
|
- t.Errorf("Expected version to be %s, but it was %s.", expectedVersion, rel.Version)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- expectedBuilds := len(buildArtifacts)
|
|
|
|
|
- if len(rel.Builds) != expectedBuilds {
|
|
|
|
|
- t.Errorf("Expected %v builds, but got %v.", expectedBuilds, len(rel.Builds))
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- build := rel.Builds[0]
|
|
|
|
|
- if build.Arch != expectedArch {
|
|
|
|
|
- t.Errorf("Expected arch to be %v, but it was %v", expectedArch, build.Arch)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if build.Os != expectedOs {
|
|
|
|
|
- t.Errorf("Expected arch to be %v, but it was %v", expectedOs, build.Os)
|
|
|
|
|
|
|
+ cases := []struct {
|
|
|
|
|
+ version string
|
|
|
|
|
+ expectedVersion string
|
|
|
|
|
+ whatsNewUrl string
|
|
|
|
|
+ relNotesUrl string
|
|
|
|
|
+ nightly bool
|
|
|
|
|
+ expectedBeta bool
|
|
|
|
|
+ expectedStable bool
|
|
|
|
|
+ expectedArch string
|
|
|
|
|
+ expectedOs string
|
|
|
|
|
+ expectedUrl string
|
|
|
|
|
+ baseArchiveUrl string
|
|
|
|
|
+ buildArtifacts []buildArtifact
|
|
|
|
|
+ }{
|
|
|
|
|
+ {
|
|
|
|
|
+ version: "v5.2.0-beta1",
|
|
|
|
|
+ expectedVersion: "5.2.0-beta1",
|
|
|
|
|
+ whatsNewUrl: "https://whatsnews.foo/",
|
|
|
|
|
+ relNotesUrl: "https://relnotes.foo/",
|
|
|
|
|
+ nightly: false,
|
|
|
|
|
+ expectedBeta: true,
|
|
|
|
|
+ expectedStable: false,
|
|
|
|
|
+ expectedArch: "amd64",
|
|
|
|
|
+ expectedOs: "linux",
|
|
|
|
|
+ expectedUrl: "https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.2.0-beta1.linux-amd64.tar.gz",
|
|
|
|
|
+ baseArchiveUrl: "https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana",
|
|
|
|
|
+ buildArtifacts: []buildArtifact{{"linux", "amd64", ".linux-amd64.tar.gz"}},
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ version: "v5.2.3",
|
|
|
|
|
+ expectedVersion: "5.2.3",
|
|
|
|
|
+ whatsNewUrl: "https://whatsnews.foo/",
|
|
|
|
|
+ relNotesUrl: "https://relnotes.foo/",
|
|
|
|
|
+ nightly: false,
|
|
|
|
|
+ expectedBeta: false,
|
|
|
|
|
+ expectedStable: true,
|
|
|
|
|
+ expectedArch: "amd64",
|
|
|
|
|
+ expectedOs: "rhel",
|
|
|
|
|
+ expectedUrl: "https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.2.3-1.x86_64.rpm",
|
|
|
|
|
+ baseArchiveUrl: "https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana",
|
|
|
|
|
+ buildArtifacts: []buildArtifact{{"rhel", "amd64", ".x86_64.rpm"}},
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ version: "v5.4.0-pre1asdf",
|
|
|
|
|
+ expectedVersion: "5.4.0-pre1asdf",
|
|
|
|
|
+ whatsNewUrl: "https://whatsnews.foo/",
|
|
|
|
|
+ relNotesUrl: "https://relnotes.foo/",
|
|
|
|
|
+ nightly: true,
|
|
|
|
|
+ expectedBeta: false,
|
|
|
|
|
+ expectedStable: false,
|
|
|
|
|
+ expectedArch: "amd64",
|
|
|
|
|
+ expectedOs: "rhel",
|
|
|
|
|
+ expectedUrl: "https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.4.0-pre1asdf.x86_64.rpm",
|
|
|
|
|
+ baseArchiveUrl: "https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana",
|
|
|
|
|
+ buildArtifacts: []buildArtifact{{"rhel", "amd64", ".x86_64.rpm"}},
|
|
|
|
|
+ },
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for _, test := range cases {
|
|
|
|
|
+ builder := releaseFromExternalContent{
|
|
|
|
|
+ getter: mockHttpGetter{},
|
|
|
|
|
+ rawVersion: test.version,
|
|
|
|
|
+ artifactConfigurations: test.buildArtifacts,
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ rel, _ := builder.prepareRelease(test.baseArchiveUrl, test.whatsNewUrl, test.relNotesUrl, test.nightly)
|
|
|
|
|
+
|
|
|
|
|
+ if rel.Beta != test.expectedBeta || rel.Stable != test.expectedStable {
|
|
|
|
|
+ t.Errorf("%s should have been tagged as beta=%v, stable=%v.", test.version, test.expectedBeta, test.expectedStable)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if rel.Version != test.expectedVersion {
|
|
|
|
|
+ t.Errorf("Expected version to be %s, but it was %s.", test.expectedVersion, rel.Version)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ expectedBuilds := len(test.buildArtifacts)
|
|
|
|
|
+ if len(rel.Builds) != expectedBuilds {
|
|
|
|
|
+ t.Errorf("Expected %v builds, but got %v.", expectedBuilds, len(rel.Builds))
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ build := rel.Builds[0]
|
|
|
|
|
+ if build.Arch != test.expectedArch {
|
|
|
|
|
+ t.Errorf("Expected arch to be %v, but it was %v", test.expectedArch, build.Arch)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if build.Os != test.expectedOs {
|
|
|
|
|
+ t.Errorf("Expected os to be %v, but it was %v", test.expectedOs, build.Os)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if build.Url != test.expectedUrl {
|
|
|
|
|
+ t.Errorf("Expected url to be %v, but it was %v", test.expectedUrl, build.Url)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -116,4 +170,9 @@ func TestPreparingReleaseFromLocal(t *testing.T) {
|
|
|
if build.Os != expectedOs {
|
|
if build.Os != expectedOs {
|
|
|
t.Fatalf("Expected os to be %s, but was %s", expectedOs, build.Os)
|
|
t.Fatalf("Expected os to be %s, but was %s", expectedOs, build.Os)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ _, err := builder.prepareRelease("", "", "", false)
|
|
|
|
|
+ if err == nil {
|
|
|
|
|
+ t.Error("Error was nil, but expected an error as the local releaser only supports nightly builds.")
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|