@@ -19,37 +19,50 @@ package notifier
1919import (
2020 "context"
2121 "testing"
22+ "time"
2223
2324 eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
2425 "github.com/microsoft/azure-devops-go-api/azuredevops/v6/git"
25- "github.com/stretchr/testify/assert "
26+ . "github.com/onsi/gomega "
2627 corev1 "k8s.io/api/core/v1"
2728)
2829
2930func TestNewAzureDevOpsBasic (t * testing.T ) {
30- a , err := NewAzureDevOps (context .TODO (), "kustomization/gitops-system/0c9c2e41" , "https://dev.azure.com/foo/bar/_git/baz" , "foo" , nil , "" , "" , "" , "" , nil , nil )
31- assert .Nil (t , err )
32- assert .Equal (t , a .Project , "bar" )
33- assert .Equal (t , a .Repo , "baz" )
31+ g := NewWithT (t )
32+ ctx , cancel := context .WithTimeout (context .Background (), time .Second )
33+ defer cancel ()
34+ a , err := NewAzureDevOps (ctx , "kustomization/gitops-system/0c9c2e41" , "https://dev.azure.com/foo/bar/_git/baz" , "foo" , nil , "" , "" , "" , "" , nil , nil )
35+ g .Expect (err ).ToNot (HaveOccurred ())
36+ g .Expect (a .Project ).To (Equal ("bar" ))
37+ g .Expect (a .Repo ).To (Equal ("baz" ))
3438}
3539
3640func TestNewAzureDevOpsInvalidUrl (t * testing.T ) {
37- _ , err := NewAzureDevOps (context .TODO (), "kustomization/gitops-system/0c9c2e41" , "https://dev.azure.com/foo/bar/baz" , "foo" , nil , "" , "" , "" , "" , nil , nil )
38- assert .NotNil (t , err )
41+ g := NewWithT (t )
42+ ctx , cancel := context .WithTimeout (context .Background (), time .Second )
43+ defer cancel ()
44+ _ , err := NewAzureDevOps (ctx , "kustomization/gitops-system/0c9c2e41" , "https://dev.azure.com/foo/bar/baz" , "foo" , nil , "" , "" , "" , "" , nil , nil )
45+ g .Expect (err ).To (HaveOccurred ())
3946}
4047
4148func TestNewAzureDevOpsMissingToken (t * testing.T ) {
42- _ , err := NewAzureDevOps (context .TODO (), "kustomization/gitops-system/0c9c2e41" , "https://dev.azure.com/foo/bar/baz" , "" , nil , "" , "" , "" , "" , nil , nil )
43- assert .NotNil (t , err )
49+ g := NewWithT (t )
50+ ctx , cancel := context .WithTimeout (context .Background (), time .Second )
51+ defer cancel ()
52+ _ , err := NewAzureDevOps (ctx , "kustomization/gitops-system/0c9c2e41" , "https://dev.azure.com/foo/bar/baz" , "" , nil , "" , "" , "" , "" , nil , nil )
53+ g .Expect (err ).To (HaveOccurred ())
4454}
4555
4656func TestNewAzureDevOpsEmptyCommitStatus (t * testing.T ) {
47- _ , err := NewAzureDevOps (context .TODO (), "" , "https://dev.azure.com/foo/bar/_git/baz" , "foo" , nil , "" , "" , "" , "" , nil , nil )
48- assert .NotNil (t , err )
57+ g := NewWithT (t )
58+ ctx , cancel := context .WithTimeout (context .Background (), time .Second )
59+ defer cancel ()
60+ _ , err := NewAzureDevOps (ctx , "" , "https://dev.azure.com/foo/bar/_git/baz" , "foo" , nil , "" , "" , "" , "" , nil , nil )
61+ g .Expect (err ).To (HaveOccurred ())
4962}
5063
5164func TestDuplicateAzureDevOpsStatus (t * testing.T ) {
52- assert := assert . New (t )
65+ g := NewWithT (t )
5366
5467 var tests = []struct {
5568 ss * []git.GitStatus
@@ -64,7 +77,7 @@ func TestDuplicateAzureDevOpsStatus(t *testing.T) {
6477 }
6578
6679 for _ , test := range tests {
67- assert . Equal ( test . dup , duplicateAzureDevOpsStatus (test .ss , test .s ))
80+ g . Expect ( duplicateAzureDevOpsStatus (test .ss , test .s )). To ( Equal ( test . dup ))
6881 }
6982}
7083
@@ -165,16 +178,19 @@ func TestAzureDevOps_Post(t *testing.T) {
165178
166179 for _ , tt := range postTests {
167180 t .Run (tt .name , func (t * testing.T ) {
168- a , err := NewAzureDevOps (context .TODO (), "kustomization/gitops-system/0c9c2e41" , "https://example.com/foo/bar/_git/baz" , "foo" , nil , "" , "" , "" , "" , nil , nil )
181+ ctx , cancel := context .WithTimeout (context .Background (), time .Second )
182+ defer cancel ()
183+ a , err := NewAzureDevOps (ctx , "kustomization/gitops-system/0c9c2e41" , "https://example.com/foo/bar/_git/baz" , "foo" , nil , "" , "" , "" , "" , nil , nil )
169184 fakeClient := & fakeDevOpsClient {}
170185 a .Client = fakeClient
171- assert .Nil (t , err )
186+ g := NewWithT (t )
187+ g .Expect (err ).ToNot (HaveOccurred ())
172188
173- err = a .Post (context . TODO () , tt .event )
174- assert . Nil ( t , err )
189+ err = a .Post (ctx , tt .event )
190+ g . Expect ( err ). ToNot ( HaveOccurred () )
175191
176192 want := []git.CreateCommitStatusArgs {tt .want }
177- assert . Equal ( t , want , fakeClient .created )
193+ g . Expect ( fakeClient .created ). To ( Equal ( want ) )
178194 })
179195 }
180196}
0 commit comments