| 1 | package teams_testscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/teams_test`/ |
| 2 | |
| 3 | import ( |
| 4 | "bytesscip-go gomod github.com/golang/go/src . bytes/" |
| 5 | "ioscip-go gomod github.com/golang/go/src . io/" |
| 6 | "net/httpscip-go gomod github.com/golang/go/src . `net/http`/" |
| 7 | "net/urlscip-go gomod github.com/golang/go/src . `net/url`/" |
| 8 | "stringsscip-go gomod github.com/golang/go/src . strings/" |
| 9 | "testingscip-go gomod github.com/golang/go/src . testing/" |
| 10 | |
| 11 | "github.com/stretchr/testify/mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/" |
| 12 | |
| 13 | "github.com/nicholas-fedor/shoutrrr/pkg/services/chat/teamsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/teams`/" |
| 14 | ) |
| 15 | |
| 16 | // MockHTTPClient is a testify mock that implements the teams.HTTPClient interface. |
| 17 | type MockHTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/teams_test`/MockHTTPClient# struct { |
| 18 | mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Mockscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/teams_test`/MockHTTPClient#Mock. |
| 19 | } |
| 20 | |
| 21 | // mockLogger is a simple logger implementation for testing. |
| 22 | type mockLoggerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/teams_test`/mockLogger# struct{} |
| 23 | |
| 24 | const workflowURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/teams_test`/workflowURL. = "https://prod-00.westus.logic.azure.com:443/workflows/abc123/triggers/manual/paths/invoke?api-version=2016-06-00&sp=/triggers/manual/run&sv=1.0&sig=XXXXXXXX" |
| 25 | |
| 26 | func (m *mockLoggerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/teams_test`/mockLogger#) Printscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/teams_test`/mockLogger#Print().(_ ...any) {} |
| 27 | func (m *mockLoggerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/teams_test`/mockLogger#) Printfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/teams_test`/mockLogger#Printf().(_ string, _ ...any) {} |
| 28 | func (m *mockLoggerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/teams_test`/mockLogger#) Printlnscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/teams_test`/mockLogger#Println().(_ ...any) {} |
| 29 | |
| 30 | // createTestService creates a Teams service instance configured for testing. |
| 31 | func createTestServicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/teams_test`/createTestService().( |
| 32 | t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#, |
| 33 | webhookURL string, |
| 34 | httpClients ...teamsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/teams`/.HTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/teams`/HTTPClient#, |
| 35 | ) *teamsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/teams`/.Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/teams`/Service# { |
| 36 | t.Helperscip-go gomod github.com/golang/go/src . testing/common#Helper().() |
| 37 | |
| 38 | service := &teamsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/teams`/.Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/teams`/Service#{} |
| 39 | |
| 40 | parsedURL, err := urlscip-go gomod github.com/golang/go/src . `net/url`/.Parsescip-go gomod github.com/golang/go/src . `net/url`/Parse().(webhookURL) |
| 41 | if err != nil { |
| 42 | t.Fatalfscip-go gomod github.com/golang/go/src . testing/common#Fatalf().("failed to parse webhook URL: %v", err) |
| 43 | } |
| 44 | |
| 45 | err = service.Initializescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/teams`/Service#Initialize().(parsedURL, &mockLoggerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/teams_test`/mockLogger#{}) |
| 46 | if err != nil { |
| 47 | t.Fatalfscip-go gomod github.com/golang/go/src . testing/common#Fatalf().("failed to initialize service: %v", err) |
| 48 | } |
| 49 | |
| 50 | if len(httpClients) > 0 && httpClients[0] != nil { |
| 51 | service.SetHTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/teams`/Service#SetHTTPClient().(httpClients[0]) |
| 52 | } |
| 53 | |
| 54 | return service |
| 55 | } |
| 56 | |
| 57 | func (m *MockHTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/teams_test`/MockHTTPClient#) Doscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/teams_test`/MockHTTPClient#Do().(req *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) (*httpscip-go gomod github.com/golang/go/src . `net/http`/.Responsescip-go gomod github.com/golang/go/src . `net/http`/Response#, error) { |
| 58 | if req.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Request#Body. != nil { |
| 59 | body, err := ioscip-go gomod github.com/golang/go/src . io/.ReadAllscip-go gomod github.com/golang/go/src . io/ReadAll().(req.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Request#Body.) |
| 60 | if err == nil { |
| 61 | req.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Request#Body. = ioscip-go gomod github.com/golang/go/src . io/.NopCloserscip-go gomod github.com/golang/go/src . io/NopCloser().(bytesscip-go gomod github.com/golang/go/src . bytes/.NewReaderscip-go gomod github.com/golang/go/src . bytes/NewReader().(body)) |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | args := m.Calledscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#Called().(req) |
| 66 | |
| 67 | if args.Getscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Arguments#Get().(0) == nil { |
| 68 | return nil, args.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Arguments#Error().(1) |
| 69 | } |
| 70 | |
| 71 | return args.Getscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Arguments#Get().(0).(*httpscip-go gomod github.com/golang/go/src . `net/http`/.Responsescip-go gomod github.com/golang/go/src . `net/http`/Response#), args.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Arguments#Error().(1) |
| 72 | } |
| 73 | |
| 74 | // createMockResponse creates a mock HTTP response with the given status code, body, and optional headers. |
| 75 | // |
| 76 | //nolint:unparam // body and headers are intentionally exposed for callers to use |
| 77 | func createMockResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/teams_test`/createMockResponse().(statusCode int, body string, headers ...map[string]string) *httpscip-go gomod github.com/golang/go/src . `net/http`/.Responsescip-go gomod github.com/golang/go/src . `net/http`/Response# { |
| 78 | resp := &httpscip-go gomod github.com/golang/go/src . `net/http`/.Responsescip-go gomod github.com/golang/go/src . `net/http`/Response#{ |
| 79 | StatusCodescip-go gomod github.com/golang/go/src . `net/http`/Response#StatusCode.: statusCode, |
| 80 | Bodyscip-go gomod github.com/golang/go/src . `net/http`/Response#Body.: ioscip-go gomod github.com/golang/go/src . io/.NopCloserscip-go gomod github.com/golang/go/src . io/NopCloser().(stringsscip-go gomod github.com/golang/go/src . strings/.NewReaderscip-go gomod github.com/golang/go/src . strings/NewReader().(body)), |
| 81 | Headerscip-go gomod github.com/golang/go/src . `net/http`/Response#Header.: make(httpscip-go gomod github.com/golang/go/src . `net/http`/.Headerscip-go gomod github.com/golang/go/src . `net/http`/Header#), |
| 82 | } |
| 83 | |
| 84 | for _, hdrMap := range headers { |
| 85 | for k, v := range hdrMap { |
| 86 | resp.Headerscip-go gomod github.com/golang/go/src . `net/http`/Response#Header..Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().(k, v) |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | return resp |
| 91 | } |
| 92 | |
| 93 | // assertRequestContains asserts that the HTTP request body contains the expected content. |
| 94 | func assertRequestContainsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/teams_test`/assertRequestContains().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#, mockClient *MockHTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/teams_test`/MockHTTPClient#, expectedContent string) { |
| 95 | t.Helperscip-go gomod github.com/golang/go/src . testing/common#Helper().() |
| 96 | |
| 97 | found := false |
| 98 | |
| 99 | for i := range mockClient.Callsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#Calls. { |
| 100 | call := &mockClient.Callsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#Calls.[i] |
| 101 | if call.Methodscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Method. == "Do" { |
| 102 | req := call.Argumentsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Arguments.[0].(*httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) |
| 103 | |
| 104 | body, err := ioscip-go gomod github.com/golang/go/src . io/.ReadAllscip-go gomod github.com/golang/go/src . io/ReadAll().(req.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Request#Body.) |
| 105 | if err != nil { |
| 106 | continue |
| 107 | } |
| 108 | |
| 109 | req.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Request#Body. = ioscip-go gomod github.com/golang/go/src . io/.NopCloserscip-go gomod github.com/golang/go/src . io/NopCloser().(bytesscip-go gomod github.com/golang/go/src . bytes/.NewReaderscip-go gomod github.com/golang/go/src . bytes/NewReader().(body)) |
| 110 | |
| 111 | if stringsscip-go gomod github.com/golang/go/src . strings/.Containsscip-go gomod github.com/golang/go/src . strings/Contains().(string(body), expectedContent) { |
| 112 | found = true |
| 113 | |
| 114 | break |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | if !found { |
| 120 | t.Errorfscip-go gomod github.com/golang/go/src . testing/common#Errorf().("Expected request body to contain %q, but no matching call found", expectedContent) |
| 121 | } |
| 122 | } |