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

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lelenanam committed Oct 25, 2018
1 parent bcfb292 commit 7337c9a
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 51 deletions.
12 changes: 6 additions & 6 deletions cmd/fluxctl/release_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@ import (
func TestReleaseCommand_CLIConversion(t *testing.T) {
for _, v := range []struct {
args []string
expectedSpec update.ReleaseSpec
expectedSpec update.ReleaseImageSpec
}{
{[]string{"--update-all-images", "--all"}, update.ReleaseSpec{
{[]string{"--update-all-images", "--all"}, update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
ImageSpec: update.ImageSpecLatest,
Kind: update.ReleaseKindExecute,
}},
{[]string{"--update-all-images", "--all", "--dry-run"}, update.ReleaseSpec{
{[]string{"--update-all-images", "--all", "--dry-run"}, update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
ImageSpec: update.ImageSpecLatest,
Kind: update.ReleaseKindPlan,
}},
{[]string{"--update-image=alpine:latest", "--all"}, update.ReleaseSpec{
{[]string{"--update-image=alpine:latest", "--all"}, update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
ImageSpec: "alpine:latest",
Kind: update.ReleaseKindExecute,
}},
{[]string{"--update-all-images", "--controller=deployment/flux"}, update.ReleaseSpec{
{[]string{"--update-all-images", "--controller=deployment/flux"}, update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{"default:deployment/flux"},
ImageSpec: update.ImageSpecLatest,
Kind: update.ReleaseKindExecute,
}},
{[]string{"--update-all-images", "--all", "--exclude=deployment/test,deployment/yeah"}, update.ReleaseSpec{
{[]string{"--update-all-images", "--all", "--exclude=deployment/test,deployment/yeah"}, update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
ImageSpec: update.ImageSpecLatest,
Kind: update.ReleaseKindExecute,
Expand Down
11 changes: 5 additions & 6 deletions daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func TestDaemon_ListServicesWithOptions(t *testing.T) {

ctx := context.Background()

t.Run("no filter", func (t *testing.T) {
t.Run("no filter", func(t *testing.T) {
s, err := d.ListServicesWithOptions(ctx, v11.ListServicesOptions{})
if err != nil {
t.Fatalf("Error: %s", err.Error())
Expand All @@ -153,7 +153,7 @@ func TestDaemon_ListServicesWithOptions(t *testing.T) {
t.Fatalf("Expected %v but got %v", 2, len(s))
}
})
t.Run("filter id", func (t *testing.T) {
t.Run("filter id", func(t *testing.T) {
s, err := d.ListServicesWithOptions(ctx, v11.ListServicesOptions{
Namespace: "",
Services: []flux.ResourceID{flux.MustParseResourceID(svc)}})
Expand All @@ -165,7 +165,7 @@ func TestDaemon_ListServicesWithOptions(t *testing.T) {
}
})

t.Run("filter id and namespace", func (t *testing.T) {
t.Run("filter id and namespace", func(t *testing.T) {
_, err := d.ListServicesWithOptions(ctx, v11.ListServicesOptions{
Namespace: "foo",
Services: []flux.ResourceID{flux.MustParseResourceID(svc)}})
Expand All @@ -174,7 +174,7 @@ func TestDaemon_ListServicesWithOptions(t *testing.T) {
}
})

t.Run("filter unsupported id kind", func (t *testing.T) {
t.Run("filter unsupported id kind", func(t *testing.T) {
_, err := d.ListServicesWithOptions(ctx, v11.ListServicesOptions{
Namespace: "foo",
Services: []flux.ResourceID{flux.MustParseResourceID("default:unsupportedkind/goodbyeworld")}})
Expand All @@ -184,7 +184,6 @@ func TestDaemon_ListServicesWithOptions(t *testing.T) {
})
}


// When I call list images for a service, it should return images
func TestDaemon_ListImagesWithOptions(t *testing.T) {
d, start, clean, _, _, _ := mockDaemon(t)
Expand Down Expand Up @@ -848,7 +847,7 @@ func (w *wait) ForImageTag(t *testing.T, d *Daemon, service, container, tag stri
func updateImage(ctx context.Context, d *Daemon, t *testing.T) job.ID {
return updateManifest(ctx, t, d, update.Spec{
Type: update.Images,
Spec: update.ReleaseSpec{
Spec: update.ReleaseImageSpec{
Kind: update.ReleaseKindExecute,
ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
ImageSpec: newHelloImage,
Expand Down
4 changes: 2 additions & 2 deletions daemon/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ func (d *Daemon) doSync(logger log.Logger) (retErr error) {
Error: n.Result.Error(),
},
Spec: event.ReleaseSpec{
Type: event.ReleaseContainerSpecType,
ReleaseContainerSpec: &spec,
Type: event.ReleaseContainersSpecType,
ReleaseContainersSpec: &spec,
},
Cause: n.Spec.Cause,
},
Expand Down
16 changes: 8 additions & 8 deletions event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (e Event) String() string {
if len(strImageIDs) == 0 {
strImageIDs = []string{"no image changes"}
}
if metadata.Spec.Type == ReleaseImageSpecType {
if metadata.Spec.Type == "" || metadata.Spec.Type == ReleaseImageSpecType {
for _, spec := range metadata.Spec.ReleaseImageSpec.ServiceSpecs {
if spec == update.ResourceSpecAll {
strServiceIDs = []string{"all services"}
Expand Down Expand Up @@ -244,17 +244,17 @@ type ReleaseEventCommon struct {
const (
// ReleaseImageSpecType is a type of release spec when there are update.Images
ReleaseImageSpecType = "releaseImageSpecType"
// ReleaseContainerSpecType is a type of release spec when there are update.Containers
ReleaseContainerSpecType = "releaseContainerSpecType"
// ReleaseContainersSpecType is a type of release spec when there are update.Containers
ReleaseContainersSpecType = "releaseContainersSpecType"
)

// ReleaseSpec is a spec for images and containers release
type ReleaseSpec struct {
// Type is ReleaseImagesSpecType or ReleaseContainersSpecType
// if empty (for previous version), then use ReleaseImagesSpecType
Type string
ReleaseImageSpec *update.ReleaseImageSpec
ReleaseContainerSpec *update.ReleaseContainersSpec
// Type is ReleaseImageSpecType or ReleaseContainersSpecType
// if empty (for previous version), then use ReleaseImageSpecType
Type string
ReleaseImageSpec *update.ReleaseImageSpec
ReleaseContainersSpec *update.ReleaseContainersSpec
}

// ReleaseEventMetadata is the metadata for when service(s) are released
Expand Down
9 changes: 6 additions & 3 deletions event/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

var (
spec = update.ReleaseSpec{
spec = update.ReleaseImageSpec{
ImageSpec: update.ImageSpecLatest,
}
cause = update.Cause{
Expand All @@ -22,7 +22,10 @@ func TestEvent_ParseReleaseMetaData(t *testing.T) {
Type: EventRelease,
Metadata: &ReleaseEventMetadata{
Cause: cause,
Spec: spec,
Spec: ReleaseSpec{
Type: ReleaseImageSpecType,
ReleaseImageSpec: &spec,
},
},
}

Expand All @@ -35,7 +38,7 @@ func TestEvent_ParseReleaseMetaData(t *testing.T) {
}
switch r := e.Metadata.(type) {
case *ReleaseEventMetadata:
if r.Spec.ImageSpec != spec.ImageSpec ||
if r.Spec.ReleaseImageSpec.ImageSpec != spec.ImageSpec ||
r.Cause != cause {
t.Fatal("Release event wasn't marshalled/unmarshalled")
}
Expand Down
52 changes: 26 additions & 26 deletions release/releaser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func Test_InitContainer(t *testing.T) {
}

initSpec, _ := update.ParseResourceSpec(initWorkloadID.String())
spec := update.ReleaseSpec{
spec := update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{initSpec},
ImageSpec: update.ImageSpecLatest,
Kind: update.ReleaseKindExecute,
Expand All @@ -268,13 +268,13 @@ func Test_FilterLogic(t *testing.T) {
notInRepoSpec, _ := update.ParseResourceSpec(notInRepoService)
for _, tst := range []struct {
Name string
Spec update.ReleaseSpec
Spec update.ReleaseImageSpec
Expected expected
}{
// ignored if: excluded OR not included OR not correct image.
{
Name: "include specific service",
Spec: update.ReleaseSpec{
Spec: update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{hwSvcSpec},
ImageSpec: update.ImageSpecLatest,
Kind: update.ReleaseKindExecute,
Expand Down Expand Up @@ -302,7 +302,7 @@ func Test_FilterLogic(t *testing.T) {
},
}, {
Name: "exclude specific service",
Spec: update.ReleaseSpec{
Spec: update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
ImageSpec: update.ImageSpecLatest,
Kind: update.ReleaseKindExecute,
Expand Down Expand Up @@ -334,7 +334,7 @@ func Test_FilterLogic(t *testing.T) {
},
}, {
Name: "update specific image",
Spec: update.ReleaseSpec{
Spec: update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
ImageSpec: update.ImageSpecFromRef(newHwRef),
Kind: update.ReleaseKindExecute,
Expand Down Expand Up @@ -363,7 +363,7 @@ func Test_FilterLogic(t *testing.T) {
// skipped if: not ignored AND (locked or not found in cluster)
// else: service is pending.
Name: "skipped & service is pending",
Spec: update.ReleaseSpec{
Spec: update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
ImageSpec: update.ImageSpecLatest,
Kind: update.ReleaseKindExecute,
Expand Down Expand Up @@ -395,7 +395,7 @@ func Test_FilterLogic(t *testing.T) {
},
}, {
Name: "all overrides spec",
Spec: update.ReleaseSpec{
Spec: update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{hwSvcSpec, update.ResourceSpecAll},
ImageSpec: update.ImageSpecLatest,
Kind: update.ReleaseKindExecute,
Expand Down Expand Up @@ -427,7 +427,7 @@ func Test_FilterLogic(t *testing.T) {
},
}, {
Name: "service not in repo",
Spec: update.ReleaseSpec{
Spec: update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{notInRepoSpec},
ImageSpec: update.ImageSpecLatest,
Kind: update.ReleaseKindExecute,
Expand Down Expand Up @@ -468,12 +468,12 @@ func Test_Force_lockedController(t *testing.T) {
}
for _, tst := range []struct {
Name string
Spec update.ReleaseSpec
Spec update.ReleaseImageSpec
Expected expected
}{
{
Name: "force ignores service lock (--controller --update-image)",
Spec: update.ReleaseSpec{
Spec: update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{lockedSvcSpec},
ImageSpec: update.ImageSpecFromRef(newLockedRef),
Kind: update.ReleaseKindExecute,
Expand All @@ -488,7 +488,7 @@ func Test_Force_lockedController(t *testing.T) {
},
}, {
Name: "force does not ignore lock if updating all controllers (--all --update-image)",
Spec: update.ReleaseSpec{
Spec: update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
ImageSpec: update.ImageSpecFromRef(newLockedRef),
Kind: update.ReleaseKindExecute,
Expand All @@ -504,7 +504,7 @@ func Test_Force_lockedController(t *testing.T) {
},
{
Name: "force ignores service lock (--controller --update-all-images)",
Spec: update.ReleaseSpec{
Spec: update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{lockedSvcSpec},
ImageSpec: update.ImageSpecLatest,
Kind: update.ReleaseKindExecute,
Expand All @@ -519,7 +519,7 @@ func Test_Force_lockedController(t *testing.T) {
},
}, {
Name: "force does not ignore lock if updating all controllers (--all --update-all-images)",
Spec: update.ReleaseSpec{
Spec: update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
ImageSpec: update.ImageSpecLatest,
Kind: update.ReleaseKindExecute,
Expand Down Expand Up @@ -571,12 +571,12 @@ func Test_Force_filteredContainer(t *testing.T) {
}
for _, tst := range []struct {
Name string
Spec update.ReleaseSpec
Spec update.ReleaseImageSpec
Expected expected
}{
{
Name: "force ignores container tag pattern (--controller --update-image)",
Spec: update.ReleaseSpec{
Spec: update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{semverSvcSpec},
ImageSpec: update.ImageSpecFromRef(newHwRef), // does not match filter
Kind: update.ReleaseKindExecute,
Expand All @@ -592,7 +592,7 @@ func Test_Force_filteredContainer(t *testing.T) {
},
{
Name: "force ignores container tag pattern (--all --update-image)",
Spec: update.ReleaseSpec{
Spec: update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
ImageSpec: update.ImageSpecFromRef(newHwRef), // does not match filter
Kind: update.ReleaseKindExecute,
Expand All @@ -608,7 +608,7 @@ func Test_Force_filteredContainer(t *testing.T) {
},
{
Name: "force complies with semver when updating all images (--controller --update-all-image)",
Spec: update.ReleaseSpec{
Spec: update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{semverSvcSpec},
ImageSpec: update.ImageSpecLatest, // will filter images by semver and pick newest version
Kind: update.ReleaseKindExecute,
Expand All @@ -624,7 +624,7 @@ func Test_Force_filteredContainer(t *testing.T) {
},
{
Name: "force complies with semver when updating all images (--all --update-all-image)",
Spec: update.ReleaseSpec{
Spec: update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
ImageSpec: update.ImageSpecLatest,
Kind: update.ReleaseKindExecute,
Expand Down Expand Up @@ -670,12 +670,12 @@ func Test_ImageStatus(t *testing.T) {
testSvcSpec, _ := update.ParseResourceSpec(testSvc.ID.String())
for _, tst := range []struct {
Name string
Spec update.ReleaseSpec
Spec update.ReleaseImageSpec
Expected expected
}{
{
Name: "image not found",
Spec: update.ReleaseSpec{
Spec: update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{testSvcSpec},
ImageSpec: update.ImageSpecLatest,
Kind: update.ReleaseKindExecute,
Expand All @@ -692,7 +692,7 @@ func Test_ImageStatus(t *testing.T) {
},
}, {
Name: "image up to date",
Spec: update.ReleaseSpec{
Spec: update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{hwSvcSpec},
ImageSpec: update.ImageSpecLatest,
Kind: update.ReleaseKindExecute,
Expand Down Expand Up @@ -746,7 +746,7 @@ func Test_UpdateMultidoc(t *testing.T) {
repo: checkout,
registry: mockRegistry,
}
spec := update.ReleaseSpec{
spec := update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{"default:deployment/multi-deploy"},
ImageSpec: update.ImageSpecLatest,
Kind: update.ReleaseKindExecute,
Expand Down Expand Up @@ -794,7 +794,7 @@ func Test_UpdateList(t *testing.T) {
repo: checkout,
registry: mockRegistry,
}
spec := update.ReleaseSpec{
spec := update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{"default:deployment/list-deploy"},
ImageSpec: update.ImageSpecLatest,
Kind: update.ReleaseKindExecute,
Expand Down Expand Up @@ -1014,7 +1014,7 @@ func Test_UpdateContainers(t *testing.T) {
},
},
} {
specs := update.ContainerSpecs{
specs := update.ReleaseContainersSpec{
ContainerSpecs: map[flux.ResourceID][]update.ContainerUpdate{tst.WorkloadID: tst.Spec},
Kind: update.ReleaseKindExecute,
}
Expand All @@ -1040,7 +1040,7 @@ func Test_UpdateContainers(t *testing.T) {
}
}

func testRelease(t *testing.T, ctx *ReleaseContext, spec update.ReleaseSpec, expected update.Result) {
func testRelease(t *testing.T, ctx *ReleaseContext, spec update.ReleaseImageSpec, expected update.Result) {
results, err := Release(ctx, spec, log.NewNopLogger())
assert.NoError(t, err)
assert.Equal(t, expected, results)
Expand All @@ -1059,7 +1059,7 @@ func (m *badManifests) UpdateImage(def []byte, resourceID flux.ResourceID, conta

func Test_BadRelease(t *testing.T) {
cluster := mockCluster(hwSvc)
spec := update.ReleaseSpec{
spec := update.ReleaseImageSpec{
ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
ImageSpec: update.ImageSpecFromRef(newHwRef),
Kind: update.ReleaseKindExecute,
Expand Down

0 comments on commit 7337c9a

Please sign in to comment.