mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
build: table-driven tests for publisher.
This commit is contained in:
parent
8130067fd1
commit
e2007733f4
@ -4,44 +4,57 @@ import "testing"
|
|||||||
|
|
||||||
func TestPreparingReleaseFromRemote(t *testing.T) {
|
func TestPreparingReleaseFromRemote(t *testing.T) {
|
||||||
|
|
||||||
var builder releaseBuilder
|
cases := []struct {
|
||||||
|
version string
|
||||||
versionIn := "v5.2.0-beta1"
|
expectedVersion string
|
||||||
expectedVersion := "5.2.0-beta1"
|
whatsNewUrl string
|
||||||
whatsNewUrl := "https://whatsnews.foo/"
|
relNotesUrl string
|
||||||
relNotesUrl := "https://relnotes.foo/"
|
expectedArch string
|
||||||
expectedArch := "amd64"
|
expectedOs string
|
||||||
expectedOs := "linux"
|
buildArtifacts []buildArtifact
|
||||||
buildArtifacts := []buildArtifact{{expectedOs, expectedArch, ".linux-amd64.tar.gz"}}
|
}{
|
||||||
|
{
|
||||||
builder = releaseFromExternalContent{
|
version: "v5.2.0-beta1",
|
||||||
getter: mockHttpGetter{},
|
expectedVersion: "5.2.0-beta1",
|
||||||
rawVersion: versionIn,
|
whatsNewUrl: "https://whatsnews.foo/",
|
||||||
artifactConfigurations: buildArtifactConfigurations,
|
relNotesUrl: "https://relnotes.foo/",
|
||||||
|
expectedArch: "amd64",
|
||||||
|
expectedOs: "linux",
|
||||||
|
buildArtifacts: []buildArtifact{{"linux", "amd64", ".linux-amd64.tar.gz"}},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
rel, _ := builder.prepareRelease("https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana", whatsNewUrl, relNotesUrl, false)
|
for _, test := range cases {
|
||||||
|
var builder releaseBuilder
|
||||||
|
builder = releaseFromExternalContent{
|
||||||
|
getter: mockHttpGetter{},
|
||||||
|
rawVersion: test.version,
|
||||||
|
artifactConfigurations: test.buildArtifacts,
|
||||||
|
}
|
||||||
|
|
||||||
if !rel.Beta || rel.Stable {
|
rel, _ := builder.prepareRelease("https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana", test.whatsNewUrl, test.relNotesUrl, false)
|
||||||
t.Errorf("%s should have been tagged as beta (not stable), but wasn't .", versionIn)
|
|
||||||
}
|
|
||||||
|
|
||||||
if rel.Version != expectedVersion {
|
if !rel.Beta || rel.Stable {
|
||||||
t.Errorf("Expected version to be %s, but it was %s.", expectedVersion, rel.Version)
|
t.Errorf("%s should have been tagged as beta (not stable), but wasn't .", test.version)
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedBuilds := len(buildArtifacts)
|
if rel.Version != test.expectedVersion {
|
||||||
if len(rel.Builds) != expectedBuilds {
|
t.Errorf("Expected version to be %s, but it was %s.", test.expectedVersion, rel.Version)
|
||||||
t.Errorf("Expected %v builds, but got %v.", expectedBuilds, len(rel.Builds))
|
}
|
||||||
}
|
|
||||||
|
|
||||||
build := rel.Builds[0]
|
expectedBuilds := len(test.buildArtifacts)
|
||||||
if build.Arch != expectedArch {
|
if len(rel.Builds) != expectedBuilds {
|
||||||
t.Errorf("Expected arch to be %v, but it was %v", expectedArch, build.Arch)
|
t.Errorf("Expected %v builds, but got %v.", expectedBuilds, len(rel.Builds))
|
||||||
}
|
}
|
||||||
|
|
||||||
if build.Os != expectedOs {
|
build := rel.Builds[0]
|
||||||
t.Errorf("Expected arch to be %v, but it was %v", expectedOs, build.Os)
|
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 arch to be %v, but it was %v", test.expectedOs, build.Os)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user