(t *testing.T)
| 28 | ) |
| 29 | |
| 30 | func TestIsReady(t *testing.T) { |
| 31 | validConf := &conf.Bootstrap_CASServer{ |
| 32 | Grpc: &conf.Server_GRPC{Addr: "localhost:1111"}, |
| 33 | } |
| 34 | |
| 35 | testCases := []struct { |
| 36 | name string |
| 37 | config *conf.Bootstrap_CASServer |
| 38 | casReady bool |
| 39 | want bool |
| 40 | wantErr bool |
| 41 | }{ |
| 42 | { |
| 43 | name: "missing configuration", |
| 44 | config: &conf.Bootstrap_CASServer{}, |
| 45 | wantErr: true, |
| 46 | }, |
| 47 | { |
| 48 | name: "invalid configuration", |
| 49 | config: &conf.Bootstrap_CASServer{Grpc: &conf.Server_GRPC{}}, |
| 50 | wantErr: true, |
| 51 | }, |
| 52 | { |
| 53 | name: "not ready configuration", |
| 54 | config: validConf, |
| 55 | wantErr: false, |
| 56 | }, |
| 57 | { |
| 58 | name: "ready configuration", |
| 59 | config: validConf, |
| 60 | casReady: true, |
| 61 | want: true, |
| 62 | wantErr: false, |
| 63 | }, |
| 64 | } |
| 65 | |
| 66 | for _, tc := range testCases { |
| 67 | t.Run(tc.name, func(_ *testing.T) { |
| 68 | clientProvider := func(_ *conf.Bootstrap_CASServer, _ string) (casclient.DownloaderUploader, func(), error) { |
| 69 | c := mocks.NewDownloaderUploader(t) |
| 70 | c.On("IsReady", mock.Anything).Return(tc.casReady, nil) |
| 71 | return c, func() {}, nil |
| 72 | } |
| 73 | uc := biz.NewCASClientUseCase(nil, tc.config, nil, biz.WithClientFactory(clientProvider)) |
| 74 | |
| 75 | got, err := uc.IsReady(context.Background()) |
| 76 | if tc.wantErr { |
| 77 | assert.Error(t, err) |
| 78 | } else { |
| 79 | assert.NoError(t, err) |
| 80 | } |
| 81 | assert.Equal(t, tc.want, got) |
| 82 | }) |
| 83 | } |
| 84 | } |
nothing calls this directly
no test coverage detected