github.com/greenpau/go-authcrunch@v1.1.4/pkg/messaging/file_send_test.go (about) 1 // Copyright 2022 Paul Greenberg greenpau@outlook.com 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package messaging 16 17 import ( 18 "github.com/google/go-cmp/cmp" 19 "github.com/greenpau/go-authcrunch/internal/tests" 20 "testing" 21 ) 22 23 func TestFileProviderSend(t *testing.T) { 24 tmpDir, err := tests.TempDir("TestFileProviderSend") 25 if err != nil { 26 t.Fatal(err) 27 } 28 29 tmpDir += "/inbox" 30 // t.Logf("Temp dir: %s", tmpDir) 31 32 testcases := []struct { 33 name string 34 provider *FileProvider 35 want string 36 shouldErr bool 37 err error 38 }{ 39 { 40 name: "test sending notification", 41 provider: &FileProvider{ 42 Name: "default", 43 RootDir: tmpDir, 44 }, 45 }, 46 } 47 for _, tc := range testcases { 48 t.Run(tc.name, func(t *testing.T) { 49 err := tc.provider.Validate() 50 if err != nil { 51 t.Fatalf("unexpected validation error: %v", err) 52 } 53 54 err = tc.provider.Send(&FileProviderSendInput{ 55 Subject: "foo", 56 Body: "foobar", 57 Recipients: []string{"root@localhost"}, 58 }) 59 60 if err != nil { 61 if !tc.shouldErr { 62 t.Fatalf("expected success, got: %v", err) 63 } 64 if diff := cmp.Diff(err.Error(), tc.err.Error()); diff != "" { 65 t.Fatalf("unexpected error: %v, want: %v", err, tc.err) 66 } 67 return 68 } 69 if tc.shouldErr { 70 t.Fatalf("unexpected success, want: %v", tc.err) 71 } 72 }) 73 } 74 }