github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/internal/controllers/core/uibutton/reconciler_test.go (about)

     1  package uibutton
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
     8  	"k8s.io/apimachinery/pkg/types"
     9  
    10  	"github.com/tilt-dev/tilt/internal/controllers/fake"
    11  	"github.com/tilt-dev/tilt/internal/hud/server"
    12  	"github.com/tilt-dev/tilt/internal/store"
    13  	"github.com/tilt-dev/tilt/pkg/apis/core/v1alpha1"
    14  )
    15  
    16  func TestDefault(t *testing.T) {
    17  	f := newFixture(t)
    18  
    19  	b := v1alpha1.UIButton{
    20  		ObjectMeta: metav1.ObjectMeta{
    21  			Name: "my-button",
    22  		},
    23  		Spec: v1alpha1.UIButtonSpec{
    24  			Text: "Hello world!",
    25  		},
    26  	}
    27  	f.Create(&b)
    28  
    29  	f.MustGet(types.NamespacedName{Name: "my-button"}, &b)
    30  	assert.Equal(t, "dbcfa71870a98e800b0a", b.Annotations[annotationSpecHash])
    31  	f.assertSteadyState(&b)
    32  }
    33  
    34  type fixture struct {
    35  	*fake.ControllerFixture
    36  	r *Reconciler
    37  }
    38  
    39  func newFixture(t *testing.T) *fixture {
    40  	cfb := fake.NewControllerFixtureBuilder(t)
    41  	st := store.NewTestingStore()
    42  	r := NewReconciler(cfb.Client, server.NewWebsocketList(), st)
    43  	return &fixture{
    44  		ControllerFixture: cfb.Build(r),
    45  		r:                 r,
    46  	}
    47  }
    48  
    49  func (f *fixture) assertSteadyState(b *v1alpha1.UIButton) {
    50  	f.T().Helper()
    51  	f.MustReconcile(types.NamespacedName{Name: b.Name})
    52  	var b2 v1alpha1.UIButton
    53  	f.MustGet(types.NamespacedName{Name: b.Name}, &b2)
    54  	assert.Equal(f.T(), b.ResourceVersion, b2.ResourceVersion)
    55  }