@@ -55,6 +55,50 @@ func TestModelComponent_Index(t *testing.T) {
5555
5656}
5757
58+ func TestModelComponent_Index_HalfCreatedRepos (t * testing.T ) {
59+ ctx := context .TODO ()
60+ mc := initializeTestModelComponent (ctx , t )
61+
62+ filter := & types.RepoFilter {Username : "user" }
63+ // PublicToUser returns 3 repositories, but only 2 have corresponding models
64+ mc .mocks .components .repo .EXPECT ().PublicToUser (ctx , types .ModelRepo , "user" , filter , 10 , 1 ).Return (
65+ []* database.Repository {
66+ {ID : 1 , Name : "r1" , Tags : []database.Tag {{Name : "t1" }}},
67+ {ID : 2 , Name : "r2" , Tags : []database.Tag {{Name : "t2" }}},
68+ {ID : 3 , Name : "half-created" , Tags : []database.Tag {{Name : "t3" }}}, // This is a half-created repo with no model
69+ }, 3 , nil , // Total should be 3
70+ )
71+
72+ // ByRepoIDs returns only 2 models (no model for repo ID 3)
73+ mc .mocks .stores .ModelMock ().EXPECT ().ByRepoIDs (ctx , []int64 {1 , 2 , 3 }).Return ([]database.Model {
74+ {RepositoryID : 1 , ID : 11 , Repository : & database.Repository {}},
75+ {RepositoryID : 2 , ID : 12 , Repository : & database.Repository {}},
76+ }, nil )
77+
78+ data , total , err := mc .Index (ctx , filter , 10 , 1 , false )
79+ require .Nil (t , err )
80+ require .Equal (t , 3 , total ) // Total should match PublicToUser's return value
81+ require .Len (t , data , 2 ) // But only 2 models should be returned
82+
83+ require .Equal (t , []* types.Model {
84+ {
85+ ID : 11 , Name : "r1" , Tags : []types.RepoTag {{Name : "t1" }}, RepositoryID : 1 ,
86+ Repository : types.Repository {
87+ HTTPCloneURL : "https://foo.com/s/.git" ,
88+ SSHCloneURL : "test@127.0.0.1:s/.git" ,
89+ },
90+ },
91+ {
92+ ID : 12 , Name : "r2" , Tags : []types.RepoTag {{Name : "t2" }}, RepositoryID : 2 ,
93+ Repository : types.Repository {
94+ HTTPCloneURL : "https://foo.com/s/.git" ,
95+ SSHCloneURL : "test@127.0.0.1:s/.git" ,
96+ },
97+ },
98+ }, data )
99+
100+ }
101+
58102func TestModelComponent_Create (t * testing.T ) {
59103 ctx := context .TODO ()
60104 mc := initializeTestModelComponent (ctx , t )
0 commit comments