Skip to content

Commit 599a530

Browse files
fix merge and tests
2 parents e495f3a + 612af95 commit 599a530

File tree

7 files changed

+40
-39
lines changed

7 files changed

+40
-39
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ cmd/transform/test_data/test_create.json
2121
cmd/transform/test_data/test_update.json
2222
example_transforms
2323
config.json
24+
gotest.log

cmd/api/test_data/test_create.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"attributes":{"accountFilter":"!(nativeIdentity.startsWith(\"*DELETED*\"))","accountPropertyFilter":"(groups.containsAll({'Admin'}) || location == 'Austin')","accountReturnFirstLink":false,"accountSortAttribute":"created","accountSortDescending":false,"attributeName":"DEPARTMENT","input":{"attributes":{"attributeName":"first_name","sourceName":"Source"},"type":"accountAttribute"},"requiresPeriodicRefresh":false,"sourceName":"Workday"},"name":"uSBRsleKLwWMsnMh","type":"dateFormat"}
1+
{"attributes":{"accountFilter":"!(nativeIdentity.startsWith(\"*DELETED*\"))","accountPropertyFilter":"(groups.containsAll({'Admin'}) || location == 'Austin')","accountReturnFirstLink":false,"accountSortAttribute":"created","accountSortDescending":false,"attributeName":"DEPARTMENT","input":{"attributes":{"attributeName":"first_name","sourceName":"Source"},"type":"accountAttribute"},"requiresPeriodicRefresh":false,"sourceName":"Workday"},"name":"xQTfLofnWtrDsrbX","type":"dateFormat"}

cmd/api/test_data/test_update.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"attributes":{"accountFilter":"!(nativeIdentity.startsWith(\"*DELETED*\"))","accountPropertyFilter":"(groups.containsAll({'Admin'}) || location == 'Austin')","accountReturnFirstLink":false,"accountSortAttribute":"created","accountSortDescending":false,"attributeName":"UPDATED_DEPARTMENT","input":{"attributes":{"attributeName":"first_name","sourceName":"Source"},"type":"accountAttribute"},"requiresPeriodicRefresh":false,"sourceName":"Workday"},"name":"uSBRsleKLwWMsnMh","type":"dateFormat"}
1+
{"attributes":{"accountFilter":"!(nativeIdentity.startsWith(\"*DELETED*\"))","accountPropertyFilter":"(groups.containsAll({'Admin'}) || location == 'Austin')","accountReturnFirstLink":false,"accountSortAttribute":"created","accountSortDescending":false,"attributeName":"UPDATED_DEPARTMENT","input":{"attributes":{"attributeName":"first_name","sourceName":"Source"},"type":"accountAttribute"},"requiresPeriodicRefresh":false,"sourceName":"Workday"},"name":"xQTfLofnWtrDsrbX","type":"dateFormat"}

cmd/connector/customizer_link.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func newCustomizerLinkCmd(client client.Client) *cobra.Command {
3333
return err
3434
}
3535

36-
resp, err := client.Patch(cmd.Context(), util.ResourceUrl(connectorInstancesEndpoint, instanceID, "link"), bytes.NewReader(raw), nil)
36+
resp, err := client.Patch(cmd.Context(), util.ResourceUrl(connectorInstancesEndpoint, instanceID), bytes.NewReader(raw), nil)
3737
if err != nil {
3838
return err
3939
}

cmd/connector/customizer_link_test.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// cmd/connector/link_test.go
1+
// cmd/connector/customizer_link_test.go
22
package connector
33

