github.com/drud/ddev@v1.21.5-alpha1.0.20230226034409-94fcc4b94453/pkg/ddevapp/container_test.go (about) 1 package ddevapp_test 2 3 import ( 4 "fmt" 5 "github.com/drud/ddev/pkg/ddevapp" 6 "github.com/drud/ddev/pkg/util" 7 asrt "github.com/stretchr/testify/assert" 8 "os" 9 "strings" 10 "testing" 11 "time" 12 ) 13 14 // Test to make sure that the user provisioned in the container has 15 // the proper uid/gid/username characteristics. 16 func TestUserProvisioningInContainer(t *testing.T) { 17 assert := asrt.New(t) 18 app := &ddevapp.DdevApp{} 19 20 // Make sure this leaves us in the original test directory 21 testDir, _ := os.Getwd() 22 //nolint: errcheck 23 defer os.Chdir(testDir) 24 25 site := TestSites[0] 26 switchDir := site.Chdir() 27 defer switchDir() 28 29 runTime := util.TimeTrack(time.Now(), fmt.Sprintf("%s %s", site.Name, t.Name())) 30 defer runTime() 31 32 err := app.Init(site.Dir) 33 assert.NoError(err) 34 35 err = app.Start() 36 assert.NoError(err) 37 //nolint: errcheck 38 defer app.Stop(true, false) 39 40 // make sure files get created in the user? 41 42 uid, gid, username := util.GetContainerUIDGid() 43 44 for _, service := range []string{"web", "db"} { 45 46 out, _, err := app.Exec(&ddevapp.ExecOpts{ 47 Service: service, 48 Cmd: "id -un", 49 }) 50 assert.NoError(err) 51 assert.Equal(username, strings.Trim(out, "\r\n")) 52 53 out, _, err = app.Exec(&ddevapp.ExecOpts{ 54 Service: service, 55 Cmd: "id -u", 56 }) 57 assert.NoError(err) 58 assert.Equal(uid, strings.Trim(out, "\r\n")) 59 60 out, _, err = app.Exec(&ddevapp.ExecOpts{ 61 Service: service, 62 Cmd: "id -g", 63 }) 64 assert.NoError(err) 65 assert.Equal(gid, strings.Trim(out, "\r\n")) 66 } 67 68 }