Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Commit

Permalink
remove empty and v0 state types, leaving only versioned state
Browse files Browse the repository at this point in the history
  • Loading branch information
laverya committed May 17, 2019
1 parent ac0de70 commit 00638c4
Show file tree
Hide file tree
Showing 25 changed files with 231 additions and 306 deletions.
2 changes: 1 addition & 1 deletion pkg/filetree/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestAferoLoader(t *testing.T) {
testResources[resource.Key.(string)] = resource.Value.(string)
}

mockState.EXPECT().TryLoad().Return(state.VersionedState{
mockState.EXPECT().TryLoad().Return(state.State{
V1: &state.V1{
Kustomize: &state.Kustomize{
Overlays: map[string]state.Overlay{
Expand Down
20 changes: 10 additions & 10 deletions pkg/lifecycle/daemon/headless/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestHeadlessDaemon(t *testing.T) {
},
{
Name: "one group one item, not required, no value",
State: []byte(`{"alpha": ""}`),
State: []byte(`{"v1":{"config":{"alpha":""}}}`),
Release: &api.Release{
Spec: api.Spec{
Config: api.Config{
Expand All @@ -68,7 +68,7 @@ func TestHeadlessDaemon(t *testing.T) {
},
{
Name: "one group one item, required, no value",
State: []byte(`{"alpha": ""}`),
State: []byte(`{"v1":{"config":{"alpha":""}}}`),
Release: &api.Release{
Spec: api.Spec{
Config: api.Config{
Expand Down Expand Up @@ -188,7 +188,7 @@ func TestHeadlessDaemon(t *testing.T) {
},
{
Name: "one group one item, required, value, not hidden",
State: []byte(`{"alpha": "100"}`),
State: []byte(`{"v1":{"config":{"alpha": "100"}}}`),
Release: &api.Release{
Spec: api.Spec{
Config: api.Config{
Expand All @@ -212,7 +212,7 @@ func TestHeadlessDaemon(t *testing.T) {
},
{
Name: "one group one item, not required, no value, not hidden",
State: []byte(`{"alpha": ""}`),
State: []byte(`{"v1":{"config":{"alpha": ""}}}`),
Release: &api.Release{
Spec: api.Spec{
Config: api.Config{
Expand Down Expand Up @@ -260,7 +260,7 @@ func TestHeadlessDaemon(t *testing.T) {
},
{
Name: "one group two items, neither required, neither present",
State: []byte(`{"alpha": "", "beta": ""}`),
State: []byte(`{"v1":{"config":{"alpha": "", "beta": ""}}}`),
Release: &api.Release{
Spec: api.Spec{
Config: api.Config{
Expand Down Expand Up @@ -291,7 +291,7 @@ func TestHeadlessDaemon(t *testing.T) {
},
{
Name: "one group two items, both required, neither present",
State: []byte(`{"alpha": "", "beta": ""}`),
State: []byte(`{"v1":{"config":{"alpha": "", "beta": ""}}}`),
Release: &api.Release{
Spec: api.Spec{
Config: api.Config{
Expand Down Expand Up @@ -322,7 +322,7 @@ func TestHeadlessDaemon(t *testing.T) {
},
{
Name: "one group two items, both required, one present",
State: []byte(`{"alpha":"", "beta": ""}`),
State: []byte(`{"v1":{"config":{"alpha":"", "beta": ""}}}`),
Release: &api.Release{
Spec: api.Spec{
Config: api.Config{
Expand Down Expand Up @@ -384,7 +384,7 @@ func TestHeadlessDaemon(t *testing.T) {
},
{
Name: "beta value resolves to alpha value",
State: []byte(`{"alpha": "101"}`),
State: []byte(`{"v1":{"config":{"alpha": "101"}}}`),
Release: &api.Release{
Spec: api.Spec{
Config: api.Config{
Expand Down Expand Up @@ -415,7 +415,7 @@ func TestHeadlessDaemon(t *testing.T) {
},
{
Name: "beta value resolves to alpha value when wrong beta value is presented",
State: []byte(`{"alpha": "101", "beta":"abc"}`),
State: []byte(`{"v1":{"config":{"alpha": "101", "beta":"abc"}}}`),
Release: &api.Release{
Spec: api.Spec{
Config: api.Config{
Expand Down Expand Up @@ -446,7 +446,7 @@ func TestHeadlessDaemon(t *testing.T) {
},
{
Name: "charlie value resolves to beta value resolves to alpha value",
State: []byte(`{"alpha": "100"}`),
State: []byte(`{"v1":{"config":{"alpha":"100"}}}`),
Release: &api.Release{
Spec: api.Spec{
Config: api.Config{
Expand Down
3 changes: 2 additions & 1 deletion pkg/lifecycle/daemon/routes_navcycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ func (d *NavcycleRoutes) getRequiredButIncompleteStepFor(requires []string) (str
if err != nil {
return "", errors.Wrap(err, "load state")
}
if currentState.Versioned().V1.Lifecycle != nil &&
if currentState.Versioned().V1 != nil &&
currentState.Versioned().V1.Lifecycle != nil &&
currentState.Versioned().V1.Lifecycle.StepsCompleted != nil {
stepsCompleted = currentState.Versioned().V1.Lifecycle.StepsCompleted
debug.Log("event", "steps.notEmpty", "completed", fmt.Sprintf("%v", stepsCompleted))
Expand Down
2 changes: 1 addition & 1 deletion pkg/lifecycle/daemon/routes_navcycle_completestep.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (d *NavcycleRoutes) handleAsync(errChan chan error, debug log.Logger, step
return
}

_, err := d.StateManager.StateUpdate(func(currentState state.VersionedState) (state.VersionedState, error) {
_, err := d.StateManager.StateUpdate(func(currentState state.State) (state.State, error) {
return currentState.WithCompletedStep(step), nil
})
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions pkg/lifecycle/daemon/routes_navcycle_completestep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestV2CompleteStep(t *testing.T) {
ExpectState: &matchers.Is{
Describe: "saved state has step foo completed",
Test: func(v interface{}) bool {
if versioned, ok := v.(state2.VersionedState); ok {
if versioned, ok := v.(state2.State); ok {
_, ok := versioned.V1.Lifecycle.StepsCompleted["foo"]
return ok
}
Expand Down Expand Up @@ -168,7 +168,7 @@ func TestV2CompleteStep(t *testing.T) {
ExpectState: &matchers.Is{
Describe: "saved state has step foo completed and bar uncompleted",
Test: func(v interface{}) bool {
if versioned, ok := v.(state2.VersionedState); ok {
if versioned, ok := v.(state2.State); ok {
_, fooOk := versioned.V1.Lifecycle.StepsCompleted["foo"]
_, barOk := versioned.V1.Lifecycle.StepsCompleted["bar"]
return fooOk && !barOk
Expand Down Expand Up @@ -197,7 +197,7 @@ func TestV2CompleteStep(t *testing.T) {
ExpectState: &matchers.Is{
Describe: "saved state has step foo and bar completed",
Test: func(v interface{}) bool {
if versioned, ok := v.(state2.VersionedState); ok {
if versioned, ok := v.(state2.State); ok {
_, fooOk := versioned.V1.Lifecycle.StepsCompleted["foo"]
_, barOk := versioned.V1.Lifecycle.StepsCompleted["bar"]
return fooOk && barOk
Expand Down Expand Up @@ -226,7 +226,7 @@ func TestV2CompleteStep(t *testing.T) {
ExpectState: &matchers.Is{
Describe: "saved state has step foo completed and step bar invalidated",
Test: func(v interface{}) bool {
if versioned, ok := v.(state2.VersionedState); ok {
if versioned, ok := v.(state2.State); ok {
_, fooOk := versioned.V1.Lifecycle.StepsCompleted["foo"]
_, barOk := versioned.V1.Lifecycle.StepsCompleted["bar"]
return fooOk && !barOk
Expand Down Expand Up @@ -299,7 +299,7 @@ func TestV2CompleteStep(t *testing.T) {
ExpectState: &matchers.Is{
Describe: "saved state has step make-the-things completed",
Test: func(v interface{}) bool {
if versioned, ok := v.(state2.VersionedState); ok {
if versioned, ok := v.(state2.State); ok {
_, ok := versioned.V1.Lifecycle.StepsCompleted["make-the-things"]
return ok
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/lifecycle/daemon/routes_navcycle_getstep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func TestV2GetStep(t *testing.T) {
StepProgress: progressmap,
}

fakeState.EXPECT().TryLoad().Return(state2.VersionedState{
fakeState.EXPECT().TryLoad().Return(state2.State{
V1: &state2.V1{
Lifecycle: test.State,
},
Expand Down Expand Up @@ -442,7 +442,7 @@ func TestHydrateStep(t *testing.T) {
},
},
},
state: state2.V0{},
state: state2.State{V1: &state2.V1{}},
want: &daemontypes.StepResponse{
CurrentStep: daemontypes.Step{
Source: api.Step{
Expand Down Expand Up @@ -492,7 +492,7 @@ func TestHydrateStep(t *testing.T) {
},
Spec: api.Spec{},
},
state: state2.VersionedState{
state: state2.State{
V1: &state2.V1{
HelmValues: "fake: values",
ReleaseName: "fake-releasename",
Expand Down Expand Up @@ -563,7 +563,7 @@ func TestHydrateStep(t *testing.T) {
mockFs := afero.Afero{Fs: afero.NewMemMapFs()}
mockState := state.NewMockManager(mc)

if test.state != nil {
if !test.state.IsEmpty() {
mockState.EXPECT().TryLoad().Return(test.state, nil)
mockState.EXPECT().TryLoad().Return(test.state, nil)
}
Expand Down Expand Up @@ -636,7 +636,7 @@ func TestHydrateTemplatedKustomizeStep(t *testing.T) {
},
},
},
state: state2.V0{},
state: state2.State{V1: &state2.V1{}},
want: &daemontypes.StepResponse{
CurrentStep: daemontypes.Step{
Source: api.Step{
Expand Down Expand Up @@ -696,7 +696,7 @@ func TestHydrateTemplatedKustomizeStep(t *testing.T) {
progressmap := &daemontypes.ProgressMap{}
mockFs := afero.Afero{Fs: afero.NewMemMapFs()}
mockState := state.NewMockManager(mc)
if test.state != nil {
if !test.state.IsEmpty() {
mockState.EXPECT().TryLoad().Return(test.state, nil)
mockState.EXPECT().TryLoad().Return(test.state, nil)
mockState.EXPECT().TryLoad().Return(test.state, nil)
Expand Down
4 changes: 2 additions & 2 deletions pkg/lifecycle/daemon/routes_navcycle_kustomize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func TestV2KustomizeSaveFile(t *testing.T) {
StepProgress: progressmap,
}

fakeState.EXPECT().TryLoad().Return(state.VersionedState{
fakeState.EXPECT().TryLoad().Return(state.State{
V1: &test.InState,
}, nil).AnyTimes()

Expand Down Expand Up @@ -269,7 +269,7 @@ func TestV2KustomizeDeleteFile(t *testing.T) {
StepProgress: progressmap,
}

fakeState.EXPECT().TryLoad().Return(state.VersionedState{
fakeState.EXPECT().TryLoad().Return(state.State{
V1: &test.InState,
}, nil).AnyTimes()

Expand Down
4 changes: 2 additions & 2 deletions pkg/lifecycle/kustomize/kustomizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ resources:
mockDaemon := daemon2.NewMockDaemon(mc)
mockState := state2.NewMockManager(mc)

mockState.EXPECT().TryLoad().Return(state.VersionedState{
mockState.EXPECT().TryLoad().Return(state.State{
V1: &state.V1{
Kustomize: &state.Kustomize{
Overlays: map[string]state.Overlay{
Expand Down Expand Up @@ -508,7 +508,7 @@ resources:
BasePath: constants.KustomizeBasePath,
})
mockDaemon.EXPECT().KustomizeSavedChan().Return(saveChan)
mockState.EXPECT().TryLoad().Return(state.VersionedState{V1: &state.V1{
mockState.EXPECT().TryLoad().Return(state.State{V1: &state.V1{
Kustomize: test.kustomize,
}}, nil).Times(2)

Expand Down
2 changes: 1 addition & 1 deletion pkg/lifecycle/kustomize/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (l *Kustomizer) generateTillerPatches(step api.Kustomize) error {
if err != nil {
return errors.Wrap(err, "load state")
}
if state != nil && state.CurrentKustomize() != nil {
if state.V1 != nil && state.CurrentKustomize() != nil {
excludedBases = state.CurrentKustomize().Ship().ExcludedBases
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/lifecycle/kustomize/patch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ metadata:

stateManager := state.NewManager(log.NewNopLogger(), mockFs, viper.New())

err := stateManager.Save(state.VersionedState{V1: &state.V1{Kustomize: &state.Kustomize{}}})
err := stateManager.Save(state.State{V1: &state.V1{Kustomize: &state.Kustomize{}}})
req.NoError(err)

l := &Kustomizer{
Expand Down
2 changes: 1 addition & 1 deletion pkg/lifecycle/kustomize/pre_kustomize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ spec:
req.NoError(err)

actualLists := make([]util.List, 0)
if currentState.Versioned().V1.Metadata != nil {
if currentState.V1 != nil && currentState.V1.Metadata != nil {
actualLists = currentState.Versioned().V1.Metadata.Lists
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/lifecycle/render/helm/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestLocalTemplater(t *testing.T) {
expectedChannelName string
expectHelmOpts *matchers.Is
ontemplate func(req *require.Assertions, mockFs afero.Afero) func(chartRoot string, args []string) error
state *state2.VersionedState
state *state2.State
requirements *chartutil.Requirements
repoAdd []string
namespace string
Expand Down Expand Up @@ -130,7 +130,7 @@ func TestLocalTemplater(t *testing.T) {
name: "helm template with namespace in state",
describe: "template uses namespace from state",
expectError: "",
state: &state2.VersionedState{
state: &state2.State{
V1: &state2.V1{
Namespace: "test-namespace",
},
Expand Down Expand Up @@ -172,7 +172,7 @@ func TestLocalTemplater(t *testing.T) {
}

if test.state == nil {
mockState.EXPECT().TryLoad().Return(state2.VersionedState{
mockState.EXPECT().TryLoad().Return(state2.State{
V1: &state2.V1{
HelmValues: "we fake",
ReleaseName: channelName,
Expand Down Expand Up @@ -787,7 +787,7 @@ something: maybe
err := mockFs.WriteFile(tt.defaultValuesPath, []byte(tt.defaultValuesContent), 0755)
req.NoError(err)

mockState.EXPECT().TryLoad().Return(state2.VersionedState{V1: &state2.V1{}}, nil)
mockState.EXPECT().TryLoad().Return(state2.State{V1: &state2.V1{}}, nil)
f := &LocalTemplater{
Logger: &logger.TestLogger{T: t},
FS: mockFs,
Expand Down
11 changes: 8 additions & 3 deletions pkg/lifecycle/render/noconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestRenderNoConfig(t *testing.T) {

tests := loadTestCases(t, filepath.Join("test-cases", "render-inline.yaml"))

for _, test := range tests[:1] {
for _, test := range tests {
t.Run(test.Name, func(t *testing.T) {
mc := gomock.NewController(t)

Expand Down Expand Up @@ -57,10 +57,15 @@ func TestRenderNoConfig(t *testing.T) {
func() {
defer mc.Finish()

mockState.EXPECT().TryLoad().Return(state.V0(test.ViperConfig), nil)
mockState.EXPECT().TryLoad().Return(state.State{V1: &state.V1{Config: test.ViperConfig}}, nil)

expectedConfig := test.ViperConfig
if expectedConfig == nil {
expectedConfig = make(map[string]interface{})
}

p.EXPECT().
Build("testdir", test.Spec.Assets.V1, test.Spec.Config.V1, gomock.Any(), test.ViperConfig).
Build("testdir", test.Spec.Assets.V1, test.Spec.Config.V1, gomock.Any(), expectedConfig).
Return(planner.Plan{}, nil)

p.EXPECT().
Expand Down
Loading

0 comments on commit 00638c4

Please sign in to comment.