|
| 1 | +package app_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + "time" |
| 6 | + |
| 7 | + "github.com/stretchr/testify/assert" |
| 8 | + "github.com/stretchr/testify/require" |
| 9 | + |
| 10 | + app "github.com/alexandear/import-gitlab-commits/internal" |
| 11 | +) |
| 12 | + |
| 13 | +func TestNewCommit(t *testing.T) { |
| 14 | + committedAt, err := time.Parse(time.RFC3339, "2021-08-01T12:00:00Z") |
| 15 | + if err != nil { |
| 16 | + t.Fatal(err) |
| 17 | + } |
| 18 | + |
| 19 | + projectID := 2323 |
| 20 | + hash := "9bc457f81c86307f28662b40a164105f14df64e3" |
| 21 | + |
| 22 | + commit := app.NewCommit(committedAt, projectID, hash) |
| 23 | + |
| 24 | + assert.Equal(t, &app.Commit{ |
| 25 | + CommittedAt: committedAt, |
| 26 | + Message: "Project: 2323 commit: 9bc457f81c86307f28662b40a164105f14df64e3", |
| 27 | + }, commit) |
| 28 | +} |
| 29 | + |
| 30 | +func TestParseCommitMessage(t *testing.T) { |
| 31 | + t.Run("valid", func(t *testing.T) { |
| 32 | + msg := "Project: 2323 commit: 9bc457f81c86307f28662b40a164105f14df64e3" |
| 33 | + projectID, hash, err := app.ParseCommitMessage(msg) |
| 34 | + |
| 35 | + require.NoError(t, err) |
| 36 | + assert.Equal(t, 2323, projectID) |
| 37 | + assert.Equal(t, "9bc457f81c86307f28662b40a164105f14df64e3", hash) |
| 38 | + }) |
| 39 | + |
| 40 | + t.Run("wrong project id", func(t *testing.T) { |
| 41 | + msg := "Project: PROJ commit: 9bc457f81c86307f28662b40a164105f14df64e3" |
| 42 | + _, _, err := app.ParseCommitMessage(msg) |
| 43 | + |
| 44 | + assert.Error(t, err) |
| 45 | + }) |
| 46 | +} |
0 commit comments