-
Notifications
You must be signed in to change notification settings - Fork 1
/
magento2_test.go
70 lines (60 loc) · 2.21 KB
/
magento2_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
package gocommerce
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
var m2store = Magento2{
basePlatform{
"Magento 2",
"app/etc/env.php",
"app/etc/env.php",
},
"n98-magerun2",
}
func TestM2ConfigSimpleDB(t *testing.T) {
cfg, err := m2store.ParseConfig(fixtureBase + "magento2/app/etc/env.php")
assert.NoError(t, err)
assert.Equal(t, "app:sldfjlskdfklds@tcp(localhost:3306)/magento2?allowOldPasswords=true", cfg.DB.DSN())
assert.Equal(t, "admin_c6018w", cfg.AdminSlug)
}
func TestVariousM2Configs(t *testing.T) {
tests := []struct{ path, want string }{
{"crash1.php", "xx:xx@tcp(localhost:3306)/xx?allowOldPasswords=true"},
{"crash2.php", "xx:xx@tcp(10.10.20.39:3306)/xx?allowOldPasswords=true"},
{"crash3.php", "myuser:mypass@tcp(myhost:3306)/mydb?allowOldPasswords=true"},
{"hostport.php", "gooduser:verylongpassword@tcp(goodhost:3309)/gooddb?allowOldPasswords=true"},
{"multidb.php", "gooduser:goodpass@tcp(goodhost:3306)/gooddb?allowOldPasswords=true"},
{"simple.php", "gooduser:verylongpassword@tcp(goodhost:3306)/gooddb?allowOldPasswords=true"},
}
for _, test := range tests {
cfg, err := m2store.ParseConfig(fixtureBase + "magento2/app/etc/" + test.path)
assert.NoError(t, err)
assert.Equal(t, test.want, cfg.DB.DSN())
}
}
func TestEmptyConfig(t *testing.T) {
cfg, err := m2store.ParseConfig(fixtureBase + "magento2/app/etc/empty.php")
assert.Error(t, err)
assert.Nil(t, cfg)
}
func TestGetMagentoVersionFromLockFile(t *testing.T) {
version, err := m2store.Version(fixtureBase + "magento2")
assert.Nil(t, err)
assert.Equal(t, "2.4.2-p2", version)
}
func TestGetMagentoVersionWithoutLockFile(t *testing.T) {
version, err := m2store.Version(fixtureBase + "magento2_no_lockfile")
assert.Nil(t, err)
assert.Equal(t, "2.4.2-p2", version)
}
func TestGetMagentoVersionWithoutSystemPackages(t *testing.T) {
version, err := m2store.Version(fixtureBase + "magento2_git_clone")
assert.Nil(t, err)
assert.Equal(t, "2.4.2-p2", version)
}
func TestGetMagentoBaseURLsFromConfigNilCtx(t *testing.T) {
baseURLs, err := m2store.BaseURLs(context.TODO(), fixtureBase+"magento2")
assert.Nil(t, err)
assert.ElementsMatch(t, []string{"https://sansec.io/", "https://api.sansec.io/"}, baseURLs)
}