Skip to content

Commit 9785c01

Browse files
freeznetCopilot
andauthored
fix(utils): add JSON tag for UpdateAuthData in UpdateOptions (#1450)
* feat(utils): add JSON tag for UpdateAuthData in UpdateOptions * add tests * Update pulsaradmin/pkg/utils/update_options.go Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent faed695 commit 9785c01

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

pulsaradmin/pkg/utils/update_options.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
package utils
1919

20-
// Options while updating the sink
20+
// Options while updating functions, sources, and sinks
2121
type UpdateOptions struct {
22-
UpdateAuthData bool
22+
UpdateAuthData bool `json:"updateAuthData"`
2323
}
2424

2525
func NewUpdateOptions() *UpdateOptions {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package utils
19+
20+
import (
21+
"encoding/json"
22+
"testing"
23+
24+
"github.com/stretchr/testify/assert"
25+
"github.com/stretchr/testify/require"
26+
)
27+
28+
func TestUpdateOptionsMarshalJSON(t *testing.T) {
29+
opts := UpdateOptions{UpdateAuthData: true}
30+
31+
data, err := json.Marshal(opts)
32+
require.NoError(t, err)
33+
34+
assert.JSONEq(t, `{"updateAuthData":true}`, string(data))
35+
}
36+
37+
func TestUpdateOptionsUnmarshalJSON(t *testing.T) {
38+
payload := `{"updateAuthData":true}`
39+
40+
var opts UpdateOptions
41+
err := json.Unmarshal([]byte(payload), &opts)
42+
require.NoError(t, err)
43+
44+
assert.True(t, opts.UpdateAuthData)
45+
}

0 commit comments

Comments
 (0)