Skip to content

Commit 04b719d

Browse files
committed
o/h/ctlcmd: reduce comment verbosity, inline unit test setup code
1 parent afa324a commit 04b719d

2 files changed

Lines changed: 8 additions & 27 deletions

File tree

overlord/hookstate/ctlcmd/helpers.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,6 @@ const snapctlDebounceWindow = 200 * time.Millisecond
7272
const finalSeedTask = "mark-seeded"
7373

7474
// ChangeInfo represents the information about a change that is needed for JSON marshaling.
75-
// To unmarshal the data needed for `snap tasks`, we need access
76-
// to all struct fields that client.Change has. However, Change.data is an
77-
// unexported field, so we cannot unmarshal into it directly. There is a
78-
// changeAndData struct in the client package with all exported fields, but the
79-
// struct itself is not exported.
8075
type ChangeInfo struct {
8176
ID string `json:"id"`
8277
Kind string `json:"kind"`
@@ -93,9 +88,7 @@ type ChangeInfo struct {
9388
}
9489

9590
// TaskInfo represents the information about a task that is needed for JSON marshaling
96-
// for `snap tasks` output. It includes fields such as ID, kind, summary, status, and
97-
// any additional data associated with the task. The Data field is a map of string keys
98-
// to raw JSON messages, allowing for flexible inclusion of task-specific data in the output.
91+
// for `snap tasks` output.
9992
type TaskInfo struct {
10093
ID string `json:"id"`
10194
Kind string `json:"kind"`
@@ -111,8 +104,7 @@ type TaskInfo struct {
111104
}
112105

113106
// TaskInfoProgress represents the progress of a task, including a label and the
114-
// amount of work done out of the total. Used in the TaskInfo struct to provide
115-
// progress information for tasks in the `snap tasks` output.
107+
// amount of work done out of the total.
116108
type TaskInfoProgress struct {
117109
Label string `json:"label"`
118110
Done int `json:"done"`

overlord/hookstate/ctlcmd/helpers_test.go

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ type helperSuite struct {
3434

3535
var _ = Suite(&helperSuite{})
3636

37-
func setupChange() (*state.State, string, *state.Change) {
37+
// TestStateChangeToChangeInfo tests the StateChangeToChangeInfo function,
38+
// verifying that state changes are correctly converted to ChangeInfo structs
39+
// and that the data can be successfully marshaled and unmarshaled.
40+
func (s *helperSuite) TestStateChangeToChangeInfo(c *C) {
3841
st := state.New(nil)
3942
st.Lock()
4043
defer st.Unlock()
@@ -51,25 +54,12 @@ func setupChange() (*state.State, string, *state.Change) {
5154
"kind": "install-components",
5255
})
5356

54-
return st, chg.ID(), chg
55-
}
56-
57-
// TestStateChangeToChangeInfo tests the StateChangeToChangeInfo function,
58-
// verifying that state changes are correctly converted to ChangeInfo structs
59-
// and that the data can be successfully marshalled and unmarshalled.
60-
func (s *helperSuite) TestStateChangeToChangeInfo(c *C) {
61-
st, changeID, _ := setupChange()
62-
63-
st.Lock()
64-
chg := st.Change(changeID)
65-
c.Assert(chg, NotNil)
66-
6757
// Convert the state.Change to ChangeInfo
58+
c.Assert(chg, NotNil)
6859
changeInfo := ctlcmd.StateChangeToChangeInfo(chg)
69-
st.Unlock()
7060

7161
// Verify basic change information
72-
c.Check(changeInfo.ID, Equals, changeID)
62+
c.Check(changeInfo.ID, Equals, chg.ID())
7363
c.Check(changeInfo.Kind, Equals, "snapctl-install")
7464
c.Check(changeInfo.Summary, Equals, "install components for test-snap")
7565
c.Check(changeInfo.Status, Equals, "Done")
@@ -93,5 +83,4 @@ func (s *helperSuite) TestStateChangeToChangeInfo(c *C) {
9383
// Verify change-level data (api-data)
9484
c.Assert(changeInfo.Data, NotNil)
9585
c.Assert(changeInfo.Data["snap-names"], NotNil)
96-
9786
}

0 commit comments

Comments
 (0)