@@ -2921,43 +2921,61 @@ func TestWorkspaces_AddTags(t *testing.T) {
29212921 })
29222922 require .NoError (t , err )
29232923
2924- // get the id of the new tag
2925- tags , err := client .Workspaces .ListTags (ctx , wTest2 .ID , nil )
2924+ // get the id of the new tag (may take a moment to show up)
2925+ createdTags , err := retryPatientlyIf (
2926+ func () (any , error ) {
2927+ return client .Workspaces .ListTags (ctx , wTest2 .ID , nil )
2928+ },
2929+ func (tl * TagList ) bool {
2930+ return tl == nil || len (tl .Items ) == 0
2931+ },
2932+ )
29262933 require .NoError (t , err )
2934+ require .NotNil (t , createdTags )
2935+ require .NotEmpty (t , createdTags .Items )
2936+ tagID := createdTags .Items [0 ].ID
29272937
29282938 // add the tag to our workspace by id
29292939 err = client .Workspaces .AddTags (ctx , wTest .ID , WorkspaceAddTagsOptions {
29302940 Tags : []* Tag {
29312941 {
2932- ID : tags . Items [ 0 ]. ID ,
2942+ ID : tagID ,
29332943 },
29342944 },
29352945 })
29362946 require .NoError (t , err )
29372947
2938- // tag is now in the tag_names
2939- // retry in case the system is busy
2940- w , err := retryPatientlyIf (
2948+ // tag is now in our tag list
2949+ wt , err := retryPatientlyIf (
29412950 func () (any , error ) {
2942- return client .Workspaces .Read (ctx , orgTest . Name , wTest . Name )
2951+ return client .Workspaces .ListTags (ctx , wTest . ID , nil )
29432952 },
2944- func (w * Workspace ) bool {
2945- return len (w .TagNames ) < 5
2953+ func (tl * TagList ) bool {
2954+ // wait for the tag to appear
2955+ if tl == nil {
2956+ return true
2957+ }
2958+ for _ , tag := range tl .Items {
2959+ if tag .ID == tagID {
2960+ return false
2961+ }
2962+ }
2963+ return true
29462964 },
29472965 )
2948-
29492966 require .NoError (t , err )
2950- require .NotEmpty (t , w )
2951- assert .Equal (t , 5 , len (w .TagNames ))
2952- sort .Strings (w .TagNames )
2953- assert .Equal (t , w .TagNames , []string {"tag1" , "tag2" , "tag3" , "tag4" , "tagbyid" })
2967+ require .NotNil (t , wt )
29542968
2955- // tag is now in our tag list
2956- wt , err := client .Workspaces .ListTags (ctx , wTest .ID , nil )
2957- require .NoError (t , err )
2958- assert .Equal (t , 5 , len (wt .Items ))
2959- assert .Equal (t , wt .Items [4 ].ID , tags .Items [0 ].ID )
2960- assert .Equal (t , wt .Items [4 ].Name , "tagbyid" )
2969+ // find the tag we added
2970+ var addedTag * Tag
2971+ for _ , tag := range wt .Items {
2972+ if tag .ID == tagID {
2973+ addedTag = tag
2974+ break
2975+ }
2976+ }
2977+ require .NotNil (t , addedTag )
2978+ assert .Equal (t , "tagbyid" , addedTag .Name )
29612979 })
29622980
29632981 t .Run ("with invalid options" , func (t * testing.T ) {
0 commit comments