@@ -25,6 +25,40 @@ import (
2525 "github.com/tidwall/gjson"
2626)
2727
28+ func TestIsComponentInstalledFound (t * gotest.T ) {
29+ betaComponents , err := os .ReadFile (filepath .Join ("." , "testdata" , "beta_components_installed.json" ))
30+ assert .NoError (t , err )
31+ gcp := GCP {
32+ Runf : func (t testing.TB , cmd string , args ... interface {}) gjson.Result {
33+ return gjson.Result {
34+ Type : gjson .JSON ,
35+ Raw : string (betaComponents [:]),
36+ }
37+ },
38+ sleepTime : 1 ,
39+ }
40+ componentID := "beta"
41+ result := gcp .IsComponentInstalled (t , componentID )
42+ assert .True (t , result , "component '%s' should be installed" , componentID )
43+ }
44+
45+ func TestIsComponentInstalledNotFound (t * gotest.T ) {
46+ betaComponents , err := os .ReadFile (filepath .Join ("." , "testdata" , "beta_components_not_installed.json" ))
47+ assert .NoError (t , err )
48+ gcp := GCP {
49+ Runf : func (t testing.TB , cmd string , args ... interface {}) gjson.Result {
50+ return gjson.Result {
51+ Type : gjson .JSON ,
52+ Raw : string (betaComponents [:]),
53+ }
54+ },
55+ sleepTime : 1 ,
56+ }
57+ componentID := "beta"
58+ result := gcp .IsComponentInstalled (t , componentID )
59+ assert .False (t , result , "component '%s' should not be installed" , componentID )
60+ }
61+
2862func TestGetLastBuildStatus (t * gotest.T ) {
2963 current , err := os .ReadFile (filepath .Join ("." , "testdata" , "success_build.json" ))
3064 assert .NoError (t , err )
@@ -101,7 +135,7 @@ func TestWaitBuildSuccess(t *gotest.T) {
101135 sleepTime : 1 ,
102136 }
103137
104- err = gcp .WaitBuildSuccess (t , "prj-b-cicd-0123" , "us-central1" , "repo" ,"" , "failed_test_for_WaitBuildSuccess" , 40 )
138+ err = gcp .WaitBuildSuccess (t , "prj-b-cicd-0123" , "us-central1" , "repo" , "" , "failed_test_for_WaitBuildSuccess" , 40 )
105139 assert .Error (t , err , "should have failed" )
106140 assert .Contains (t , err .Error (), "failed_test_for_WaitBuildSuccess" , "should have failed with custom info" )
107141 assert .Equal (t , callCount , 3 , "Runf must be called three times" )
@@ -133,7 +167,7 @@ func TestWaitBuildTimeout(t *gotest.T) {
133167 sleepTime : 1 ,
134168 }
135169
136- err = gcp .WaitBuildSuccess (t , "prj-b-cicd-0123" , "us-central1" , "repo" ,"" , "failed_test_for_WaitBuildSuccess" , 1 )
170+ err = gcp .WaitBuildSuccess (t , "prj-b-cicd-0123" , "us-central1" , "repo" , "" , "failed_test_for_WaitBuildSuccess" , 1 )
137171 assert .Error (t , err , "should have failed" )
138172 assert .Contains (t , err .Error (), "timeout waiting for build '736f4689-2497-4382-afd0-b5f0f50eea5b' execution" , "should have failed with timeout error" )
139173 assert .Equal (t , callCount , 3 , "Runf must be called three times" )
0 commit comments