github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/ci/test/e2e.go (about) 1 /* 2 * Copyright (C) 2019 The "MysteriumNetwork/node" Authors. 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 package test 19 20 import ( 21 "fmt" 22 "os" 23 24 "github.com/magefile/mage/mg" 25 "github.com/magefile/mage/sh" 26 "github.com/mysteriumnetwork/node/e2e" 27 "github.com/mysteriumnetwork/node/logconfig" 28 "github.com/rs/zerolog/log" 29 ) 30 31 var crossCompileFlags = map[string]string{ 32 "GOARCH": "amd64", 33 "GOOS": "linux", 34 "CGO_ENABLED": "0", 35 } 36 37 // BuildMystBinaryForE2eDocker builds myst binary for e2e tests. 38 func BuildMystBinaryForE2eDocker() error { 39 return sh.RunWith(crossCompileFlags, "go", "build", "-o", "./build/e2e/myst", "./cmd/mysterium_node/mysterium_node.go") 40 } 41 42 // BuildE2eTestBinary builds the e2e test binary. 43 func BuildE2eTestBinary() error { 44 err := sh.RunWith(crossCompileFlags, "go", "test", "-c", "./e2e/") 45 if err != nil { 46 return err 47 } 48 49 _ = os.Mkdir("./build/e2e/", os.ModeDir) 50 return os.Rename("./e2e.test", "./build/e2e/test") 51 } 52 53 // BuildE2eDeployerBinary builds the deployer binary for e2e tests. 54 func BuildE2eDeployerBinary() error { 55 return sh.RunWith(crossCompileFlags, "go", "build", "-o", "./build/e2e/deployer", "./e2e/blockchain/deployer.go") 56 } 57 58 // TestE2EBasic runs end-to-end tests 59 func TestE2EBasic() error { 60 logconfig.Bootstrap() 61 62 mg.Deps(BuildMystBinaryForE2eDocker, BuildE2eDeployerBinary) 63 64 // not running this in parallel as it does some package switching magic 65 mg.Deps(BuildE2eTestBinary) 66 67 composeFiles := []string{ 68 "./docker-compose.e2e-basic.yml", 69 } 70 runner, cleanup := e2e.NewRunner(composeFiles, "node_e2e_basic_test", "openvpn,noop,wireguard,hermes2") 71 defer cleanup() 72 if err := runner.Init(); err != nil { 73 return err 74 } 75 return runner.Test("myst-provider") 76 } 77 78 // TestE2ENAT runs end-to-end tests in NAT environment 79 func TestE2ENAT() error { 80 logconfig.Bootstrap() 81 82 mg.Deps(BuildMystBinaryForE2eDocker, BuildE2eTestBinary, BuildE2eDeployerBinary) 83 84 composeFiles := []string{ 85 "./docker-compose.e2e-traversal.yml", 86 } 87 runner, cleanup := e2e.NewRunner(composeFiles, "node_e2e_nat_test", "wireguard,openvpn,noop,hermes2") 88 defer cleanup() 89 if err := runner.Init(); err != nil { 90 return err 91 } 92 return runner.Test("myst-provider") 93 } 94 95 // TestE2ECompatibility runs end-to-end tests with older node version to make check compatibility 96 func TestE2ECompatibility() error { 97 logconfig.Bootstrap() 98 99 mg.Deps(BuildMystBinaryForE2eDocker, BuildE2eTestBinary, BuildE2eDeployerBinary) 100 101 composeFiles := []string{ 102 "./docker-compose.e2e-compatibility.yml", 103 } 104 runner, cleanup := e2e.NewRunner(composeFiles, "node_e2e_compatibility", "openvpn,noop,wireguard") 105 defer cleanup() 106 if err := runner.Init(); err != nil { 107 return err 108 } 109 110 tests := []struct { 111 provider, consumer string 112 }{ 113 {provider: "myst-provider", consumer: "myst-consumer-local"}, 114 {provider: "myst-provider-local", consumer: "myst-consumer"}, 115 } 116 117 for _, test := range tests { 118 log.Info().Msgf("Testing compatibility for %s and %s", test.provider, test.consumer) 119 120 if err := runner.Test(test.provider); err != nil { 121 return fmt.Errorf("compatibility test failed for %s and %s", test.provider, test.consumer) 122 } 123 } 124 return nil 125 }