From c72d263c36f419bf042a76aa220a00f6b3a0fa45 Mon Sep 17 00:00:00 2001 From: Enrico Hoffmann Date: Fri, 8 Nov 2019 10:01:31 +0100 Subject: [PATCH 1/3] add mock file and update deps --- Gopkg.lock | 20 +++++++++++++++++--- mocks/API.go | 25 +++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 mocks/API.go diff --git a/Gopkg.lock b/Gopkg.lock index 316f347..14f7d9c 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -18,9 +18,20 @@ version = "v1.0.0" [[projects]] - digest = "1:972c2427413d41a1e06ca4897e8528e5a1622894050e2f527b38ddf0f343f759" + digest = "1:ac83cf90d08b63ad5f7e020ef480d319ae890c208f8524622a2f3136e2686b02" + name = "github.com/stretchr/objx" + packages = ["."] + pruneopts = "UT" + revision = "477a77ecc69700c7cdeb1fa9e129548e1c1c393c" + version = "v0.1.1" + +[[projects]] + digest = "1:0bcc464dabcfad5393daf87c3f8142911d0f6c52569b837e91a1c15e890265f3" name = "github.com/stretchr/testify" - packages = ["assert"] + packages = [ + "assert", + "mock", + ] pruneopts = "UT" revision = "ffdc059bfe9ce6a4e144ba849dbedead332c6053" version = "v1.3.0" @@ -28,6 +39,9 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - input-imports = ["github.com/stretchr/testify/assert"] + input-imports = [ + "github.com/stretchr/testify/assert", + "github.com/stretchr/testify/mock", + ] solver-name = "gps-cdcl" solver-version = 1 diff --git a/mocks/API.go b/mocks/API.go new file mode 100644 index 0000000..5a54f0b --- /dev/null +++ b/mocks/API.go @@ -0,0 +1,25 @@ +// Code generated by mockery v1.0.0. DO NOT EDIT. + +package mocks + +import goteamsnotify "go-teams-notify" +import mock "github.com/stretchr/testify/mock" + +// API is an autogenerated mock type for the API type +type API struct { + mock.Mock +} + +// Send provides a mock function with given fields: webhookURL, webhookMessage +func (_m *API) Send(webhookURL string, webhookMessage goteamsnotify.MessageCard) error { + ret := _m.Called(webhookURL, webhookMessage) + + var r0 error + if rf, ok := ret.Get(0).(func(string, goteamsnotify.MessageCard) error); ok { + r0 = rf(webhookURL, webhookMessage) + } else { + r0 = ret.Error(0) + } + + return r0 +} From 1f93e29ec9f60cb01ee83e66dc35871a6a63956b Mon Sep 17 00:00:00 2001 From: Enrico Hoffmann Date: Fri, 8 Nov 2019 10:06:25 +0100 Subject: [PATCH 2/3] improve/shorten conditions --- send.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/send.go b/send.go index 3b81569..146c570 100644 --- a/send.go +++ b/send.go @@ -35,7 +35,7 @@ func (c teamsClient) Send(webhookURL string, webhookMessage MessageCard) error { // validate url // needs to look like: https://outlook.office.com/webhook/xxx valid, err := isValidWebhookURL(webhookURL) - if valid != true { + if !valid { return err } // prepare message @@ -83,7 +83,7 @@ func isValidWebhookURL(webhookURL string) (bool, error) { } // only pass MS teams webhook URLs hasPrefix := strings.HasPrefix(webhookURL, "https://outlook.office.com/webhook/") - if hasPrefix != true { + if !hasPrefix { err = errors.New("unvalid ms teams webhook url") return false, err } From c6640ae2fc4a3676be586fe37cab7b855ae3cf54 Mon Sep 17 00:00:00 2001 From: Enrico Hoffmann Date: Fri, 8 Nov 2019 10:14:18 +0100 Subject: [PATCH 3/3] play with mock manipulation --- Gopkg.lock | 9 +++++++++ mocks/API.go | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 14f7d9c..cd9bf40 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -1,6 +1,14 @@ # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. +[[projects]] + digest = "1:922bd72f17793b0a3392b89552680850ecced7c35fba3e1afd6fcda86d6af3fb" + name = "github.com/dasrick/go-teams-notify" + packages = ["."] + pruneopts = "UT" + revision = "bc0163bde8aac788dd03c31d2879a55b49e226d2" + version = "v1.1.1" + [[projects]] digest = "1:ffe9824d294da03b391f44e1ae8281281b4afc1bdaa9588c9097785e3af10cec" name = "github.com/davecgh/go-spew" @@ -40,6 +48,7 @@ analyzer-name = "dep" analyzer-version = 1 input-imports = [ + "github.com/dasrick/go-teams-notify", "github.com/stretchr/testify/assert", "github.com/stretchr/testify/mock", ] diff --git a/mocks/API.go b/mocks/API.go index 5a54f0b..a3736f7 100644 --- a/mocks/API.go +++ b/mocks/API.go @@ -2,8 +2,10 @@ package mocks -import goteamsnotify "go-teams-notify" -import mock "github.com/stretchr/testify/mock" +import ( + goteamsnotify "github.com/dasrick/go-teams-notify" + mock "github.com/stretchr/testify/mock" +) // API is an autogenerated mock type for the API type type API struct {