corso/src/pkg/fault/alert_test.go
Abin Simon 68256cf59f
Change printing of backup stats to single line (#4526)
Previously we were printing a table for a single item which, for one
was unnecessary, but this also make the output of a backup more
compact.

Before:

```
Logging to file: /home/meain/.cache/corso/logs/2023-10-20T10-21-23Z.log
Connecting to M365                               done
Connecting to repository                      1s done

Backing Up ∙ Teams Testing (meain)
Discovering items to backup                  27s done
    Libraries (TeamsTestingmeain)                  done (found 0 items)
    Libraries (TeamsTestingmeain-Shared0)          done (found 0 items)
    Libraries (TeamsTestingmeain-Private2)         done (found 0 items)
    Messages                                    7s done (found 6 channels)
Backing up data                               7s done
Backup complete ∙ 7b40dd40-f808-4d57-8e39-b4553e48dc5d
    ID                                    Bytes Uploaded  Items Uploaded  Items Skipped  Errors
    7b40dd40-f808-4d57-8e39-b4553e48dc5d  0 B             0               0              0

Completed Backups:
    ID                                    Started At            Duration       Status     Resource Owner
    7b40dd40-f808-4d57-8e39-b4553e48dc5d  2023-10-20T10:21:32Z  36.632747912s  Completed  Teams Testing (meain)
```

After:
```
Connecting to M365                               done
Connecting to repository                      1s done

Backing Up ∙ Teams Testing (meain)
Discovering items to backup                  31s done
    Libraries (TeamsTestingmeain)                  done (found 0 items)
    Libraries (TeamsTestingmeain-Shared0)          done (found 0 items)
    Libraries (TeamsTestingmeain-Private2)         done (found 0 items)
    Messages                                    9s done (found 6 channels)
Backing up data                               7s done
Backup complete ∙ ffb2f619-1cb7-4a11-b3e2-7300aa513c6a
Bytes Uploaded: 0 B | Items Uploaded: 0 | Items Skipped: 0 | Errors: 0

Completed Backups:
    ID                                    ID                    Started At     Duration   Status                 Resource Owner
    ffb2f619-1cb7-4a11-b3e2-7300aa513c6a  2023-10-20T10:23:35Z  40.096203016s  Completed  Teams Testing (meain)
```


---

#### Does this PR need a docs update or release note?

- [x]  Yes, it's included
- [ ] 🕐 Yes, but in a later PR
- [ ]  No

#### Type of change

<!--- Please check the type of change your PR introduces: --->
- [x] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Supportability/Tests
- [ ] 💻 CI/Deployment
- [ ] 🧹 Tech Debt/Cleanup

#### Issue(s)

<!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. -->
* #<issue>

#### Test Plan

<!-- How will this be tested prior to merging.-->
- [ ] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
2023-11-16 12:43:27 +00:00

92 lines
2.0 KiB
Go

package fault_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/alcionai/corso/src/internal/tester"
"github.com/alcionai/corso/src/pkg/fault"
)
type AlertUnitSuite struct {
tester.Suite
}
func TestAlertUnitSuite(t *testing.T) {
suite.Run(t, &AlertUnitSuite{Suite: tester.NewUnitSuite(t)})
}
func (suite *AlertUnitSuite) TestAlert_String() {
var (
t = suite.T()
a fault.Alert
)
assert.Contains(t, a.String(), "Alert: <missing>")
a = fault.Alert{
Item: fault.Item{},
Message: "",
}
assert.Contains(t, a.String(), "Alert: <missing>")
a = fault.Alert{
Item: fault.Item{
ID: "item_id",
},
Message: "msg",
}
assert.NotContains(t, a.String(), "item_id")
assert.Contains(t, a.String(), "Alert: msg")
}
func (suite *AlertUnitSuite) TestNewAlert() {
t := suite.T()
addtl := map[string]any{"foo": "bar"}
a := fault.NewAlert("message-to-show", "ns", "item_id", "item_name", addtl)
expect := fault.Alert{
Item: fault.Item{
Namespace: "ns",
ID: "item_id",
Name: "item_name",
Additional: addtl,
},
Message: "message-to-show",
}
assert.Equal(t, expect, *a)
}
func (suite *AlertUnitSuite) TestAlert_HeadersValues() {
addtl := map[string]any{
fault.AddtlContainerID: "cid",
fault.AddtlContainerName: "cname",
}
table := []struct {
name string
alert *fault.Alert
expect []string
}{
{
name: "new alert",
alert: fault.NewAlert("message-to-show", "ns", "id", "name", addtl),
expect: []string{"Alert", "message-to-show", "cname", "name", "id"},
},
}
for _, test := range table {
suite.Run(test.name, func() {
t := suite.T()
assert.Equal(t, []string{"Action", "Message", "Container", "Name", "ID"}, test.alert.Headers(false))
assert.Equal(t, test.expect, test.alert.Values(false))
assert.Equal(t, []string{"Action", "Message", "Container", "Name", "ID"}, test.alert.Headers(true))
assert.Equal(t, test.expect, test.alert.Values(true))
})
}
}