|
|
@ -139,13 +139,12 @@ func Test_SetupSuccessNoninteractive(t *testing.T) {
|
|
|
|
assert.Equal(t, retentionSecs, *body.RetentionPeriodSeconds)
|
|
|
|
assert.Equal(t, retentionSecs, *body.RetentionPeriodSeconds)
|
|
|
|
})).Return(resp, nil)
|
|
|
|
})).Return(resp, nil)
|
|
|
|
|
|
|
|
|
|
|
|
host := "fake-host"
|
|
|
|
|
|
|
|
configSvc := mock.NewMockConfigService(ctrl)
|
|
|
|
configSvc := mock.NewMockConfigService(ctrl)
|
|
|
|
configSvc.EXPECT().ListConfigs().Return(nil, nil)
|
|
|
|
configSvc.EXPECT().ListConfigs().Return(nil, nil)
|
|
|
|
configSvc.EXPECT().CreateConfig(tmock.MatchedBy(func(in config.Config) bool {
|
|
|
|
configSvc.EXPECT().CreateConfig(tmock.MatchedBy(func(in config.Config) bool {
|
|
|
|
return assert.Equal(t, params.ConfigName, in.Name) &&
|
|
|
|
return assert.Equal(t, params.ConfigName, in.Name) &&
|
|
|
|
assert.Equal(t, params.AuthToken, in.Token) &&
|
|
|
|
assert.Equal(t, params.AuthToken, in.Token) &&
|
|
|
|
assert.Equal(t, host, in.Host) &&
|
|
|
|
assert.Equal(t, config.DefaultConfig.Host, in.Host) &&
|
|
|
|
assert.Equal(t, params.Org, in.Org)
|
|
|
|
assert.Equal(t, params.Org, in.Org)
|
|
|
|
})).DoAndReturn(func(in config.Config) (config.Config, error) {
|
|
|
|
})).DoAndReturn(func(in config.Config) (config.Config, error) {
|
|
|
|
return in, nil
|
|
|
|
return in, nil
|
|
|
@ -155,7 +154,7 @@ func Test_SetupSuccessNoninteractive(t *testing.T) {
|
|
|
|
bytesWritten := bytes.Buffer{}
|
|
|
|
bytesWritten := bytes.Buffer{}
|
|
|
|
stdio.EXPECT().Write(gomock.Any()).DoAndReturn(bytesWritten.Write).AnyTimes()
|
|
|
|
stdio.EXPECT().Write(gomock.Any()).DoAndReturn(bytesWritten.Write).AnyTimes()
|
|
|
|
cli := setup.Client{
|
|
|
|
cli := setup.Client{
|
|
|
|
CLI: clients.CLI{ConfigService: configSvc, ActiveConfig: config.Config{Host: host}, StdIO: stdio},
|
|
|
|
CLI: clients.CLI{ConfigService: configSvc, ActiveConfig: config.Config{}, StdIO: stdio},
|
|
|
|
SetupApi: client,
|
|
|
|
SetupApi: client,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
require.NoError(t, cli.Setup(context.Background(), ¶ms))
|
|
|
|
require.NoError(t, cli.Setup(context.Background(), ¶ms))
|
|
|
@ -198,13 +197,12 @@ func Test_SetupSuccessInteractive(t *testing.T) {
|
|
|
|
assert.Equal(t, retentionSecs, *body.RetentionPeriodSeconds)
|
|
|
|
assert.Equal(t, retentionSecs, *body.RetentionPeriodSeconds)
|
|
|
|
})).Return(resp, nil)
|
|
|
|
})).Return(resp, nil)
|
|
|
|
|
|
|
|
|
|
|
|
host := "fake-host"
|
|
|
|
|
|
|
|
configSvc := mock.NewMockConfigService(ctrl)
|
|
|
|
configSvc := mock.NewMockConfigService(ctrl)
|
|
|
|
configSvc.EXPECT().ListConfigs().Return(nil, nil)
|
|
|
|
configSvc.EXPECT().ListConfigs().Return(nil, nil)
|
|
|
|
configSvc.EXPECT().CreateConfig(tmock.MatchedBy(func(in config.Config) bool {
|
|
|
|
configSvc.EXPECT().CreateConfig(tmock.MatchedBy(func(in config.Config) bool {
|
|
|
|
return assert.Equal(t, config.DefaultConfig.Name, in.Name) &&
|
|
|
|
return assert.Equal(t, config.DefaultConfig.Name, in.Name) &&
|
|
|
|
assert.Equal(t, token, in.Token) &&
|
|
|
|
assert.Equal(t, token, in.Token) &&
|
|
|
|
assert.Equal(t, host, in.Host) &&
|
|
|
|
assert.Equal(t, config.DefaultConfig.Host, in.Host) &&
|
|
|
|
assert.Equal(t, org, in.Org)
|
|
|
|
assert.Equal(t, org, in.Org)
|
|
|
|
})).DoAndReturn(func(in config.Config) (config.Config, error) {
|
|
|
|
})).DoAndReturn(func(in config.Config) (config.Config, error) {
|
|
|
|
return in, nil
|
|
|
|
return in, nil
|
|
|
@ -221,7 +219,7 @@ func Test_SetupSuccessInteractive(t *testing.T) {
|
|
|
|
stdio.EXPECT().GetStringInput("Please type your retention period in hours, or 0 for infinite", gomock.Any()).Return(strconv.Itoa(retentionHrs), nil)
|
|
|
|
stdio.EXPECT().GetStringInput("Please type your retention period in hours, or 0 for infinite", gomock.Any()).Return(strconv.Itoa(retentionHrs), nil)
|
|
|
|
stdio.EXPECT().GetConfirm(gomock.Any()).Return(true)
|
|
|
|
stdio.EXPECT().GetConfirm(gomock.Any()).Return(true)
|
|
|
|
cli := setup.Client{
|
|
|
|
cli := setup.Client{
|
|
|
|
CLI: clients.CLI{ConfigService: configSvc, ActiveConfig: config.Config{Host: host}, StdIO: stdio},
|
|
|
|
CLI: clients.CLI{ConfigService: configSvc, ActiveConfig: config.Config{}, StdIO: stdio},
|
|
|
|
SetupApi: client,
|
|
|
|
SetupApi: client,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
require.NoError(t, cli.Setup(context.Background(), &setup.Params{}))
|
|
|
|
require.NoError(t, cli.Setup(context.Background(), &setup.Params{}))
|
|
|
@ -231,7 +229,7 @@ func Test_SetupSuccessInteractive(t *testing.T) {
|
|
|
|
}, strings.Split(bytesWritten.String(), "\n"))
|
|
|
|
}, strings.Split(bytesWritten.String(), "\n"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func Test_SetupPasswordParamToShort(t *testing.T) {
|
|
|
|
func Test_SetupPasswordParamTooShort(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
|
|
|
|
retentionSecs := int64(duration.Week.Seconds())
|
|
|
|
retentionSecs := int64(duration.Week.Seconds())
|
|
|
@ -250,13 +248,12 @@ func Test_SetupPasswordParamToShort(t *testing.T) {
|
|
|
|
client.EXPECT().GetSetup(gomock.Any()).Return(api.ApiGetSetupRequest{ApiService: client})
|
|
|
|
client.EXPECT().GetSetup(gomock.Any()).Return(api.ApiGetSetupRequest{ApiService: client})
|
|
|
|
client.EXPECT().GetSetupExecute(gomock.Any()).Return(api.InlineResponse200{Allowed: api.PtrBool(true)}, nil)
|
|
|
|
client.EXPECT().GetSetupExecute(gomock.Any()).Return(api.InlineResponse200{Allowed: api.PtrBool(true)}, nil)
|
|
|
|
|
|
|
|
|
|
|
|
host := "fake-host"
|
|
|
|
|
|
|
|
configSvc := mock.NewMockConfigService(ctrl)
|
|
|
|
configSvc := mock.NewMockConfigService(ctrl)
|
|
|
|
configSvc.EXPECT().ListConfigs().Return(nil, nil)
|
|
|
|
configSvc.EXPECT().ListConfigs().Return(nil, nil)
|
|
|
|
|
|
|
|
|
|
|
|
stdio := mock.NewMockStdIO(ctrl)
|
|
|
|
stdio := mock.NewMockStdIO(ctrl)
|
|
|
|
cli := setup.Client{
|
|
|
|
cli := setup.Client{
|
|
|
|
CLI: clients.CLI{ConfigService: configSvc, ActiveConfig: config.Config{Host: host}, StdIO: stdio},
|
|
|
|
CLI: clients.CLI{ConfigService: configSvc, ActiveConfig: config.Config{}, StdIO: stdio},
|
|
|
|
SetupApi: client,
|
|
|
|
SetupApi: client,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
err := cli.Setup(context.Background(), ¶ms)
|
|
|
|
err := cli.Setup(context.Background(), ¶ms)
|
|
|
@ -282,7 +279,6 @@ func Test_SetupCancelAtConfirmation(t *testing.T) {
|
|
|
|
client.EXPECT().GetSetup(gomock.Any()).Return(api.ApiGetSetupRequest{ApiService: client})
|
|
|
|
client.EXPECT().GetSetup(gomock.Any()).Return(api.ApiGetSetupRequest{ApiService: client})
|
|
|
|
client.EXPECT().GetSetupExecute(gomock.Any()).Return(api.InlineResponse200{Allowed: api.PtrBool(true)}, nil)
|
|
|
|
client.EXPECT().GetSetupExecute(gomock.Any()).Return(api.InlineResponse200{Allowed: api.PtrBool(true)}, nil)
|
|
|
|
|
|
|
|
|
|
|
|
host := "fake-host"
|
|
|
|
|
|
|
|
configSvc := mock.NewMockConfigService(ctrl)
|
|
|
|
configSvc := mock.NewMockConfigService(ctrl)
|
|
|
|
configSvc.EXPECT().ListConfigs().Return(nil, nil)
|
|
|
|
configSvc.EXPECT().ListConfigs().Return(nil, nil)
|
|
|
|
|
|
|
|
|
|
|
@ -291,9 +287,72 @@ func Test_SetupCancelAtConfirmation(t *testing.T) {
|
|
|
|
stdio.EXPECT().GetConfirm(gomock.Any()).Return(false)
|
|
|
|
stdio.EXPECT().GetConfirm(gomock.Any()).Return(false)
|
|
|
|
|
|
|
|
|
|
|
|
cli := setup.Client{
|
|
|
|
cli := setup.Client{
|
|
|
|
CLI: clients.CLI{ConfigService: configSvc, ActiveConfig: config.Config{Host: host}, StdIO: stdio},
|
|
|
|
CLI: clients.CLI{ConfigService: configSvc, ActiveConfig: config.Config{}, StdIO: stdio},
|
|
|
|
SetupApi: client,
|
|
|
|
SetupApi: client,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
err := cli.Setup(context.Background(), ¶ms)
|
|
|
|
err := cli.Setup(context.Background(), ¶ms)
|
|
|
|
require.Equal(t, setup.ErrSetupCanceled, err)
|
|
|
|
require.Equal(t, setup.ErrSetupCanceled, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func Test_SetupNonDefaultHost(t *testing.T) {
|
|
|
|
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
retentionSecs := int64(duration.Week.Seconds())
|
|
|
|
|
|
|
|
params := setup.Params{
|
|
|
|
|
|
|
|
Username: "user",
|
|
|
|
|
|
|
|
Password: "mysecretpassword",
|
|
|
|
|
|
|
|
AuthToken: "mytoken",
|
|
|
|
|
|
|
|
Org: "org",
|
|
|
|
|
|
|
|
Bucket: "bucket",
|
|
|
|
|
|
|
|
Retention: fmt.Sprintf("%ds", retentionSecs),
|
|
|
|
|
|
|
|
Force: true,
|
|
|
|
|
|
|
|
ConfigName: "my-config",
|
|
|
|
|
|
|
|
Host: "https://my-server.foo",
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
resp := api.OnboardingResponse{
|
|
|
|
|
|
|
|
Auth: &api.Authorization{Token: ¶ms.AuthToken},
|
|
|
|
|
|
|
|
Org: &api.Organization{Name: params.Org},
|
|
|
|
|
|
|
|
User: &api.UserResponse{Name: params.Username},
|
|
|
|
|
|
|
|
Bucket: &api.Bucket{Name: params.Bucket},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctrl := gomock.NewController(t)
|
|
|
|
|
|
|
|
client := mock.NewMockSetupApi(ctrl)
|
|
|
|
|
|
|
|
client.EXPECT().GetSetup(gomock.Any()).Return(api.ApiGetSetupRequest{ApiService: client})
|
|
|
|
|
|
|
|
client.EXPECT().GetSetupExecute(gomock.Any()).Return(api.InlineResponse200{Allowed: api.PtrBool(true)}, nil)
|
|
|
|
|
|
|
|
client.EXPECT().PostSetup(gomock.Any()).Return(api.ApiPostSetupRequest{ApiService: client})
|
|
|
|
|
|
|
|
client.EXPECT().PostSetupExecute(tmock.MatchedBy(func(in api.ApiPostSetupRequest) bool {
|
|
|
|
|
|
|
|
body := in.GetOnboardingRequest()
|
|
|
|
|
|
|
|
return assert.NotNil(t, body) &&
|
|
|
|
|
|
|
|
assert.Equal(t, params.Username, body.Username) &&
|
|
|
|
|
|
|
|
assert.Equal(t, params.Password, *body.Password) &&
|
|
|
|
|
|
|
|
assert.Equal(t, params.AuthToken, *body.Token) &&
|
|
|
|
|
|
|
|
assert.Equal(t, params.Org, body.Org) &&
|
|
|
|
|
|
|
|
assert.Equal(t, params.Bucket, body.Bucket) &&
|
|
|
|
|
|
|
|
assert.Equal(t, retentionSecs, *body.RetentionPeriodSeconds)
|
|
|
|
|
|
|
|
})).Return(resp, nil)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configSvc := mock.NewMockConfigService(ctrl)
|
|
|
|
|
|
|
|
configSvc.EXPECT().ListConfigs().Return(nil, nil)
|
|
|
|
|
|
|
|
configSvc.EXPECT().CreateConfig(tmock.MatchedBy(func(in config.Config) bool {
|
|
|
|
|
|
|
|
return assert.Equal(t, params.ConfigName, in.Name) &&
|
|
|
|
|
|
|
|
assert.Equal(t, params.AuthToken, in.Token) &&
|
|
|
|
|
|
|
|
assert.Equal(t, params.Host, in.Host) &&
|
|
|
|
|
|
|
|
assert.Equal(t, params.Org, in.Org)
|
|
|
|
|
|
|
|
})).DoAndReturn(func(in config.Config) (config.Config, error) {
|
|
|
|
|
|
|
|
return in, nil
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stdio := mock.NewMockStdIO(ctrl)
|
|
|
|
|
|
|
|
bytesWritten := bytes.Buffer{}
|
|
|
|
|
|
|
|
stdio.EXPECT().Write(gomock.Any()).DoAndReturn(bytesWritten.Write).AnyTimes()
|
|
|
|
|
|
|
|
cli := setup.Client{
|
|
|
|
|
|
|
|
CLI: clients.CLI{ConfigService: configSvc, ActiveConfig: config.Config{}, StdIO: stdio},
|
|
|
|
|
|
|
|
SetupApi: client,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
require.NoError(t, cli.Setup(context.Background(), ¶ms))
|
|
|
|
|
|
|
|
testutils.MatchLines(t, []string{
|
|
|
|
|
|
|
|
`User\s+Organization\s+Bucket`,
|
|
|
|
|
|
|
|
fmt.Sprintf(`%s\s+%s\s+%s`, params.Username, params.Org, params.Bucket),
|
|
|
|
|
|
|
|
}, strings.Split(bytesWritten.String(), "\n"))
|
|
|
|
|
|
|
|
}
|
|
|
|