Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Test that verifying a release works
Browse files Browse the repository at this point in the history
The minimal test that if the release doesn't work (in this case,
nothing is updated), verification will fail.
  • Loading branch information
squaremo committed May 24, 2018
1 parent a782c4c commit 5465716
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
4 changes: 2 additions & 2 deletions release/releaser.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ func VerifyChanges(before map[string]resource.Resource, updates []*update.Contro
}
for i := range afterContainers {
if beforeContainers[i].Name != afterContainers[i].Name {
return fmt.Errorf("Container [%d] has a different name after update: was %q, now %q", i, beforeContainers[i].Name, afterContainers[i].Name)
return fmt.Errorf("Container in position %d of resource %q has a different name after update: was %q, now %q", i, id, beforeContainers[i].Name, afterContainers[i].Name)
}
if beforeContainers[i].Image != afterContainers[i].Image {
return fmt.Errorf("The image for container %q in resource %q was changed (to %q) and should not have been", beforeContainers[i].Name, id, afterContainers[i].Image.String())
return fmt.Errorf("The image for container %q in resource %q should be %q, but is %q", beforeContainers[i].Name, id, beforeContainers[i].Image.String(), afterContainers[i].Image.String())
}
}

Expand Down
48 changes: 48 additions & 0 deletions release/releaser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,3 +439,51 @@ func testRelease(t *testing.T, name string, ctx *ReleaseContext, spec update.Rel
t.Errorf("%s\n--- expected ---\n%s\n--- got ---\n%s\n", name, string(exp), string(got))
}
}

// --- test verification

// A Manifests implementation that does updates incorrectly, so they should fail verification.
type badManifests struct {
kubernetes.Manifests
}

func (m *badManifests) UpdateImage(def []byte, resourceID flux.ResourceID, container string, newImageID image.Ref) ([]byte, error) {
return def, nil
}

func TestBadRelease(t *testing.T) {
cluster := mockCluster(hwSvc)
spec := update.ReleaseSpec{
ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
ImageSpec: update.ImageSpecFromRef(newHwRef),
Kind: update.ReleaseKindExecute,
Excludes: []flux.ResourceID{},
}
checkout1, cleanup1 := setup(t)
defer cleanup1()

ctx := &ReleaseContext{
cluster: cluster,
manifests: &kubernetes.Manifests{},
repo: checkout1,
registry: mockRegistry,
}
_, err := Release(ctx, spec, log.NewNopLogger())
if err != nil {
t.Fatal("release with 'good' Manifests should succeed, but errored:", err)
}

checkout2, cleanup2 := setup(t)
defer cleanup2()

ctx = &ReleaseContext{
cluster: cluster,
manifests: &badManifests{Manifests: kubernetes.Manifests{}},
repo: checkout2,
registry: mockRegistry,
}
_, err = Release(ctx, spec, log.NewNopLogger())
if err == nil {
t.Fatal("did not return an error, but was expected to fail verification")
}
}

0 comments on commit 5465716

Please sign in to comment.