99 "net/http"
1010 "net/url"
1111 "path"
12+ "regexp"
1213 "strings"
1314 "testing"
1415 "time"
@@ -19,6 +20,7 @@ import (
1920 "forgejo.org/models/unittest"
2021 user_model "forgejo.org/models/user"
2122 "forgejo.org/modules/git"
23+ "forgejo.org/modules/optional"
2224 "forgejo.org/modules/setting"
2325 "forgejo.org/modules/test"
2426 "forgejo.org/modules/translation"
@@ -1438,3 +1440,58 @@ func TestBlameDirectory(t *testing.T) {
14381440 req = NewRequest (t , "GET" , "/user2/repo59/blame/branch/master/deep" )
14391441 MakeRequest (t , req , http .StatusNotFound )
14401442}
1443+
1444+ func TestInitInstructions (t * testing.T ) {
1445+ defer tests .PrepareTestEnv (t )()
1446+
1447+ user := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : 2 })
1448+ session := loginUser (t , user .Name )
1449+
1450+ sha256Repo , _ , f := tests .CreateDeclarativeRepoWithOptions (t , user , tests.DeclarativeRepoOptions {
1451+ Name : optional .Some ("sha256-instruction" ),
1452+ AutoInit : optional .Some (false ),
1453+ EnabledUnits : optional .Some ([]unit_model.Type {unit_model .TypeCode }),
1454+ ObjectFormat : optional .Some ("sha256" ),
1455+ })
1456+ defer f ()
1457+
1458+ sha1Repo , _ , f := tests .CreateDeclarativeRepoWithOptions (t , user , tests.DeclarativeRepoOptions {
1459+ Name : optional .Some ("sha1-instruction" ),
1460+ AutoInit : optional .Some (false ),
1461+ EnabledUnits : optional .Some ([]unit_model.Type {unit_model .TypeCode }),
1462+ ObjectFormat : optional .Some ("sha1" ),
1463+ })
1464+ defer f ()
1465+
1466+ portMatcher := regexp .MustCompile (`localhost:\d+` )
1467+
1468+ t .Run ("sha256" , func (t * testing.T ) {
1469+ defer tests .PrintCurrentTest (t )()
1470+
1471+ resp := session .MakeRequest (t , NewRequest (t , "GET" , "/" + sha256Repo .FullName ()), http .StatusOK )
1472+
1473+ htmlDoc := NewHTMLParser (t , resp .Body )
1474+ assert .Equal (t , `touch README.md
1475+ git init --object-format=sha256
1476+ git switch -c main
1477+ git add README.md
1478+ git commit -m "first commit"
1479+ git remote add origin http://localhost/user2/sha256-instruction.git
1480+ git push -u origin main` , portMatcher .ReplaceAllString (htmlDoc .Find (".empty-repo-guide code" ).First ().Text (), "localhost" ))
1481+ })
1482+
1483+ t .Run ("sha1" , func (t * testing.T ) {
1484+ defer tests .PrintCurrentTest (t )()
1485+
1486+ resp := session .MakeRequest (t , NewRequest (t , "GET" , "/" + sha1Repo .FullName ()), http .StatusOK )
1487+
1488+ htmlDoc := NewHTMLParser (t , resp .Body )
1489+ assert .Equal (t , `touch README.md
1490+ git init
1491+ git switch -c main
1492+ git add README.md
1493+ git commit -m "first commit"
1494+ git remote add origin http://localhost/user2/sha1-instruction.git
1495+ git push -u origin main` , portMatcher .ReplaceAllString (htmlDoc .Find (".empty-repo-guide code" ).First ().Text (), "localhost" ))
1496+ })
1497+ }
0 commit comments