@@ -10,6 +10,7 @@ import (
10
10
"testing"
11
11
"time"
12
12
13
+ "github.com/google/uuid"
13
14
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
14
15
)
15
16
@@ -22,7 +23,7 @@ func TestAccCachedImageDataSource(t *testing.T) {
22
23
files := map [string ]string {
23
24
".devcontainer/devcontainer.json" : `{"build": { "dockerfile": "Dockerfile" }}` ,
24
25
".devcontainer/Dockerfile" : `FROM localhost:5000/test-ubuntu:latest
25
- RUN apt-get update && apt-get install -y cowsay ` ,
26
+ RUN date > /date.txt ` ,
26
27
}
27
28
28
29
deps := setup (ctx , t , files )
@@ -37,7 +38,7 @@ func TestAccCachedImageDataSource(t *testing.T) {
37
38
}
38
39
cache_repo = %q
39
40
verbose = true
40
- }` , deps .BuilderImage , "/workspace" , deps .Repo .URL , deps .Repo .Key , deps .CacheRepo )
41
+ }` , deps .BuilderImage , deps . Repo . Dir , deps .Repo .URL , deps .Repo .Key , deps .CacheRepo )
41
42
resource .Test (t , resource.TestCase {
42
43
PreCheck : func () { testAccPreCheck (t ) },
43
44
ProtoV6ProviderFactories : testAccProtoV6ProviderFactories ,
@@ -85,7 +86,7 @@ func TestAccCachedImageDataSource(t *testing.T) {
85
86
files := map [string ]string {
86
87
".devcontainer/devcontainer.json" : `{"build": { "dockerfile": "Dockerfile" }}` ,
87
88
".devcontainer/Dockerfile" : `FROM localhost:5000/test-ubuntu:latest
88
- RUN apt-get update && apt-get install -y cowsay ` ,
89
+ RUN date > /date.txt ` ,
89
90
}
90
91
deps := setup (ctx , t , files )
91
92
// We do not seed the cache.
@@ -99,27 +100,28 @@ func TestAccCachedImageDataSource(t *testing.T) {
99
100
}
100
101
cache_repo = %q
101
102
verbose = true
102
- }` , deps .BuilderImage , "/workspace" , deps .Repo .URL , deps .Repo .Key , deps .CacheRepo )
103
+ }` , deps .BuilderImage , deps . Repo . Dir , deps .Repo .URL , deps .Repo .Key , deps .CacheRepo )
103
104
resource .Test (t , resource.TestCase {
104
105
PreCheck : func () { testAccPreCheck (t ) },
105
106
ProtoV6ProviderFactories : testAccProtoV6ProviderFactories ,
106
107
Steps : []resource.TestStep {
107
108
{
108
109
Config : tfCfg ,
109
110
Check : resource .ComposeAggregateTestCheckFunc (
111
+ // Computed values MUST be present.
112
+ resource .TestCheckResourceAttr ("envbuilder_cached_image.test" , "id" , uuid .Nil .String ()),
113
+ resource .TestCheckResourceAttr ("envbuilder_cached_image.test" , "exists" , "false" ),
114
+ resource .TestCheckResourceAttrSet ("envbuilder_cached_image.test" , "env.0" ),
115
+ // Cached image should be set to the builder image.
116
+ resource .TestCheckResourceAttr ("envbuilder_cached_image.test" , "image" , deps .BuilderImage ),
110
117
// Inputs should still be present.
111
118
resource .TestCheckResourceAttr ("envbuilder_cached_image.test" , "cache_repo" , deps .CacheRepo ),
112
119
resource .TestCheckResourceAttr ("envbuilder_cached_image.test" , "extra_env.FOO" , "bar" ),
113
120
resource .TestCheckResourceAttr ("envbuilder_cached_image.test" , "git_url" , deps .Repo .URL ),
114
- resource .TestCheckResourceAttr ("envbuilder_cached_image.test" , "exists" , "false" ),
115
- resource .TestCheckResourceAttr ("envbuilder_cached_image.test" , "image" , deps .BuilderImage ),
116
121
// Should be empty
117
122
resource .TestCheckNoResourceAttr ("envbuilder_cached_image.test" , "git_username" ),
118
123
resource .TestCheckNoResourceAttr ("envbuilder_cached_image.test" , "git_password" ),
119
124
resource .TestCheckNoResourceAttr ("envbuilder_cached_image.test" , "cache_ttl_days" ),
120
- // Computed values should be empty.
121
- resource .TestCheckNoResourceAttr ("envbuilder_cached_image.test" , "id" ),
122
- resource .TestCheckResourceAttrSet ("envbuilder_cached_image.test" , "env.0" ),
123
125
),
124
126
},
125
127
},
0 commit comments