@@ -18,6 +18,7 @@ import (
1818 "github.com/coder/coder/provisioner/echo"
1919 "github.com/coder/coder/provisionersdk/proto"
2020 "github.com/coder/coder/pty/ptytest"
21+ "github.com/coder/coder/testutil"
2122)
2223
2324func TestTemplatePush (t * testing.T ) {
@@ -69,6 +70,86 @@ func TestTemplatePush(t *testing.T) {
6970 require .Equal (t , "example" , templateVersions [1 ].Name )
7071 })
7172
73+ t .Run ("NoLockfile" , func (t * testing.T ) {
74+ t .Parallel ()
75+ client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerDaemon : true })
76+ user := coderdtest .CreateFirstUser (t , client )
77+ version := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
78+ _ = coderdtest .AwaitTemplateVersionJob (t , client , version .ID )
79+
80+ template := coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
81+
82+ // Test the cli command.
83+ source := clitest .CreateTemplateVersionSource (t , & echo.Responses {
84+ Parse : echo .ParseComplete ,
85+ ProvisionApply : echo .ProvisionComplete ,
86+ })
87+ require .NoError (t , os .Remove (filepath .Join (source , ".terraform.lock.hcl" )))
88+
89+ inv , root := clitest .New (t , "templates" , "push" , template .Name , "--directory" , source , "--test.provisioner" , string (database .ProvisionerTypeEcho ), "--name" , "example" )
90+ clitest .SetupConfig (t , client , root )
91+ pty := ptytest .New (t ).Attach (inv )
92+
93+ execDone := make (chan error )
94+ go func () {
95+ execDone <- inv .Run ()
96+ }()
97+
98+ matches := []struct {
99+ match string
100+ write string
101+ }{
102+ {match : "No .terraform.lock.hcl file found" },
103+ {match : "Upload" , write : "no" },
104+ }
105+ for _ , m := range matches {
106+ pty .ExpectMatch (m .match )
107+ if m .write != "" {
108+ pty .WriteLine (m .write )
109+ }
110+ }
111+
112+ // cmd should error once we say no.
113+ require .Error (t , <- execDone )
114+ })
115+
116+ t .Run ("NoLockfileIgnored" , func (t * testing.T ) {
117+ t .Parallel ()
118+ client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerDaemon : true })
119+ user := coderdtest .CreateFirstUser (t , client )
120+ version := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
121+ _ = coderdtest .AwaitTemplateVersionJob (t , client , version .ID )
122+
123+ template := coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
124+
125+ // Test the cli command.
126+ source := clitest .CreateTemplateVersionSource (t , & echo.Responses {
127+ Parse : echo .ParseComplete ,
128+ ProvisionApply : echo .ProvisionComplete ,
129+ })
130+ require .NoError (t , os .Remove (filepath .Join (source , ".terraform.lock.hcl" )))
131+
132+ inv , root := clitest .New (t , "templates" , "push" , template .Name , "--directory" , source , "--test.provisioner" , string (database .ProvisionerTypeEcho ), "--name" , "example" , "--ignore-lockfile" )
133+ clitest .SetupConfig (t , client , root )
134+ pty := ptytest .New (t ).Attach (inv )
135+
136+ execDone := make (chan error )
137+ go func () {
138+ execDone <- inv .Run ()
139+ }()
140+
141+ {
142+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitMedium )
143+ defer cancel ()
144+
145+ pty .ExpectNoMatchBefore (ctx , "No .terraform.lock.hcl file found" , "Upload" )
146+ pty .WriteLine ("no" )
147+ }
148+
149+ // cmd should error once we say no.
150+ require .Error (t , <- execDone )
151+ })
152+
72153 t .Run ("PushInactiveTemplateVersion" , func (t * testing.T ) {
73154 t .Parallel ()
74155 client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerDaemon : true })
0 commit comments