44
import (
@@ -17,30 +17,31 @@ import (
1717
func TestNewCustomizerLinkCmd_missingFlags(t *testing.T) {
1818
ctrl := gomock.NewController(t)
1919
defer ctrl.Finish()
20-
2120
mockClient := mocks.NewMockClient(ctrl)
21+
2222
// Patch should never be called if flags missing
2323
mockClient.EXPECT().
2424
Patch(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
2525
Times(0)
2626

2727
cmd := newCustomizerLinkCmd(mockClient)
28-
cmd.SetArgs([]string{})
28+
cmd.SetArgs([]string{}) // no -c or -i
2929
if err := cmd.Execute(); err == nil {
30-
t.Error("expected error when -c and/or -i missing")
30+
t.Error("expected error when flags are missing")
3131
}
3232
}
3333

3434
func TestNewCustomizerLinkCmd_httpError(t *testing.T) {
3535
ctrl := gomock.NewController(t)
3636
defer ctrl.Finish()
37-
3837
mockClient := mocks.NewMockClient(ctrl)
38+
39+
// stub 400 response, expecting URL without "/link"
3940
mockClient.
4041
EXPECT().
4142
Patch(
4243
gomock.Any(),
43-
gomock.Eq(util.ResourceUrl(connectorInstancesEndpoint, "inst-1", "link")),
44+
gomock.Eq(util.ResourceUrl(connectorInstancesEndpoint, "inst-1")),
4445
gomock.Any(),
4546
gomock.Nil(),
4647
).
@@ -55,22 +56,22 @@ func TestNewCustomizerLinkCmd_httpError(t *testing.T) {
5556
cmd.SetErr(&bytes.Buffer{})
5657
cmd.SetArgs([]string{"-c", "cust-1", "-i", "inst-1"})
5758

58-
err := cmd.Execute()
59-
if err == nil || !strings.Contains(err.Error(), "link customizer failed") {
60-
t.Fatalf("expected HTTP error, got %v", err)
59+
if err := cmd.Execute(); err == nil || !strings.Contains(err.Error(), "link customizer failed") {
60+
t.Fatalf("expected HTTP-error, got %v", err)
6161
}
6262
}
6363

6464
func TestNewCustomizerLinkCmd_jsonError(t *testing.T) {
6565
ctrl := gomock.NewController(t)
6666
defer ctrl.Finish()
67-
6867
mockClient := mocks.NewMockClient(ctrl)
68+
69+
// stub 200 but invalid JSON
6970
mockClient.
7071
EXPECT().
7172
Patch(
7273
gomock.Any(),
73-
gomock.Eq(util.ResourceUrl(connectorInstancesEndpoint, "inst-2", "link")),
74+
gomock.Eq(util.ResourceUrl(connectorInstancesEndpoint, "inst-2")),
7475
gomock.Any(),
7576
gomock.Nil(),
7677
).
@@ -85,26 +86,26 @@ func TestNewCustomizerLinkCmd_jsonError(t *testing.T) {
8586
cmd.SetErr(&bytes.Buffer{})
8687
cmd.SetArgs([]string{"-c", "cust-1", "-i", "inst-2"})
8788

88-
err := cmd.Execute()
89-
if err == nil || !strings.Contains(err.Error(), "invalid character") {
89+
if err := cmd.Execute(); err == nil || !strings.Contains(err.Error(), "invalid character") {
9090
t.Fatalf("expected JSON decode error, got %v", err)
9191
}
9292
}
9393

9494
func TestNewCustomizerLinkCmd_success(t *testing.T) {
9595
ctrl := gomock.NewController(t)
9696
defer ctrl.Finish()
97+
mockClient := mocks.NewMockClient(ctrl)
9798

98-
// simulate a successful response with a valid instance
99+
// prepare a fake instance
99100
inst := instance{ID: "inst-3", Name: "LinkedInst"}
100101
raw, _ := json.Marshal(inst)
101102

102-
mockClient := mocks.NewMockClient(ctrl)
103+
// expecting URL without "/link"
103104
mockClient.
104105
EXPECT().
105106
Patch(
106107
gomock.Any(),
107-
gomock.Eq(util.ResourceUrl(connectorInstancesEndpoint, "inst-3", "link")),
108+
gomock.Eq(util.ResourceUrl(connectorInstancesEndpoint, "inst-3")),
108109
gomock.Any(),
109110
gomock.Nil(),
110111
).

cmd/connector/customizer_unlink.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func newCustomizerUnlinkCmd(client client.Client) *cobra.Command {
3131
return err
3232
}
3333

34-
resp, err := client.Patch(cmd.Context(), util.ResourceUrl(connectorInstancesEndpoint, instanceID, "unlink"), bytes.NewReader(raw), nil)
34+
resp, err := client.Patch(cmd.Context(), util.ResourceUrl(connectorInstancesEndpoint, instanceID), bytes.NewReader(raw), nil)
3535
if err != nil {
3636
return err
3737
}

cmd/connector/customizer_unlink_test.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import (
1717
func TestNewCustomizerUnlinkCmd_missingFlag(t *testing.T) {
1818
ctrl := gomock.NewController(t)
1919
defer ctrl.Finish()
20-
mockClient := mocks.NewMockClient(ctrl)
2120

22-
// Patch must not be called
21+
mockClient := mocks.NewMockClient(ctrl)
22+
// Patch should not be called when the required flag is missing
2323
mockClient.
2424
EXPECT().
2525
Patch(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
@@ -29,20 +29,20 @@ func TestNewCustomizerUnlinkCmd_missingFlag(t *testing.T) {
2929
cmd.SetArgs([]string{}) // no -i
3030

3131
if err := cmd.Execute(); err == nil {
32-
t.Error("expected error when required flag is missing")
32+
t.Error("expected error when -i is missing")
3333
}
3434
}
3535

3636
func TestNewCustomizerUnlinkCmd_httpError(t *testing.T) {
3737
ctrl := gomock.NewController(t)
3838
defer ctrl.Finish()
39-
mockClient := mocks.NewMockClient(ctrl)
4039

40+
mockClient := mocks.NewMockClient(ctrl)
4141
mockClient.
4242
EXPECT().
4343
Patch(
4444
gomock.Any(),
45-
gomock.Eq(util.ResourceUrl(connectorInstancesEndpoint, "inst-1", "unlink")),
45+
gomock.Eq(util.ResourceUrl(connectorInstancesEndpoint, "inst-1")),
4646
gomock.Any(),
4747
gomock.Nil(),
4848
).
@@ -59,20 +59,20 @@ func TestNewCustomizerUnlinkCmd_httpError(t *testing.T) {
5959

6060
err := cmd.Execute()
6161
if err == nil || !strings.Contains(err.Error(), "unlink customizer failed") {
62-
t.Fatalf("expected HTTP error, got %v", err)
62+
t.Fatalf("expected HTTPerror, got %v", err)
6363
}
6464
}
6565

6666
func TestNewCustomizerUnlinkCmd_jsonError(t *testing.T) {
6767
ctrl := gomock.NewController(t)
6868
defer ctrl.Finish()
69-
mockClient := mocks.NewMockClient(ctrl)
7069

70+
mockClient := mocks.NewMockClient(ctrl)
7171
mockClient.
7272
EXPECT().
7373
Patch(
7474
gomock.Any(),
75-
gomock.Eq(util.ResourceUrl(connectorInstancesEndpoint, "inst-2", "unlink")),
75+
gomock.Eq(util.ResourceUrl(connectorInstancesEndpoint, "inst-2")),
7676
gomock.Any(),
7777
gomock.Nil(),
7878
).
@@ -89,24 +89,24 @@ func TestNewCustomizerUnlinkCmd_jsonError(t *testing.T) {
8989

9090
err := cmd.Execute()
9191
if err == nil || !strings.Contains(err.Error(), "invalid character") {
92-
t.Fatalf("expected JSON decode error, got %v", err)
92+
t.Fatalf("expected JSONdecode error, got %v", err)
9393
}
9494
}
9595

9696
func TestNewCustomizerUnlinkCmd_success(t *testing.T) {
9797
ctrl := gomock.NewController(t)
9898
defer ctrl.Finish()
99-
mockClient := mocks.NewMockClient(ctrl)
10099

101100
// prepare a fake instance response
102-
inst := instance{ID: "inst-3", Name: "FooInst"}
101+
inst := instance{ID: "inst-3", Name: "UnlinkedInst"}
103102
raw, _ := json.Marshal(inst)
104103

104+
mockClient := mocks.NewMockClient(ctrl)
105105
mockClient.
106106
EXPECT().
107107
Patch(
108108
gomock.Any(),
109-
gomock.Eq(util.ResourceUrl(connectorInstancesEndpoint, "inst-3", "unlink")),
109+
gomock.Eq(util.ResourceUrl(connectorInstancesEndpoint, "inst-3")),
110110
gomock.Any(),
111111
gomock.Nil(),
112112
).
@@ -123,19 +123,18 @@ func TestNewCustomizerUnlinkCmd_success(t *testing.T) {
123123
cmd.SetArgs([]string{"-i", "inst-3"})
124124

125125
if err := cmd.Execute(); err != nil {
126-
t.Fatalf("unexpected Execute error: %v", err)
126+
t.Fatalf("unexpected error: %v", err)
127127
}
128128

129129
out := outBuf.String()
130-
// ID must appear
130+
// The table should contain the ID
131131
if !strings.Contains(out, inst.ID) {
132-
t.Errorf("output missing instance ID, got:\n%s", out)
132+
t.Errorf("output missing ID %q, got:\n%s", inst.ID, out)
133133
}
134-
// uppercase headers
134+
// And uppercase headers
135135
for _, col := range instanceColumns {
136-
uc := strings.ToUpper(col)
137-
if !strings.Contains(out, uc) {
138-
t.Errorf("output missing header %q, got:\n%s", uc, out)
136+
if !strings.Contains(out, strings.ToUpper(col)) {
137+
t.Errorf("output missing header %q, got:\n%s", strings.ToUpper(col), out)
139138
}
140139
}
141140
}

0 commit comments

Comments
 (0)