github.com/chenbh/concourse/v6@v6.4.2/atc/integration/team_migration_test.go (about) 1 package integration_test 2 3 import ( 4 "fmt" 5 "math/rand" 6 "net/http" 7 "os" 8 "time" 9 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 "github.com/tedsuo/ifrit" 13 ) 14 15 var _ = XDescribe("ATC 3.13 Team Migration Test", func() { 16 var ( 17 atcProcess ifrit.Process 18 atcURL string 19 20 oldMigrationVersion = 1524079655 21 22 runner ifrit.Runner 23 24 username string 25 password string 26 ) 27 28 BeforeSuite(func() { 29 rand.Seed(time.Now().UnixNano()) 30 }) 31 32 BeforeEach(func() { 33 username = randomString() 34 password = randomString() 35 36 atcURL = fmt.Sprintf("http://localhost:%v", cmd.BindPort) 37 38 cmd.Auth.MainTeamFlags.LocalUsers = []string{username} 39 cmd.Auth.AuthFlags.LocalUsers = map[string]string{ 40 username: password, 41 } 42 43 var err error 44 runner, err = cmd.Runner([]string{}) 45 Expect(err).NotTo(HaveOccurred()) 46 }) 47 48 AfterEach(func() { 49 atcProcess.Signal(os.Interrupt) 50 <-atcProcess.Wait() 51 }) 52 53 Context("migrations", func() { 54 BeforeEach(func() { 55 db := postgresRunner.OpenDBAtVersion(oldMigrationVersion) 56 defer db.Close() 57 58 auth := fmt.Sprintf(`{"basicauth":{"username":"%s", "password":"%s"}}`, username, password) 59 rows, err := db.Query(`UPDATE teams SET auth=$1 WHERE name='main'`, auth) 60 rows.Close() 61 62 Expect(err).ToNot(HaveOccurred()) 63 Expect(db.Close()).ToNot(HaveOccurred()) 64 }) 65 66 It("Successfully migrates", func() { 67 atcProcess = ifrit.Invoke(runner) 68 Eventually(func() error { 69 _, err := http.Get(atcURL + "/api/v1/info") 70 return err 71 }, 20*time.Second).ShouldNot(HaveOccurred()) 72 73 db := postgresRunner.OpenDB() 74 rows, err := db.Query(`SELECT auth FROM teams`) 75 76 defer db.Close() 77 defer rows.Close() 78 79 Expect(err).ToNot(HaveOccurred()) 80 81 var auth string 82 for rows.Next() { 83 rows.Scan(&auth) 84 } 85 Expect(auth).To(ContainSubstring(username)) 86 }) 87 }) 88 }) 89 90 var characterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%=") 91 92 func randomString() string { 93 b := make([]rune, 50) 94 for i := range b { 95 b[i] = characterRunes[rand.Intn(len(characterRunes))] 96 } 97 return string(b) 98 }