[resultstore] Refactor UploadClient tests to be table driven
Change-Id: Id40ac7576cea24a2d8c936cb999cd990d89511ad
diff --git a/resultstore/upload_client_test.go b/resultstore/upload_client_test.go
index 40661d9..f4c7085 100644
--- a/resultstore/upload_client_test.go
+++ b/resultstore/upload_client_test.go
@@ -22,578 +22,506 @@
// The value of entity start times and durations is not important for these tests,
// so we use the same value everywhere.
may18_1993 = time.Date(1993, time.May, 18, 0, 0, 0, 0, time.UTC)
+)
+const (
// The specific values of the UUIDs are not important for these tests. We just want to
// verify that the client sets some value other than the empty string, so we just use
// the same UUID everywhere.
testUUID = "uuid"
+
+ // The specific value of the auth token included in requests is not important. What
+ // matters is that the value in an RPC matches the value given to the UploadClient.
+ // Reuse this same value in all test cases.
+ testAuthToken = "auth_token"
)
-// uploadClientTestBed manages the setup and teardown phases of individual test cases.
-type uploadClientTestBed struct {
- MockRPCClient *mocks.MockResultStoreUploadClient
- ctrl *gomock.Controller
+type tester struct {
+ client resultstore.UploadClient
+ mock *mocks.MockResultStoreUploadClient
}
-// Setup creates the client-under-test and should be run before every test case.
-func (bed *uploadClientTestBed) Setup(t *testing.T, authToken string) (resultstore.UploadClient, context.Context) {
- // Cache the mock controller so we can Finish() it during test teardown.
- bed.ctrl = gomock.NewController(t)
- bed.MockRPCClient = mocks.NewMockResultStoreUploadClient(bed.ctrl)
+func TestUploadClient(t *testing.T) {
+ tests := []struct {
+ // The method being tested. Keep tests ordered alphabetically by method name.
+ method string
- // Force UploadClient to re-use a fake UUID for testing by embedding the UUID in the
- // context object.
- ctx, err := resultstore.SetTestUUID(context.Background(), testUUID)
- if err != nil {
- t.Fatal(err)
+ // A brief test case description.
+ description string
+
+ // Exercises the method under test.
+ execute func(ctx context.Context, tester *tester) (interface{}, error)
+
+ // The expected output of the method
+ output interface{}
+ }{
+ {
+ method: "CreateConfiguration",
+ description: "should rmake an RPC to create a Configuration",
+ output: &resultstore.Configuration{
+ Name: "resultstore_configuration_name",
+ ID: "configuration_id",
+ InvocationID: "invocation_id",
+ },
+ execute: func(ctx context.Context, tester *tester) (interface{}, error) {
+ input := &resultstore.Configuration{
+ ID: "configuration_id",
+ InvocationID: "invocation_id",
+ Properties: map[string]string{"key": "value"},
+ }
+
+ response := &api.Configuration{
+ Name: "resultstore_configuration_name",
+ Id: &api.Configuration_Id{
+ ConfigurationId: "configuration_id",
+ InvocationId: "invocation_id",
+ },
+ }
+
+ tester.mock.EXPECT().
+ CreateConfiguration(ctx, &api.CreateConfigurationRequest{
+ RequestId: testUUID,
+ AuthorizationToken: testAuthToken,
+ Parent: "invocation_name",
+ ConfigId: "configuration_id",
+ Configuration: input.ToResultStoreConfiguration(),
+ }).
+ Return(response, nil)
+
+ return tester.client.CreateConfiguration(ctx, input, "invocation_name")
+ },
+ },
+ {
+ method: "CreateConfiguredTarget",
+ description: "should make an RPC to create a ConfiguredTarget",
+ output: &resultstore.ConfiguredTarget{
+ Name: "resultstore_configured_target_name",
+ ID: &resultstore.ConfiguredTargetID{
+ InvocationID: "invocation_id",
+ ConfigID: "configuration_id",
+ TargetID: "target_id",
+ },
+ },
+ execute: func(ctx context.Context, tester *tester) (interface{}, error) {
+ input := &resultstore.ConfiguredTarget{
+ ID: &resultstore.ConfiguredTargetID{
+ InvocationID: "invocation_id",
+ TargetID: "target_id",
+ ConfigID: "configuration_id",
+ },
+ Properties: map[string]string{"key": "value"},
+ StartTime: may18_1993,
+ Status: resultstore.Passed,
+ }
+
+ response := &api.ConfiguredTarget{
+ Name: "resultstore_configured_target_name",
+ Id: &api.ConfiguredTarget_Id{
+ InvocationId: "invocation_id",
+ ConfigurationId: "configuration_id",
+ TargetId: "target_id",
+ },
+ }
+
+ tester.mock.EXPECT().
+ CreateConfiguredTarget(ctx, &api.CreateConfiguredTargetRequest{
+ RequestId: testUUID,
+ AuthorizationToken: testAuthToken,
+ Parent: "target_name",
+ ConfigId: input.ID.ConfigID,
+ ConfiguredTarget: input.ToResultStoreConfiguredTarget(),
+ }).
+ Return(response, nil)
+
+ return tester.client.CreateConfiguredTarget(ctx, input, "target_name")
+ },
+ },
+ {
+ method: "CreateInvocation",
+ description: "should make an RPC to create an Invocation",
+ output: &resultstore.Invocation{
+ Name: "resultstore_invocation_name",
+ ID: "invocation_id",
+ },
+ execute: func(ctx context.Context, tester *tester) (interface{}, error) {
+ input := &resultstore.Invocation{
+ ProjectID: "123456789",
+ ID: "invocation_id",
+ Users: []string{"user"},
+ Labels: []string{"label"},
+ Properties: map[string]string{"key": "value"},
+ LogURL: "http://test.log",
+ StartTime: may18_1993,
+ Status: resultstore.Passed,
+ }
+
+ response := &api.Invocation{
+ Name: "resultstore_invocation_name",
+ Id: &api.Invocation_Id{
+ InvocationId: "invocation_id",
+ },
+ }
+
+ tester.mock.EXPECT().
+ CreateInvocation(ctx, &api.CreateInvocationRequest{
+ RequestId: testUUID,
+ AuthorizationToken: testAuthToken,
+ InvocationId: "invocation_id",
+ Invocation: input.ToResultStoreInvocation(),
+ }).
+ Return(response, nil)
+
+ return tester.client.CreateInvocation(ctx, input)
+ },
+ },
+ {
+ method: "CreateTarget",
+ description: "should make an RPC to create a Target",
+ output: &resultstore.Target{
+ Name: "resultstore_target_name",
+ ID: &resultstore.TargetID{
+ ID: "target_id",
+ InvocationID: "invocation_id",
+ },
+ },
+ execute: func(ctx context.Context, tester *tester) (interface{}, error) {
+ input := &resultstore.Target{
+ ID: &resultstore.TargetID{
+ ID: "target_id",
+ },
+ Properties: map[string]string{"key": "value"},
+ StartTime: may18_1993,
+ Status: resultstore.Passed,
+ }
+
+ response := &api.Target{
+ Name: "resultstore_target_name",
+ Id: &api.Target_Id{
+ TargetId: "target_id",
+ InvocationId: "invocation_id",
+ },
+ }
+
+ tester.mock.EXPECT().
+ CreateTarget(ctx, &api.CreateTargetRequest{
+ RequestId: testUUID,
+ AuthorizationToken: testAuthToken,
+ Parent: "invocation_name",
+ TargetId: input.ID.ID,
+ Target: input.ToResultStoreTarget(),
+ }).
+ Return(response, nil)
+
+ return tester.client.CreateTarget(ctx, input, "invocation_name")
+ },
+ },
+ {
+ method: "CreateTestAction",
+ description: "should make an RPC to create a Test Action",
+ output: &resultstore.TestAction{
+ Name: "resultstore_action_name",
+ ID: &resultstore.TestActionID{
+ InvocationID: "invocation_id",
+ ConfigID: "configuration_id",
+ TargetID: "target_id",
+ },
+ },
+ execute: func(ctx context.Context, tester *tester) (interface{}, error) {
+ input := &resultstore.TestAction{
+ ID: &resultstore.TestActionID{
+ ID: "test",
+ InvocationID: "invocation_id",
+ TargetID: "target_id",
+ ConfigID: "configuration_id",
+ },
+ TestSuite: "test_suite",
+ TestLogURI: "http://test.log",
+ StartTime: may18_1993,
+ Status: resultstore.Passed,
+ }
+
+ response := &api.Action{
+ Name: "resultstore_action_name",
+ Id: &api.Action_Id{
+ InvocationId: "invocation_id",
+ ConfigurationId: "configuration_id",
+ TargetId: "target_id",
+ },
+ }
+
+ tester.mock.EXPECT().
+ CreateAction(ctx, &api.CreateActionRequest{
+ RequestId: testUUID,
+ AuthorizationToken: testAuthToken,
+ Parent: "configured_target_name",
+ ActionId: "test",
+ Action: input.ToResultStoreAction(),
+ }).
+ Return(response, nil)
+
+ return tester.client.CreateTestAction(ctx, input, "configured_target_name")
+
+ },
+ },
+ {
+ method: "FinishConfiguredTarget",
+ description: "should make an RPC to finish a ConfiguredTarget",
+ execute: func(ctx context.Context, tester *tester) (interface{}, error) {
+ tester.mock.EXPECT().
+ FinishConfiguredTarget(ctx, &api.FinishConfiguredTargetRequest{
+ AuthorizationToken: testAuthToken,
+ Name: "configured_target_name",
+ }).
+ Return(&api.FinishConfiguredTargetResponse{}, nil)
+
+ return nil, tester.client.FinishConfiguredTarget(ctx, "configured_target_name")
+ },
+ },
+ {
+ method: "FinishInvocation",
+ description: "should make an RPC to finish an Invocation",
+ execute: func(ctx context.Context, tester *tester) (interface{}, error) {
+ tester.mock.EXPECT().
+ FinishInvocation(ctx, &api.FinishInvocationRequest{
+ AuthorizationToken: testAuthToken,
+ Name: "invocation_name",
+ }).
+ Return(&api.FinishInvocationResponse{}, nil)
+
+ return nil, tester.client.FinishInvocation(ctx, "invocation_name")
+ },
+ },
+ {
+ method: "FinishTarget",
+ description: "should make an RPC to finish a Target",
+ execute: func(ctx context.Context, tester *tester) (interface{}, error) {
+ tester.mock.EXPECT().
+ FinishTarget(ctx, &api.FinishTargetRequest{
+ AuthorizationToken: testAuthToken,
+ Name: "target_name",
+ }).
+ Return(&api.FinishTargetResponse{}, nil)
+
+ return nil, tester.client.FinishTarget(ctx, "target_name")
+ },
+ },
+ {
+ method: "UpdateConfiguredTarget",
+ description: "should make an RPC to update a ConfiguredTarget",
+ output: &resultstore.ConfiguredTarget{
+ Name: "resultstore_configured_target_name",
+ ID: &resultstore.ConfiguredTargetID{
+ InvocationID: "invocation_id",
+ ConfigID: "configuration_id",
+ TargetID: "target_id",
+ },
+ },
+ execute: func(ctx context.Context, tester *tester) (interface{}, error) {
+ input := &resultstore.ConfiguredTarget{
+ ID: &resultstore.ConfiguredTargetID{
+ InvocationID: "invocation_id",
+ TargetID: "target_id",
+ ConfigID: "configuration_id",
+ },
+ Properties: map[string]string{"key": "value"},
+ Status: resultstore.Passed,
+ StartTime: may18_1993,
+ Duration: time.Hour,
+ }
+
+ response := &api.ConfiguredTarget{
+ Name: "resultstore_configured_target_name",
+ Id: &api.ConfiguredTarget_Id{
+ InvocationId: "invocation_id",
+ ConfigurationId: "configuration_id",
+ TargetId: "target_id",
+ },
+ }
+
+ fieldsToUpdate := []string{"timing.duration", "status_attributes"}
+
+ tester.mock.EXPECT().
+ UpdateConfiguredTarget(ctx, &api.UpdateConfiguredTargetRequest{
+ AuthorizationToken: testAuthToken,
+ ConfiguredTarget: input.ToResultStoreConfiguredTarget(),
+ UpdateMask: &field_mask.FieldMask{Paths: fieldsToUpdate},
+ }).
+ Return(response, nil)
+
+ return tester.client.UpdateConfiguredTarget(ctx, input, fieldsToUpdate)
+ },
+ },
+ {
+ method: "UpdateInvocation",
+ description: "should make an RPC to update an Invocation",
+ output: &resultstore.Invocation{
+ Name: "resultstore_invocation_name",
+ ID: "invocation_id",
+ },
+ execute: func(ctx context.Context, tester *tester) (interface{}, error) {
+ input := &resultstore.Invocation{
+ ID: "invocation_id",
+ Properties: map[string]string{"key": "value"},
+ ProjectID: "project_id",
+ StartTime: may18_1993,
+ Duration: time.Hour,
+ Users: []string{"users"},
+ Labels: []string{"label"},
+ LogURL: "url",
+ Status: resultstore.Passed,
+ }
+
+ response := &api.Invocation{
+ Name: "resultstore_invocation_name",
+ Id: &api.Invocation_Id{
+ InvocationId: "invocation_id",
+ },
+ }
+
+ fieldsToUpdate := []string{"timing.duration", "status_attributes"}
+
+ tester.mock.EXPECT().
+ UpdateInvocation(ctx, &api.UpdateInvocationRequest{
+ AuthorizationToken: testAuthToken,
+ Invocation: input.ToResultStoreInvocation(),
+ UpdateMask: &field_mask.FieldMask{Paths: fieldsToUpdate},
+ }).
+ Return(response, nil)
+
+ return tester.client.UpdateInvocation(ctx, input, fieldsToUpdate)
+ },
+ },
+ {
+ method: "UpdateTarget",
+ description: "should make an RPC to update a Target",
+ output: &resultstore.Target{
+ Name: "resultstore_target_name",
+ ID: &resultstore.TargetID{
+ ID: "target_id",
+ InvocationID: "invocation_id",
+ },
+ },
+ execute: func(ctx context.Context, tester *tester) (interface{}, error) {
+ input := &resultstore.Target{
+ ID: &resultstore.TargetID{
+ ID: "target_id",
+ InvocationID: "invocation_id",
+ },
+ Properties: map[string]string{"key": "value"},
+ StartTime: may18_1993,
+ Duration: time.Hour,
+ Status: resultstore.Passed,
+ }
+
+ response := &api.Target{
+ Name: "resultstore_target_name",
+ Id: &api.Target_Id{
+ TargetId: "target_id",
+ InvocationId: "invocation_id",
+ },
+ }
+
+ fieldsToUpdate := []string{"timing.duration", "status_attributes"}
+
+ tester.mock.EXPECT().
+ UpdateTarget(ctx, &api.UpdateTargetRequest{
+ AuthorizationToken: testAuthToken,
+ Target: input.ToResultStoreTarget(),
+ UpdateMask: &field_mask.FieldMask{Paths: fieldsToUpdate},
+ }).
+ Return(response, nil)
+
+ return tester.client.UpdateTarget(ctx, input, fieldsToUpdate)
+ },
+ },
+ {
+ method: "UpdateTestAction",
+ description: "should make an RPC to update a Test Action",
+ output: &resultstore.TestAction{
+ Name: "resultstore_action_name",
+ ID: &resultstore.TestActionID{
+ ID: "action_id",
+ InvocationID: "invocation_id",
+ ConfigID: "configuration_id",
+ TargetID: "target_id",
+ },
+ },
+ execute: func(ctx context.Context, tester *tester) (interface{}, error) {
+ input := &resultstore.TestAction{
+ ID: &resultstore.TestActionID{
+ ID: "test",
+ InvocationID: "invocation_id",
+ TargetID: "target_id",
+ ConfigID: "configuration_id",
+ },
+ TestSuite: "test_suite",
+ TestLogURI: "http://test.log",
+ StartTime: may18_1993,
+ Duration: time.Hour,
+ Status: resultstore.Passed,
+ }
+
+ response := &api.Action{
+ Name: "resultstore_action_name",
+ Id: &api.Action_Id{
+ ActionId: "action_id",
+ InvocationId: "invocation_id",
+ ConfigurationId: "configuration_id",
+ TargetId: "target_id",
+ },
+ }
+
+ fieldsToUpdate := []string{"timing.duration", "status_attributes"}
+
+ tester.mock.EXPECT().
+ UpdateAction(ctx, &api.UpdateActionRequest{
+ AuthorizationToken: testAuthToken,
+ Action: input.ToResultStoreAction(),
+ UpdateMask: &field_mask.FieldMask{Paths: fieldsToUpdate},
+ }).
+ Return(response, nil)
+
+ return tester.client.UpdateTestAction(ctx, input, fieldsToUpdate)
+ },
+ },
}
- ctx, err = resultstore.SetAuthToken(ctx, authToken)
- if err != nil {
- t.Fatal(err)
+ setup := func(t *testing.T) (context.Context, resultstore.UploadClient, *mocks.MockResultStoreUploadClient, *gomock.Controller) {
+ ctx, err := resultstore.SetTestUUID(context.Background(), testUUID)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ ctx, err = resultstore.SetAuthToken(ctx, testAuthToken)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ controller := gomock.NewController(t)
+ mock := mocks.NewMockResultStoreUploadClient(controller)
+ client := resultstore.NewUploadClient(mock)
+ return ctx, client, mock, controller
}
- return resultstore.NewUploadClient(bed.MockRPCClient), ctx
-}
+ for _, tt := range tests {
+ ctx, client, mock, controller := setup(t)
+ defer controller.Finish()
-// Teardown is used to clean up after every test-case.
-func (bed *uploadClientTestBed) Teardown() {
- bed.ctrl.Finish()
-}
+ t.Run(tt.method, func(t *testing.T) {
+ t.Run(tt.description, func(t *testing.T) {
+ actual, err := tt.execute(ctx, &tester{client: client, mock: mock})
+ if err != nil {
+ t.Error(err.Error())
+ return
+ }
-// ExpectRPC is used to expect that a specific RPC message is recieved by the test bed.
-// If an invalid message or no message is received, the test will fail.
-func (bed *uploadClientTestBed) ExpectRPC() *mocks.MockResultStoreUploadClientMockRecorder {
- return bed.MockRPCClient.EXPECT()
-}
-
-func expectEqual(t *testing.T, expected interface{}, actual interface{}) {
- if !reflect.DeepEqual(expected, actual) {
- t.Errorf("Objects do not match:\n")
- t.Errorf("Expected: %+v\n", expected)
- t.Errorf("Actual: %+v\n", actual)
+ expected := tt.output
+ if !reflect.DeepEqual(expected, actual) {
+ t.Errorf("objects do not match:\n")
+ t.Errorf("Expected: %+v\n", expected)
+ t.Errorf("Actual: %+v\n", actual)
+ }
+ })
+ })
}
}
-
-func TestUploadClient_CreateInvocation(t *testing.T) {
- t.Run("should return an Invocation from an RPC response", func(t *testing.T) {
- testBed := new(uploadClientTestBed)
- client, ctx := testBed.Setup(t, "auth_token")
- defer testBed.Teardown()
-
- input := &resultstore.Invocation{
- ProjectID: "123456789",
- ID: "invocation_id",
- Users: []string{"user"},
- Labels: []string{"label"},
- Properties: map[string]string{"key": "value"},
- LogURL: "http://test.log",
- StartTime: may18_1993,
- Status: resultstore.Passed,
- }
-
- apiResponse := &api.Invocation{
- Name: "resultstore_invocation_name",
- Id: &api.Invocation_Id{
- InvocationId: "invocation_id",
- },
- }
-
- expectedOutput := &resultstore.Invocation{
- Name: "resultstore_invocation_name",
- ID: "invocation_id",
- }
-
- testBed.ExpectRPC().
- CreateInvocation(ctx, &api.CreateInvocationRequest{
- RequestId: testUUID,
- AuthorizationToken: "auth_token",
- InvocationId: "invocation_id",
- Invocation: input.ToResultStoreInvocation(),
- }).
- Return(apiResponse, nil)
-
- output, err := client.CreateInvocation(ctx, input)
- if err != nil {
- t.Fatal(err)
- }
-
- expectEqual(t, expectedOutput, output)
- })
-}
-
-func TestUploadClient_UpdateInvocation(t *testing.T) {
- t.Run("should return an Invocation from an RPC response", func(t *testing.T) {
- testBed := new(uploadClientTestBed)
- client, ctx := testBed.Setup(t, "auth_token")
- defer testBed.Teardown()
-
- input := &resultstore.Invocation{
- ID: "invocation_id",
- Properties: map[string]string{"key": "value"},
- ProjectID: "project_id",
- StartTime: may18_1993,
- Duration: time.Hour,
- Users: []string{"users"},
- Labels: []string{"label"},
- LogURL: "url",
- Status: resultstore.Passed,
- }
-
- fieldsToUpdate := []string{"timing.duration", "status_attributes"}
-
- apiResponse := &api.Invocation{
- Name: "resultstore_invocation_name",
- Id: &api.Invocation_Id{
- InvocationId: "invocation_id",
- },
- }
-
- expectedOutput := &resultstore.Invocation{
- Name: "resultstore_invocation_name",
- ID: "invocation_id",
- }
-
- testBed.ExpectRPC().
- UpdateInvocation(ctx, &api.UpdateInvocationRequest{
- AuthorizationToken: "auth_token",
- Invocation: input.ToResultStoreInvocation(),
- UpdateMask: &field_mask.FieldMask{Paths: fieldsToUpdate},
- }).
- Return(apiResponse, nil)
-
- output, err := client.UpdateInvocation(ctx, input, fieldsToUpdate)
- if err != nil {
- t.Fatal(err)
- }
- expectEqual(t, expectedOutput, output)
- })
-}
-
-func TestUploadClient_FinishInvocation(t *testing.T) {
- t.Run("should return an Invocation from an RPC response", func(t *testing.T) {
- testBed := new(uploadClientTestBed)
- client, ctx := testBed.Setup(t, "auth_token")
- defer testBed.Teardown()
-
- testBed.ExpectRPC().
- FinishInvocation(ctx, &api.FinishInvocationRequest{
- AuthorizationToken: "auth_token",
- Name: "invocation_name",
- }).
- Return(&api.FinishInvocationResponse{}, nil)
-
- if err := client.FinishInvocation(ctx, "invocation_name"); err != nil {
- t.Fatal(err)
- }
- })
-}
-
-func TestUploadClient_CreateConfiguration(t *testing.T) {
- t.Run("should return a Configuration from an RPC response", func(t *testing.T) {
- testBed := new(uploadClientTestBed)
- client, ctx := testBed.Setup(t, "auth_token")
- defer testBed.Teardown()
-
- input := &resultstore.Configuration{
- ID: "configuration_id",
- InvocationID: "invocation_id",
- Properties: map[string]string{"key": "value"},
- }
-
- apiResponse := &api.Configuration{
- Name: "resultstore_configuration_name",
- Id: &api.Configuration_Id{
- ConfigurationId: "configuration_id",
- InvocationId: "invocation_id",
- },
- }
-
- expectedOutput := &resultstore.Configuration{
- Name: "resultstore_configuration_name",
- ID: "configuration_id",
- InvocationID: "invocation_id",
- }
-
- testBed.ExpectRPC().
- CreateConfiguration(ctx, &api.CreateConfigurationRequest{
- RequestId: testUUID,
- AuthorizationToken: "auth_token",
- Parent: "invocation_name",
- ConfigId: "configuration_id",
- Configuration: input.ToResultStoreConfiguration(),
- }).
- Return(apiResponse, nil)
-
- output, err := client.CreateConfiguration(ctx, input, "invocation_name")
- if err != nil {
- t.Fatal(err)
- }
-
- expectEqual(t, expectedOutput, output)
- })
-}
-
-func TestUploadClient_CreateTarget(t *testing.T) {
- t.Run("should return a Target from an RPC response", func(t *testing.T) {
- testBed := new(uploadClientTestBed)
- client, ctx := testBed.Setup(t, "auth_token")
- defer testBed.Teardown()
-
- input := &resultstore.Target{
- ID: &resultstore.TargetID{
- ID: "target_id",
- },
- Properties: map[string]string{"key": "value"},
- StartTime: may18_1993,
- Status: resultstore.Passed,
- }
-
- apiResponse := &api.Target{
- Name: "resultstore_target_name",
- Id: &api.Target_Id{
- TargetId: "target_id",
- InvocationId: "invocation_id",
- },
- }
-
- expectedOutput := &resultstore.Target{
- Name: "resultstore_target_name",
- ID: &resultstore.TargetID{
- ID: "target_id",
- InvocationID: "invocation_id",
- },
- }
-
- testBed.ExpectRPC().
- CreateTarget(ctx, &api.CreateTargetRequest{
- RequestId: testUUID,
- AuthorizationToken: "auth_token",
- Parent: "invocation_name",
- TargetId: input.ID.ID,
- Target: input.ToResultStoreTarget(),
- }).
- Return(apiResponse, nil)
-
- output, err := client.CreateTarget(ctx, input, "invocation_name")
- if err != nil {
- t.Fatal(err)
- }
-
- expectEqual(t, expectedOutput, output)
- })
-}
-
-func TestUploadClient_UpdateTarget(t *testing.T) {
- t.Run("should return a Target from an RPC response", func(t *testing.T) {
- testBed := new(uploadClientTestBed)
- client, ctx := testBed.Setup(t, "auth_token")
- defer testBed.Teardown()
-
- input := &resultstore.Target{
- ID: &resultstore.TargetID{
- ID: "target_id",
- InvocationID: "invocation_id",
- },
- Properties: map[string]string{"key": "value"},
- StartTime: may18_1993,
- Duration: time.Hour,
- Status: resultstore.Passed,
- }
-
- fieldsToUpdate := []string{"timing.duration", "status_attributes"}
-
- apiResponse := &api.Target{
- Name: "resultstore_target_name",
- Id: &api.Target_Id{
- TargetId: "target_id",
- InvocationId: "invocation_id",
- },
- }
-
- expectedOutput := &resultstore.Target{
- Name: "resultstore_target_name",
- ID: &resultstore.TargetID{
- ID: "target_id",
- InvocationID: "invocation_id",
- },
- }
-
- testBed.ExpectRPC().
- UpdateTarget(ctx, &api.UpdateTargetRequest{
- AuthorizationToken: "auth_token",
- Target: input.ToResultStoreTarget(),
- UpdateMask: &field_mask.FieldMask{Paths: fieldsToUpdate},
- }).
- Return(apiResponse, nil)
-
- output, err := client.UpdateTarget(ctx, input, fieldsToUpdate)
- if err != nil {
- t.Fatal(err)
- }
-
- expectEqual(t, expectedOutput, output)
- })
-}
-
-func TestUploadClient_FinishTarget(t *testing.T) {
- t.Run("should return a Target from an RPC response", func(t *testing.T) {
- testBed := new(uploadClientTestBed)
- client, ctx := testBed.Setup(t, "auth_token")
- defer testBed.Teardown()
-
- testBed.ExpectRPC().
- FinishTarget(ctx, &api.FinishTargetRequest{
- AuthorizationToken: "auth_token",
- Name: "target_name",
- }).
- Return(&api.FinishTargetResponse{}, nil)
-
- if err := client.FinishTarget(ctx, "target_name"); err != nil {
- t.Fatal(err)
- }
- })
-}
-
-func TestUploadClient_CreateConfiguredTarget(t *testing.T) {
- t.Run("should return a ConfiguredTarget from an RPC response", func(t *testing.T) {
- testBed := new(uploadClientTestBed)
- client, ctx := testBed.Setup(t, "auth_token")
- defer testBed.Teardown()
-
- input := &resultstore.ConfiguredTarget{
- ID: &resultstore.ConfiguredTargetID{
- InvocationID: "invocation_id",
- TargetID: "target_id",
- ConfigID: "configuration_id",
- },
- Properties: map[string]string{"key": "value"},
- StartTime: may18_1993,
- Status: resultstore.Passed,
- }
-
- apiResponse := &api.ConfiguredTarget{
- Name: "resultstore_configured_target_name",
- Id: &api.ConfiguredTarget_Id{
- InvocationId: "invocation_id",
- ConfigurationId: "configuration_id",
- TargetId: "target_id",
- },
- }
-
- expectedOutput := &resultstore.ConfiguredTarget{
- Name: "resultstore_configured_target_name",
- ID: &resultstore.ConfiguredTargetID{
- InvocationID: "invocation_id",
- ConfigID: "configuration_id",
- TargetID: "target_id",
- },
- }
-
- testBed.ExpectRPC().
- CreateConfiguredTarget(ctx, &api.CreateConfiguredTargetRequest{
- RequestId: testUUID,
- AuthorizationToken: "auth_token",
- Parent: "target_name",
- ConfigId: input.ID.ConfigID,
- ConfiguredTarget: input.ToResultStoreConfiguredTarget(),
- }).
- Return(apiResponse, nil)
-
- output, err := client.CreateConfiguredTarget(ctx, input, "target_name")
- if err != nil {
- t.Fatal(err)
- }
-
- expectEqual(t, expectedOutput, output)
- })
-}
-
-func TestUploadClient_UpdateConfiguredTarget(t *testing.T) {
- t.Run("should return a ConfiguredTarget from an RPC response", func(t *testing.T) {
- testBed := new(uploadClientTestBed)
- client, ctx := testBed.Setup(t, "auth_token")
- defer testBed.Teardown()
-
- input := &resultstore.ConfiguredTarget{
- ID: &resultstore.ConfiguredTargetID{
- InvocationID: "invocation_id",
- TargetID: "target_id",
- ConfigID: "configuration_id",
- },
- Properties: map[string]string{"key": "value"},
- Status: resultstore.Passed,
- StartTime: may18_1993,
- Duration: time.Hour,
- }
-
- fieldsToUpdate := []string{"timing.duration", "status_attributes"}
-
- apiResponse := &api.ConfiguredTarget{
- Name: "resultstore_configured_target_name",
- Id: &api.ConfiguredTarget_Id{
- InvocationId: "invocation_id",
- ConfigurationId: "configuration_id",
- TargetId: "target_id",
- },
- }
-
- expectedOutput := &resultstore.ConfiguredTarget{
- Name: "resultstore_configured_target_name",
- ID: &resultstore.ConfiguredTargetID{
- InvocationID: "invocation_id",
- ConfigID: "configuration_id",
- TargetID: "target_id",
- },
- }
-
- testBed.ExpectRPC().
- UpdateConfiguredTarget(ctx, &api.UpdateConfiguredTargetRequest{
- AuthorizationToken: "auth_token",
- ConfiguredTarget: input.ToResultStoreConfiguredTarget(),
- UpdateMask: &field_mask.FieldMask{Paths: fieldsToUpdate},
- }).
- Return(apiResponse, nil)
-
- output, err := client.UpdateConfiguredTarget(ctx, input, fieldsToUpdate)
- if err != nil {
- t.Fatal(err)
- }
-
- expectEqual(t, expectedOutput, output)
- })
-}
-
-func TestUploadClient_FinishConfiguredTarget(t *testing.T) {
- t.Run("should return a ConfiguredTarget from an RPC response", func(t *testing.T) {
- testBed := new(uploadClientTestBed)
- client, ctx := testBed.Setup(t, "auth_token")
- defer testBed.Teardown()
-
- testBed.ExpectRPC().
- FinishConfiguredTarget(ctx, &api.FinishConfiguredTargetRequest{
- AuthorizationToken: "auth_token",
- Name: "configured_target_name",
- }).
- Return(&api.FinishConfiguredTargetResponse{}, nil)
-
- if err := client.FinishConfiguredTarget(ctx, "configured_target_name"); err != nil {
- t.Fatal(err)
- }
- })
-}
-
-func TestUploadClient_CreateTestAction(t *testing.T) {
- t.Run("should return an Action from an RPC response", func(t *testing.T) {
- testBed := new(uploadClientTestBed)
- client, ctx := testBed.Setup(t, "auth_token")
- defer testBed.Teardown()
-
- input := &resultstore.TestAction{
- ID: &resultstore.TestActionID{
- ID: "test",
- InvocationID: "invocation_id",
- TargetID: "target_id",
- ConfigID: "configuration_id",
- },
- TestSuite: "test_suite",
- TestLogURI: "http://test.log",
- StartTime: may18_1993,
- Status: resultstore.Passed,
- }
-
- apiResponse := &api.Action{
- Name: "resultstore_action_name",
- Id: &api.Action_Id{
- InvocationId: "invocation_id",
- ConfigurationId: "configuration_id",
- TargetId: "target_id",
- },
- }
-
- expectedOutput := &resultstore.TestAction{
- Name: "resultstore_action_name",
- ID: &resultstore.TestActionID{
- InvocationID: "invocation_id",
- ConfigID: "configuration_id",
- TargetID: "target_id",
- },
- }
-
- testBed.ExpectRPC().
- CreateAction(ctx, &api.CreateActionRequest{
- RequestId: testUUID,
- AuthorizationToken: "auth_token",
- Parent: "configured_target_name",
- ActionId: "test",
- Action: input.ToResultStoreAction(),
- }).
- Return(apiResponse, nil)
-
- output, err := client.CreateTestAction(ctx, input, "configured_target_name")
- if err != nil {
- t.Fatal(err)
- }
-
- expectEqual(t, expectedOutput, output)
- })
-}
-
-func TestUploadClient_UpdateTestAction(t *testing.T) {
- t.Run("should return an Action from an RPC response", func(t *testing.T) {
- testBed := new(uploadClientTestBed)
- client, ctx := testBed.Setup(t, "auth_token")
- defer testBed.Teardown()
-
- input := &resultstore.TestAction{
- ID: &resultstore.TestActionID{
- ID: "test",
- InvocationID: "invocation_id",
- TargetID: "target_id",
- ConfigID: "configuration_id",
- },
- TestSuite: "test_suite",
- TestLogURI: "http://test.log",
- StartTime: may18_1993,
- Duration: time.Hour,
- Status: resultstore.Passed,
- }
-
- fieldsToUpdate := []string{"timing.duration", "status_attributes"}
-
- apiResponse := &api.Action{
- Name: "resultstore_action_name",
- Id: &api.Action_Id{
- ActionId: "action_id",
- InvocationId: "invocation_id",
- ConfigurationId: "configuration_id",
- TargetId: "target_id",
- },
- }
-
- expectedOutput := &resultstore.TestAction{
- Name: "resultstore_action_name",
- ID: &resultstore.TestActionID{
- ID: "action_id",
- InvocationID: "invocation_id",
- ConfigID: "configuration_id",
- TargetID: "target_id",
- },
- }
-
- testBed.ExpectRPC().
- UpdateAction(ctx, &api.UpdateActionRequest{
- AuthorizationToken: "auth_token",
- Action: input.ToResultStoreAction(),
- UpdateMask: &field_mask.FieldMask{Paths: fieldsToUpdate},
- }).
- Return(apiResponse, nil)
-
- output, err := client.UpdateTestAction(ctx, input, fieldsToUpdate)
- if err != nil {
- t.Fatal(err)
- }
-
- expectEqual(t, expectedOutput, output)
- })
-}