-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Anton Litvinov <[email protected]>
- Loading branch information
Showing
9 changed files
with
226 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
version: '3.0' | ||
services: | ||
|
||
shaper-websvc: | ||
build: | ||
context: . | ||
dockerfile: ./e2e/shaper/websvc/Dockerfile | ||
cap_add: | ||
- NET_ADMIN | ||
working_dir: /node | ||
expose: | ||
- 8083 | ||
|
||
#go runner to run go programs inside localnet (usefull for contract deployment or e2e test running) | ||
go-runner: | ||
depends_on: | ||
- shaper-websvc | ||
build: | ||
context: . | ||
dockerfile: ./e2e/gorunner-shaper/Dockerfile.precompiled | ||
cap_add: | ||
- NET_ADMIN | ||
volumes: | ||
- ./e2e/blockchain/keystore:/node/keystore | ||
working_dir: /node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM golang:1.20-alpine | ||
|
||
RUN apk add --no-cache bash gcc musl-dev make linux-headers iptables ipset ca-certificates openvpn bash sudo openresolv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FROM alpine:3.12 | ||
|
||
RUN apk add --no-cache bash gcc musl-dev make linux-headers iptables ipset ca-certificates openvpn bash sudo openresolv | ||
RUN ln -s /sbin/iptables /usr/sbin/iptables | ||
|
||
COPY ./build/e2e/shaper.test /usr/local/bin/shaper.test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright (C) 2020 The "MysteriumNetwork/node" Authors. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package shaper | ||
|
||
import ( | ||
"github.com/magefile/mage/sh" | ||
"github.com/pkg/errors" | ||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
// NewRunner returns e2e test runners instance | ||
func NewRunner(composeFiles []string, testEnv, services string) (runner *Runner, cleanup func()) { | ||
fileArgs := make([]string, 0) | ||
for _, f := range composeFiles { | ||
fileArgs = append(fileArgs, "-f", f) | ||
} | ||
var args []string | ||
args = append(args, fileArgs...) | ||
args = append(args, "-p", testEnv) | ||
|
||
runner = &Runner{ | ||
compose: sh.RunCmd("docker", append([]string{"compose"}, args...)...), | ||
composeOut: sh.OutCmd("docker", append([]string{"compose"}, args...)...), | ||
testEnv: testEnv, | ||
services: services, | ||
} | ||
return runner, runner.cleanup | ||
} | ||
|
||
// Runner is e2e tests runner responsible for starting test environment and running e2e tests. | ||
type Runner struct { | ||
compose func(args ...string) error | ||
composeOut func(args ...string) (string, error) | ||
etherPassphrase string | ||
testEnv string | ||
services string | ||
} | ||
|
||
// Test starts given provider and consumer nodes and runs e2e tests. | ||
func (r *Runner) Test() (retErr error) { | ||
log.Info().Msg("Running tests for env: " + r.testEnv) | ||
|
||
err := r.compose("run", "go-runner", | ||
"/usr/local/bin/shaper.test", | ||
) | ||
|
||
retErr = errors.Wrap(err, "tests failed!") | ||
return | ||
} | ||
|
||
func (r *Runner) cleanup() { | ||
log.Info().Msg("Cleaning up") | ||
|
||
_ = r.compose("logs") | ||
if err := r.compose("down", "--volumes", "--remove-orphans", "--timeout", "30"); err != nil { | ||
log.Warn().Err(err).Msg("Cleanup error") | ||
} | ||
} | ||
|
||
// Init starts bug6022.test dependency | ||
func (r *Runner) Init() error { | ||
log.Info().Msg("Starting other services") | ||
if err := r.compose("pull"); err != nil { | ||
return errors.Wrap(err, "could not pull images") | ||
} | ||
|
||
if err := r.compose("up", "-d", "shaper-websvc"); err != nil { | ||
return errors.Wrap(err, "starting other services failed!") | ||
} | ||
|
||
log.Info().Msg("Building app images") | ||
if err := r.compose("build"); err != nil { | ||
return errors.Wrap(err, "building app images failed!") | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM alpine:3.12 | ||
|
||
COPY ./build/e2e/shaper.websvc /usr/local/bin/shaper.websvc | ||
|
||
ENTRYPOINT ["/usr/local/bin/shaper.websvc"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (C) 2024 The "MysteriumNetwork/node" Authors. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
func main() { | ||
http.HandleFunc("/", handler) | ||
http.ListenAndServe(":8083", nil) | ||
} | ||
|
||
func handler(w http.ResponseWriter, r *http.Request) { | ||
fmt.Println(r.URL.Path, r.RemoteAddr) | ||
fmt.Fprintf(w, "Hello, %s!", r.URL.Path[1:]) | ||
} |