|
| 1 | +package unit |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/jsas4coding/utify" |
| 7 | +) |
| 8 | + |
| 9 | +func defaultOpts() *utify.Options { |
| 10 | + return utify.OptionsDefault() |
| 11 | +} |
| 12 | + |
| 13 | +func TestBasicOutputFunctions(t *testing.T) { |
| 14 | + tests := []struct { |
| 15 | + name string |
| 16 | + fn func(string, *utify.Options) |
| 17 | + }{ |
| 18 | + {"Success", utify.Success}, |
| 19 | + {"Error", utify.Error}, |
| 20 | + {"Warning", utify.Warning}, |
| 21 | + {"Info", utify.Info}, |
| 22 | + {"Debug", utify.Debug}, |
| 23 | + {"Critical", utify.Critical}, |
| 24 | + {"Delete", utify.Delete}, |
| 25 | + {"Update", utify.Update}, |
| 26 | + {"Install", utify.Install}, |
| 27 | + {"Upgrade", utify.Upgrade}, |
| 28 | + {"Edit", utify.Edit}, |
| 29 | + {"New", utify.New}, |
| 30 | + {"Download", utify.Download}, |
| 31 | + {"Upload", utify.Upload}, |
| 32 | + {"Sync", utify.Sync}, |
| 33 | + {"Search", utify.Search}, |
| 34 | + } |
| 35 | + |
| 36 | + for _, tt := range tests { |
| 37 | + t.Run(tt.name, func(t *testing.T) { |
| 38 | + tt.fn("Test message", defaultOpts()) |
| 39 | + }) |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +func TestFormattedOutputFunctions(t *testing.T) { |
| 44 | + tests := []struct { |
| 45 | + name string |
| 46 | + fn func(string, *utify.Options, ...any) |
| 47 | + }{ |
| 48 | + {"Successf", utify.Successf}, |
| 49 | + {"Errorf", utify.Errorf}, |
| 50 | + {"Warningf", utify.Warningf}, |
| 51 | + {"Infof", utify.Infof}, |
| 52 | + {"Debugf", utify.Debugf}, |
| 53 | + {"Criticalf", utify.Criticalf}, |
| 54 | + {"Deletef", utify.Deletef}, |
| 55 | + {"Updatef", utify.Updatef}, |
| 56 | + {"Installf", utify.Installf}, |
| 57 | + {"Upgradef", utify.Upgradef}, |
| 58 | + {"Editf", utify.Editf}, |
| 59 | + {"Newf", utify.Newf}, |
| 60 | + {"Downloadf", utify.Downloadf}, |
| 61 | + {"Uploadf", utify.Uploadf}, |
| 62 | + {"Syncf", utify.Syncf}, |
| 63 | + {"Searchf", utify.Searchf}, |
| 64 | + } |
| 65 | + |
| 66 | + for _, tt := range tests { |
| 67 | + t.Run(tt.name, func(t *testing.T) { |
| 68 | + tt.fn("Formatted %s", defaultOpts(), "message") |
| 69 | + }) |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +func TestGetFunctions(t *testing.T) { |
| 74 | + tests := []struct { |
| 75 | + name string |
| 76 | + fn func(string, *utify.Options) (string, error) |
| 77 | + }{ |
| 78 | + {"GetSuccess", utify.GetSuccess}, |
| 79 | + {"GetError", utify.GetError}, |
| 80 | + {"GetWarning", utify.GetWarning}, |
| 81 | + {"GetInfo", utify.GetInfo}, |
| 82 | + {"GetDebug", utify.GetDebug}, |
| 83 | + {"GetCritical", utify.GetCritical}, |
| 84 | + {"GetDelete", utify.GetDelete}, |
| 85 | + {"GetUpdate", utify.GetUpdate}, |
| 86 | + {"GetInstall", utify.GetInstall}, |
| 87 | + {"GetUpgrade", utify.GetUpgrade}, |
| 88 | + {"GetEdit", utify.GetEdit}, |
| 89 | + {"GetNew", utify.GetNew}, |
| 90 | + {"GetDownload", utify.GetDownload}, |
| 91 | + {"GetUpload", utify.GetUpload}, |
| 92 | + {"GetSync", utify.GetSync}, |
| 93 | + {"GetSearch", utify.GetSearch}, |
| 94 | + } |
| 95 | + |
| 96 | + for _, tt := range tests { |
| 97 | + t.Run(tt.name, func(t *testing.T) { |
| 98 | + _, err := tt.fn("Test message", defaultOpts()) |
| 99 | + if err != nil && err != utify.ErrSilent { |
| 100 | + t.Errorf("%s returned unexpected error: %v", tt.name, err) |
| 101 | + } |
| 102 | + }) |
| 103 | + } |
| 104 | +} |
| 105 | + |
| 106 | +func TestLogOnlyFunctions(t *testing.T) { |
| 107 | + tests := []struct { |
| 108 | + name string |
| 109 | + fn func(string) |
| 110 | + }{ |
| 111 | + {"LogSuccess", utify.LogSuccess}, |
| 112 | + {"LogError", utify.LogError}, |
| 113 | + {"LogWarning", utify.LogWarning}, |
| 114 | + {"LogInfo", utify.LogInfo}, |
| 115 | + {"LogDebug", utify.LogDebug}, |
| 116 | + {"LogCritical", utify.LogCritical}, |
| 117 | + {"LogDelete", utify.LogDelete}, |
| 118 | + {"LogUpdate", utify.LogUpdate}, |
| 119 | + {"LogInstall", utify.LogInstall}, |
| 120 | + {"LogUpgrade", utify.LogUpgrade}, |
| 121 | + {"LogEdit", utify.LogEdit}, |
| 122 | + {"LogNew", utify.LogNew}, |
| 123 | + {"LogDownload", utify.LogDownload}, |
| 124 | + {"LogUpload", utify.LogUpload}, |
| 125 | + {"LogSync", utify.LogSync}, |
| 126 | + {"LogSearch", utify.LogSearch}, |
| 127 | + } |
| 128 | + |
| 129 | + for _, tt := range tests { |
| 130 | + t.Run(tt.name, func(t *testing.T) { |
| 131 | + tt.fn("Log-only message") |
| 132 | + }) |
| 133 | + } |
| 134 | +} |
0 commit comments