@@ -970,13 +970,24 @@ func TestPreviousTemplateVersion(t *testing.T) {
970
970
t .Parallel ()
971
971
client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerDaemon : true })
972
972
user := coderdtest .CreateFirstUser (t , client )
973
- version := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
974
- coderdtest .AwaitTemplateVersionJob (t , client , version .ID )
973
+
974
+ // Create two templates to be sure it is not returning a previous version
975
+ // from another template
976
+ templateAVersion1 := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
977
+ coderdtest .CreateTemplate (t , client , user .OrganizationID , templateAVersion1 .ID )
978
+ coderdtest .AwaitTemplateVersionJob (t , client , templateAVersion1 .ID )
979
+ // Create two versions for the template B to be sure if we try to get the
980
+ // previous version of the first version it will returns a 404
981
+ templateBVersion1 := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
982
+ templateB := coderdtest .CreateTemplate (t , client , user .OrganizationID , templateBVersion1 .ID )
983
+ coderdtest .AwaitTemplateVersionJob (t , client , templateBVersion1 .ID )
984
+ templateBVersion2 := coderdtest .UpdateTemplateVersion (t , client , user .OrganizationID , nil , templateB .ID )
985
+ coderdtest .AwaitTemplateVersionJob (t , client , templateBVersion2 .ID )
975
986
976
987
ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
977
988
defer cancel ()
978
989
979
- _ , err := client .PreviousTemplateVersion (ctx , user .OrganizationID , version .Name )
990
+ _ , err := client .PreviousTemplateVersion (ctx , user .OrganizationID , templateBVersion1 .Name )
980
991
var apiErr * codersdk.Error
981
992
require .ErrorAs (t , err , & apiErr )
982
993
require .Equal (t , http .StatusNotFound , apiErr .StatusCode ())
@@ -986,17 +997,25 @@ func TestPreviousTemplateVersion(t *testing.T) {
986
997
t .Parallel ()
987
998
client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerDaemon : true })
988
999
user := coderdtest .CreateFirstUser (t , client )
989
- previousVersion := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
990
- coderdtest .AwaitTemplateVersionJob (t , client , previousVersion .ID )
991
- template := coderdtest .CreateTemplate (t , client , user .OrganizationID , previousVersion .ID )
992
- latestVersion := coderdtest .UpdateTemplateVersion (t , client , user .OrganizationID , nil , template .ID )
993
- coderdtest .AwaitTemplateVersionJob (t , client , latestVersion .ID )
1000
+
1001
+ // Create two templates to be sure it is not returning a previous version
1002
+ // from another template
1003
+ templateAVersion1 := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
1004
+ coderdtest .CreateTemplate (t , client , user .OrganizationID , templateAVersion1 .ID )
1005
+ coderdtest .AwaitTemplateVersionJob (t , client , templateAVersion1 .ID )
1006
+ // Create two versions for the template B so we can try to get the previous
1007
+ // version of version 2
1008
+ templateBVersion1 := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
1009
+ templateB := coderdtest .CreateTemplate (t , client , user .OrganizationID , templateBVersion1 .ID )
1010
+ coderdtest .AwaitTemplateVersionJob (t , client , templateBVersion1 .ID )
1011
+ templateBVersion2 := coderdtest .UpdateTemplateVersion (t , client , user .OrganizationID , nil , templateB .ID )
1012
+ coderdtest .AwaitTemplateVersionJob (t , client , templateBVersion2 .ID )
994
1013
995
1014
ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
996
1015
defer cancel ()
997
1016
998
- result , err := client .PreviousTemplateVersion (ctx , user .OrganizationID , latestVersion .Name )
1017
+ result , err := client .PreviousTemplateVersion (ctx , user .OrganizationID , templateBVersion2 .Name )
999
1018
require .NoError (t , err )
1000
- require .Equal (t , previousVersion .ID , result .ID )
1019
+ require .Equal (t , templateBVersion1 .ID , result .ID )
1001
1020
})
1002
1021
}
0 commit comments