github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/internal/engine/configs/configs_controller_test.go (about) 1 package configs 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/require" 9 "k8s.io/apimachinery/pkg/types" 10 11 "github.com/tilt-dev/tilt/internal/controllers/apis/tiltfile" 12 "github.com/tilt-dev/tilt/internal/controllers/apis/uibutton" 13 "github.com/tilt-dev/tilt/internal/controllers/fake" 14 "github.com/tilt-dev/tilt/internal/store" 15 "github.com/tilt-dev/tilt/pkg/apis/core/v1alpha1" 16 "github.com/tilt-dev/tilt/pkg/model" 17 ) 18 19 func TestCreateTiltfile(t *testing.T) { 20 st := store.NewTestingStore() 21 st.WithState(func(s *store.EngineState) { 22 s.DesiredTiltfilePath = "./fake-tiltfile-path" 23 s.UserConfigState = model.NewUserConfigState([]string{"arg1", "arg2"}) 24 }) 25 ctx := context.Background() 26 client := fake.NewFakeTiltClient() 27 cc := NewConfigsController(client) 28 require.NoError(t, cc.OnChange(ctx, st, store.ChangeSummary{})) 29 30 var tf v1alpha1.Tiltfile 31 require.NoError(t, client.Get(ctx, types.NamespacedName{Name: model.MainTiltfileManifestName.String()}, &tf)) 32 expectedTfSpec := v1alpha1.TiltfileSpec{ 33 Path: tiltfile.ResolveFilename("fake-tiltfile-path"), 34 Args: []string{"arg1", "arg2"}, 35 RestartOn: &v1alpha1.RestartOnSpec{ 36 FileWatches: []string{"configs:(Tiltfile)"}, 37 }, 38 StopOn: &v1alpha1.StopOnSpec{ 39 UIButtons: []string{uibutton.StopBuildButtonName("(Tiltfile)")}, 40 }, 41 } 42 assert.Equal(t, expectedTfSpec, tf.Spec) 43 44 var actualButton v1alpha1.UIButton 45 name := types.NamespacedName{Name: uibutton.StopBuildButtonName(model.MainTiltfileManifestName.String())} 46 err := client.Get(ctx, name, &actualButton) 47 require.NoError(t, err) 48 expectedButton := uibutton.StopBuildButton(model.MainTiltfileManifestName.String()) 49 assert.Equal(t, expectedButton.Spec, actualButton.Spec) 50 }