MCPcopy Index your code
hub / github.com/coder/coder / TestInstall

Function TestInstall

provisioner/terraform/install_test.go:120–190  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

118}
119
120func TestInstall(t *testing.T) {
121 t.Parallel()
122 if testing.Short() {
123 t.SkipNow()
124 }
125 ctx := context.Background()
126 dir := t.TempDir()
127 log := testutil.Logger(t)
128
129 proxy := persistentlyCachedProxy(t)
130 go proxy.srv.Serve(proxy.listener)
131 t.Cleanup(func() {
132 require.NoError(t, proxy.srv.Close())
133 })
134
135 // Install spins off 8 installs with Version and waits for them all
136 // to complete. The locking mechanism within Install should
137 // prevent multiple binaries from being installed, so the function
138 // should perform like a single install.
139 install := func(version *version.Version) string {
140 var wg sync.WaitGroup
141 paths := make(chan string, 8)
142 for i := 0; i < 8; i++ {
143 wg.Add(1)
144 go func() {
145 defer wg.Done()
146 p, err := terraform.Install(ctx, log, false, dir, version, "http://"+proxy.listener.Addr().String())
147 assert.NoError(t, err)
148 paths <- p
149 }()
150 }
151 go func() {
152 wg.Wait()
153 close(paths)
154 }()
155 var firstPath string
156 for p := range paths {
157 if firstPath == "" {
158 firstPath = p
159 } else {
160 require.Equal(t, firstPath, p, "installs returned different paths")
161 }
162 }
163 return firstPath
164 }
165
166 binPath := install(version1)
167
168 checkBinModTime := func() time.Time {
169 binInfo, err := os.Stat(binPath)
170 require.NoError(t, err)
171 require.Greater(t, binInfo.Size(), int64(0))
172 return binInfo.ModTime()
173 }
174
175 modTime1 := checkBinModTime()
176
177 // Since we're using the same version the install should be idempotent.

Callers

nothing calls this directly

Calls 15

LoggerFunction · 0.92
InstallFunction · 0.92
persistentlyCachedProxyFunction · 0.85
SkipNowMethod · 0.80
SizeMethod · 0.80
TempDirMethod · 0.65
CleanupMethod · 0.65
CloseMethod · 0.65
AddMethod · 0.65
WaitMethod · 0.65
ServeMethod · 0.45
DoneMethod · 0.45

Tested by

no test coverage detected