-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
75 lines (70 loc) · 2.23 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"encoding/base64"
"io/fs"
"os"
"testing"
"ariga.io/atlas-sync-action/internal/atlascloud"
"ariga.io/atlas/sql/migrate"
"github.com/sethvargo/go-githubactions"
"github.com/stretchr/testify/require"
)
func TestArchive(t *testing.T) {
arc, err := Archive("internal/testdata/basic/migrations", atlascloud.DirFormatAtlas)
require.NoError(t, err)
exp, err := os.ReadFile("internal/testdata/basic/atlas_archive.tar.b64")
require.NoError(t, err)
require.EqualValues(t, string(exp), arc)
// Test backwards compatability.
bc, err := os.ReadFile("internal/testdata/basic/bc.tar.b64")
require.NoError(t, err)
dec, err := base64.StdEncoding.DecodeString(string(bc))
require.NoError(t, err)
dir, err := migrate.UnarchiveDir(dec)
require.NoError(t, err)
for _, name := range []string{migrate.HashFileName, "20230201094614.sql"} {
ex, err := os.ReadFile("internal/testdata/basic/migrations/" + name)
require.NoError(t, err)
ac, err := fs.ReadFile(dir, name)
require.NoError(t, err)
require.Equal(t, ex, ac)
}
}
func TestInput(t *testing.T) {
for _, tc := range []struct {
db string
driver atlascloud.Driver
}{
{"mysql", atlascloud.DriverMysql},
{"maria", atlascloud.DriverMariadb},
{"postgres", atlascloud.DriverPostgresql},
{"sqlite", atlascloud.DriverSqlite},
} {
t.Run(tc.db, func(t *testing.T) {
env := map[string]string{
"GITHUB_REPOSITORY": "ariga/test",
"GITHUB_SHA": "1234567890",
"INPUT_DIR": "migrations/",
"INPUT_DRIVER": tc.db,
"INPUT_DIR-FORMAT": "flyway",
"GITHUB_REF_NAME": "master",
"GITHUB_EVENT_PATH": "internal/testdata/push_event.json",
}
act := githubactions.New(githubactions.WithGetenv(func(key string) string {
return env[key]
}))
input, err := Input(act)
require.NoError(t, err)
require.EqualValues(t, atlascloud.ReportDirInput{
Repo: "ariga/test",
Commit: "1234567890",
Branch: "master",
Path: "migrations/",
Driver: tc.driver,
Url: "https://github.com/ariga/atlas-sync-action/commit/4a3f0bcb6dff19078393728f1b69d89d853771eb",
DirFormat: atlascloud.DirFormatFlyway,
ArchiveFormat: atlascloud.ArchiveFormatB64Tar,
}, input)
})
}
}