Skip to content

Commit

Permalink
uisession: remove actions/reducers (#4595)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicks committed Jun 1, 2021
1 parent aaec318 commit a8d576b
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 259 deletions.
62 changes: 0 additions & 62 deletions internal/engine/uiresource/actions.go

This file was deleted.

29 changes: 0 additions & 29 deletions internal/engine/uiresource/reducers.go

This file was deleted.

3 changes: 0 additions & 3 deletions internal/engine/uiresource/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ func (s *Subscriber) OnChange(ctx context.Context, st store.RStore, summary stor
st.Dispatch(store.NewErrorAction(fmt.Errorf("deleting resource %s: %v", name.Name, err)))
return
}
st.Dispatch(NewUIResourceDeleteAction(name))
continue
}

Expand All @@ -91,7 +90,6 @@ func (s *Subscriber) OnChange(ctx context.Context, st store.RStore, summary stor
logger.Get(ctx).Infof("creating uiresource %s: %v", name.Name, err)
return
}
st.Dispatch(NewUIResourceCreateAction(resource))
continue
}

Expand All @@ -107,7 +105,6 @@ func (s *Subscriber) OnChange(ctx context.Context, st store.RStore, summary stor
logger.Get(ctx).Infof("updating uiresource %s: %v", name.Name, err)
return
}
st.Dispatch(NewUIResourceUpdateStatusAction(update))
continue
}
}
Expand Down
82 changes: 37 additions & 45 deletions internal/engine/uiresource/subscriber_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package uiresource

import (
"context"
"sort"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"

"github.com/tilt-dev/tilt/internal/controllers/fake"
"github.com/tilt-dev/tilt/internal/k8s/testyaml"
Expand All @@ -21,31 +24,36 @@ func TestCreate(t *testing.T) {
defer f.TearDown()

f.sub.OnChange(f.ctx, f.store, store.LegacyChangeSummary())
assert.Equal(t, 1, len(f.store.Actions()))
assert.Equal(t, "(Tiltfile)",
f.store.Actions()[0].(UIResourceCreateAction).UIResource.Name)

r := f.resource("(Tiltfile)")
require.NotNil(t, r)
assert.Equal(t, "(Tiltfile)", r.ObjectMeta.Name)
assert.Equal(t, "1", r.ObjectMeta.ResourceVersion)

f.sub.OnChange(f.ctx, f.store, store.LegacyChangeSummary())
assert.Equal(t, 1, len(f.store.Actions()))
r = f.resource("(Tiltfile)")
assert.Equal(t, "1", r.ObjectMeta.ResourceVersion)
}

func TestUpdateTiltfile(t *testing.T) {
f := newFixture(t)
defer f.TearDown()

f.sub.OnChange(f.ctx, f.store, store.LegacyChangeSummary())
assert.Equal(t, 1, len(f.store.Actions()))
assert.Equal(t, "(Tiltfile)",
f.store.Actions()[0].(UIResourceCreateAction).UIResource.Name)
r := f.resource("(Tiltfile)")
require.NotNil(t, r)
assert.Equal(t, "(Tiltfile)", r.ObjectMeta.Name)
assert.Equal(t, "1", r.ObjectMeta.ResourceVersion)

f.store.WithState(func(es *store.EngineState) {
es.TiltfileState.CurrentBuild.StartTime = time.Now()
})

f.sub.OnChange(f.ctx, f.store, store.LegacyChangeSummary())
assert.Equal(t, 2, len(f.store.Actions()))
assert.Equal(t, v1alpha1.UpdateStatusInProgress,
f.store.Actions()[1].(UIResourceUpdateStatusAction).Status.UpdateStatus)

r = f.resource("(Tiltfile)")
require.NotNil(t, r)
assert.Equal(t, "2", r.ObjectMeta.ResourceVersion)
}

func TestDeleteManifest(t *testing.T) {
Expand All @@ -60,48 +68,22 @@ func TestDeleteManifest(t *testing.T) {
})

f.sub.OnChange(f.ctx, f.store, store.LegacyChangeSummary())
assert.Equal(t, 2, len(f.store.Actions()))

names := []string{
f.store.Actions()[0].(UIResourceCreateAction).UIResource.Name,
f.store.Actions()[1].(UIResourceCreateAction).UIResource.Name,
}
sort.Strings(names)
assert.Equal(t, []string{"(Tiltfile)", "fe"}, names)
assert.Equal(t, "(Tiltfile)", f.resource("(Tiltfile)").ObjectMeta.Name)
assert.Equal(t, "fe", f.resource("fe").ObjectMeta.Name)

f.store.WithState(func(state *store.EngineState) {
state.RemoveManifestTarget("fe")
})

f.sub.OnChange(f.ctx, f.store, store.LegacyChangeSummary())
assert.Equal(t, 3, len(f.store.Actions()))
assert.Equal(t, "fe",
f.store.Actions()[2].(UIResourceDeleteAction).Name.Name)
}

type testStore struct {
*store.TestingStore
}

func (s *testStore) Dispatch(a store.Action) {
s.TestingStore.Dispatch(a)

state := s.LockMutableStateForTesting()
defer s.UnlockMutableState()
switch a := a.(type) {
case UIResourceUpdateStatusAction:
HandleUIResourceUpdateStatusAction(state, a)
case UIResourceCreateAction:
HandleUIResourceCreateAction(state, a)
case UIResourceDeleteAction:
HandleUIResourceDeleteAction(state, a)
}
assert.Nil(t, f.resource("fe"))
}

type fixture struct {
*tempdir.TempDirFixture
ctx context.Context
store *testStore
store *store.TestingStore
tc ctrlclient.Client
sub *Subscriber
}

Expand All @@ -110,9 +92,19 @@ func newFixture(t *testing.T) *fixture {
return &fixture{
TempDirFixture: tempdir.NewTempDirFixture(t),
ctx: context.Background(),
tc: tc,
sub: NewSubscriber(tc),
store: &testStore{
TestingStore: store.NewTestingStore(),
},
store: store.NewTestingStore(),
}
}

func (f *fixture) resource(name string) *v1alpha1.UIResource {
r := &v1alpha1.UIResource{}
err := f.tc.Get(f.ctx, types.NamespacedName{Name: name}, r)
if apierrors.IsNotFound(err) {
return nil
}

require.NoError(f.T(), err)
return r
}
48 changes: 0 additions & 48 deletions internal/engine/uisession/actions.go

This file was deleted.

25 changes: 0 additions & 25 deletions internal/engine/uisession/reducers.go

This file was deleted.

2 changes: 0 additions & 2 deletions internal/engine/uisession/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func (s *Subscriber) OnChange(ctx context.Context, st store.RStore, summary stor
logger.Get(ctx).Infof("creating uisession: %v", err)
return
}
st.Dispatch(NewUISessionCreateAction(session))
return
} else if err != nil {
logger.Get(ctx).Infof("fetching uisession: %v", err)
Expand All @@ -59,7 +58,6 @@ func (s *Subscriber) OnChange(ctx context.Context, st store.RStore, summary stor
logger.Get(ctx).Infof("updating uisession: %v", err)
return
}
st.Dispatch(NewUISessionUpdateStatusAction(update))
}
}

Expand Down

0 comments on commit a8d576b

Please sign in to comment.