MCPcopy Index your code
hub / github.com/dnote/dnote / TestUserListCmd

Function TestUserListCmd

pkg/server/cmd/user_test.go:113–158  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

111}
112
113func TestUserListCmd(t *testing.T) {
114 t.Run("multiple users", func(t *testing.T) {
115 tmpDB := t.TempDir() + "/test.db"
116
117 // Create multiple users
118 db := testutils.InitDB(tmpDB)
119 user1 := testutils.SetupUserData(db, "alice@example.com", "password123")
120 user2 := testutils.SetupUserData(db, "bob@example.com", "password123")
121 user3 := testutils.SetupUserData(db, "charlie@example.com", "password123")
122 sqlDB, _ := db.DB()
123 sqlDB.Close()
124
125 // Capture output
126 var buf bytes.Buffer
127 userListCmd([]string{"--dbPath", tmpDB}, &buf)
128
129 // Verify output matches expected format
130 output := strings.TrimSpace(buf.String())
131 lines := strings.Split(output, "\n")
132
133 expectedLine1 := fmt.Sprintf("%s,alice@example.com,%s", user1.UUID, user1.CreatedAt.UTC().Format("2006-01-02T15:04:05Z"))
134 expectedLine2 := fmt.Sprintf("%s,bob@example.com,%s", user2.UUID, user2.CreatedAt.UTC().Format("2006-01-02T15:04:05Z"))
135 expectedLine3 := fmt.Sprintf("%s,charlie@example.com,%s", user3.UUID, user3.CreatedAt.UTC().Format("2006-01-02T15:04:05Z"))
136
137 assert.Equal(t, lines[0], expectedLine1, "line 1 should match")
138 assert.Equal(t, lines[1], expectedLine2, "line 2 should match")
139 assert.Equal(t, lines[2], expectedLine3, "line 3 should match")
140 })
141
142 t.Run("empty database", func(t *testing.T) {
143 tmpDB := t.TempDir() + "/test.db"
144
145 // Initialize empty database
146 db := testutils.InitDB(tmpDB)
147 sqlDB, _ := db.DB()
148 sqlDB.Close()
149
150 // Capture output
151 var buf bytes.Buffer
152 userListCmd([]string{"--dbPath", tmpDB}, &buf)
153
154 // Verify no output
155 output := buf.String()
156 assert.Equal(t, output, "", "should have no output for empty database")
157 })
158}

Callers

nothing calls this directly

Calls 5

InitDBFunction · 0.92
SetupUserDataFunction · 0.92
EqualFunction · 0.92
userListCmdFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected