github.com/quay/claircore@v1.5.28/indexer/controller/indexfinished_test.go (about)

     1  package controller
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/golang/mock/gomock"
     8  	"github.com/quay/zlog"
     9  
    10  	indexer "github.com/quay/claircore/test/mock/indexer"
    11  )
    12  
    13  func TestIndexFinished(t *testing.T) {
    14  	ctx := context.Background()
    15  	tt := []struct {
    16  		name          string
    17  		expectedState State
    18  		mock          func(t *testing.T) indexer.Store
    19  	}{
    20  		{
    21  			name:          "Success",
    22  			expectedState: Terminal,
    23  			mock: func(t *testing.T) indexer.Store {
    24  				ctrl := gomock.NewController(t)
    25  				m := indexer.NewMockStore(ctrl)
    26  
    27  				m.EXPECT().SetIndexFinished(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
    28  
    29  				return m
    30  			},
    31  		},
    32  	}
    33  
    34  	for _, table := range tt {
    35  		t.Run(table.name, func(t *testing.T) {
    36  			ctx := zlog.Test(ctx, t)
    37  			store := table.mock(t)
    38  			scnr := New(&indexer.Options{
    39  				Store: store,
    40  			})
    41  
    42  			state, err := indexFinished(ctx, scnr)
    43  			if err != nil {
    44  				t.Error(err)
    45  			}
    46  			if got, want := state, table.expectedState; got != want {
    47  				t.Errorf("got: %v, want: %v", got, want)
    48  			}
    49  		})
    50  	}
    51  }