Skip to content

Commit 5ec1d8f

Browse files
committed
Code review feedback
1 parent b1f9683 commit 5ec1d8f

File tree

2 files changed

+37
-24
lines changed

2 files changed

+37
-24
lines changed

internal/cli/streams/privatelink/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (opts *CreateOpts) Run() error {
4848
}
4949

5050
// Remaining validation will be done by the API
51-
if privateLinkEndpoint.Provider == nil || len(*privateLinkEndpoint.Provider) == 0 {
51+
if len(privateLinkEndpoint.GetProvider()) == 0 {
5252
return errors.New("provider missing")
5353
}
5454

internal/cli/streams/privatelink/create_test.go

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,34 +39,47 @@ func TestCreateOpts_Run(t *testing.T) {
3939
}
4040
`
4141

42-
t.Run("should fail if no file is passed in", func(t *testing.T) {
43-
createOpts := &CreateOpts{
44-
fs: afero.NewMemMapFs(),
45-
}
42+
testCases := []struct {
43+
name string
44+
fileContents string
45+
wantErr require.ErrorAssertionFunc
46+
}{
47+
{
48+
name: "no file passed in",
49+
fileContents: "",
50+
wantErr: require.Error,
51+
},
52+
{
53+
name: "file does not contain a provider",
54+
fileContents: `
55+
{
56+
"region": "US_EAST_2",
57+
"serviceEndpointId": "/subscriptions/fd01adff-b37e-4693-8497-83ecf183a145/resourceGroups/test-rg/providers/Microsoft.EventHub/namespaces/test-namespace",
58+
"dnsDomain": "test-namespace.servicebus.windows.net"
59+
}
60+
`,
61+
wantErr: func(tt require.TestingT, err error, _ ...any) {
62+
require.ErrorContains(tt, err, "provider missing")
63+
},
64+
},
65+
}
4666

47-
err := createOpts.Run()
48-
assert.Error(t, err)
49-
})
67+
for _, tc := range testCases {
68+
t.Run(tc.name, func(t *testing.T) {
69+
fs := afero.NewMemMapFs()
5070

51-
t.Run("should fail if the file does not contain a provider", func(t *testing.T) {
52-
fs := afero.NewMemMapFs()
53-
fileContents := `
54-
{
55-
"region": "US_EAST_2",
56-
"serviceEndpointId": "/subscriptions/fd01adff-b37e-4693-8497-83ecf183a145/resourceGroups/test-rg/providers/Microsoft.EventHub/namespaces/test-namespace",
57-
"dnsDomain": "test-namespace.servicebus.windows.net"
71+
if len(tc.fileContents) > 0 {
72+
require.NoError(t, afero.WriteFile(fs, fileName, []byte(tc.fileContents), 0600))
5873
}
59-
`
60-
require.NoError(t, afero.WriteFile(fs, fileName, []byte(fileContents), 0600))
6174

62-
createOpts := &CreateOpts{
63-
fs: fs,
64-
filename: fileName,
65-
}
75+
createOpts := &CreateOpts{
76+
fs: fs,
77+
filename: fileName,
78+
}
6679

67-
err := createOpts.Run()
68-
assert.ErrorContains(t, err, "provider missing")
69-
})
80+
tc.wantErr(t, createOpts.Run())
81+
})
82+
}
7083

7184
t.Run("should call the store create privateLink method with the correct parameters", func(t *testing.T) {
7285
fs := afero.NewMemMapFs()

0 commit comments

Comments
 (0)