Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port testinstall to docker+go #1603

Merged
merged 2 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ test-e2e-compatibility:
tags: [go]
script: go run mage.go -v TestE2ECompatibility

test-install-script:
stage: test
tags: [go,high_performance]
script: go run mage.go -v TestInstallScript
only:
- master

create-bucket:
stage: pre-release
tags: [go]
Expand Down
30 changes: 30 additions & 0 deletions ci/test/testinstall/Dockerfile.debian-buster
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM debian:buster

ENV container docker
ENV LC_ALL C
ENV DEBIAN_FRONTEND noninteractive

RUN apt update \
&& apt install -y systemd \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN rm -f /lib/systemd/system/multi-user.target.wants/* \
/etc/systemd/system/*.wants/* \
/lib/systemd/system/local-fs.target.wants/* \
/lib/systemd/system/sockets.target.wants/*udev* \
/lib/systemd/system/sockets.target.wants/*initctl* \
/lib/systemd/system/sysinit.target.wants/systemd-tmpfiles-setup* \
/lib/systemd/system/systemd-update-utmp*

# https://github.com/moby/moby/issues/1297
RUN echo resolvconf resolvconf/linkify-resolvconf boolean false | debconf-set-selections

RUN apt update \
&& apt install -y \
sudo \
curl

VOLUME ["/sys/fs/cgroup"]

CMD ["/lib/systemd/systemd"]
30 changes: 30 additions & 0 deletions ci/test/testinstall/Dockerfile.debian-stretch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM debian:stretch

ENV container docker
ENV LC_ALL C
ENV DEBIAN_FRONTEND noninteractive

RUN apt update \
&& apt install -y systemd \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN rm -f /lib/systemd/system/multi-user.target.wants/* \
/etc/systemd/system/*.wants/* \
/lib/systemd/system/local-fs.target.wants/* \
/lib/systemd/system/sockets.target.wants/*udev* \
/lib/systemd/system/sockets.target.wants/*initctl* \
/lib/systemd/system/sysinit.target.wants/systemd-tmpfiles-setup* \
/lib/systemd/system/systemd-update-utmp*

# https://github.com/moby/moby/issues/1297
RUN echo resolvconf resolvconf/linkify-resolvconf boolean false | debconf-set-selections

RUN apt update \
&& apt install -y \
sudo \
curl

VOLUME ["/sys/fs/cgroup"]

CMD ["/lib/systemd/systemd"]
37 changes: 37 additions & 0 deletions ci/test/testinstall/Dockerfile.ubuntu-bionic
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM ubuntu:18.04

ENV container docker
ENV LC_ALL C
ENV DEBIAN_FRONTEND noninteractive

RUN sed -i 's/# deb/deb/g' /etc/apt/sources.list

RUN apt update \
&& apt install -y systemd \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN cd /lib/systemd/system/sysinit.target.wants/ \
&& ls | grep -v systemd-tmpfiles-setup | xargs rm -f $1

RUN rm -f /lib/systemd/system/multi-user.target.wants/* \
/etc/systemd/system/*.wants/* \
/lib/systemd/system/local-fs.target.wants/* \
/lib/systemd/system/sockets.target.wants/*udev* \
/lib/systemd/system/sockets.target.wants/*initctl* \
/lib/systemd/system/basic.target.wants/* \
/lib/systemd/system/anaconda.target.wants/* \
/lib/systemd/system/plymouth* \
/lib/systemd/system/systemd-update-utmp*

# https://github.com/moby/moby/issues/1297
RUN echo resolvconf resolvconf/linkify-resolvconf boolean false | debconf-set-selections

RUN apt update \
&& apt install -y \
sudo \
curl

VOLUME ["/sys/fs/cgroup"]

CMD ["/lib/systemd/systemd"]
37 changes: 37 additions & 0 deletions ci/test/testinstall/Dockerfile.ubuntu-xenial
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM ubuntu:16.04

ENV container docker
ENV LC_ALL C
ENV DEBIAN_FRONTEND noninteractive

RUN sed -i 's/# deb/deb/g' /etc/apt/sources.list

RUN apt update \
&& apt install -y systemd \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN cd /lib/systemd/system/sysinit.target.wants/ \
&& ls | grep -v systemd-tmpfiles-setup | xargs rm -f $1

RUN rm -f /lib/systemd/system/multi-user.target.wants/* \
/etc/systemd/system/*.wants/* \
/lib/systemd/system/local-fs.target.wants/* \
/lib/systemd/system/sockets.target.wants/*udev* \
/lib/systemd/system/sockets.target.wants/*initctl* \
/lib/systemd/system/basic.target.wants/* \
/lib/systemd/system/anaconda.target.wants/* \
/lib/systemd/system/plymouth* \
/lib/systemd/system/systemd-update-utmp*

# https://github.com/moby/moby/issues/1297
RUN echo resolvconf resolvconf/linkify-resolvconf boolean false | debconf-set-selections

RUN apt update \
&& apt install -y \
sudo \
curl

VOLUME ["/sys/fs/cgroup"]

CMD ["/lib/systemd/systemd"]
27 changes: 27 additions & 0 deletions ci/test/testinstall/install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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 testinstall

import (
"github.com/magefile/mage/sh"
)

// TestInstallScript tests install.sh
func TestInstallScript() error {
return sh.RunV("go", "test", "-v", "-tags=integration", "github.com/mysteriumnetwork/node/ci/test/testinstall")
tadaskay marked this conversation as resolved.
Show resolved Hide resolved
}
133 changes: 133 additions & 0 deletions ci/test/testinstall/install_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// +build integration

/*
* 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 testinstall

import (
"bufio"
"encoding/json"
"fmt"
"strings"
"testing"
"time"

"github.com/magefile/mage/sh"
"github.com/stretchr/testify/assert"
)

const (
installURL = "https://raw.githubusercontent.com/mysteriumnetwork/node/master/install.sh"
installFile = "install.sh"
)

// TestInstall tests installation on various Linux distributions.
// SystemD docker images based on https://github.com/j8r/dockerfiles
// Installs myst using install.sh, tests for healthcheck output.
func TestInstall(t *testing.T) {
t.Parallel()

images := []string{
"debian-buster",
"debian-stretch",
"ubuntu-bionic",
"ubuntu-xenial",
}
for _, img := range images {
t.Run(img, func(t *testing.T) {
testImage(t, img)
})
}
}

func testImage(t *testing.T, image string) {
assert := assert.New(t)
failIf := failIfFunc(t)

buildOutput, err := sh.Output("docker", "build",
"-f", "Dockerfile."+image,
"-t", "testinstall_"+image,
".",
)
failIf(err)

var imageId string
scanner := bufio.NewScanner(strings.NewReader(buildOutput))
for scanner.Scan() {
line := scanner.Text()
fmt.Println(line)
if strings.HasPrefix(line, "Successfully built") {
fields := strings.Fields(line)
imageId = fields[len(fields)-1]
}
}
failIf(scanner.Err())
assert.NotEmpty(imageId)

runOutput, err := sh.Output("docker", "run",
"-d", "--privileged",
"-v", "/sys/fs/cgroup:/sys/fs/cgroup:ro",
imageId,
)
failIf(err)

var containerId string
scanner = bufio.NewScanner(strings.NewReader(runOutput))
for scanner.Scan() {
line := scanner.Text()
fmt.Println(line)
containerId = strings.TrimSpace(line)[0:12]
}
defer func() {
tadaskay marked this conversation as resolved.
Show resolved Hide resolved
_ = sh.RunV("docker", "kill", containerId)
}()
failIf(scanner.Err())
assert.NotEmpty(containerId)

err = sh.RunV("docker", "exec", containerId, "curl", "-o", installFile, installURL)
failIf(err)
err = sh.RunV("docker", "exec", containerId, "bash", installFile)
failIf(err)

assert.Eventually(func() bool {
return tequilaIsHealthy(t, containerId)
}, 5*time.Second, 500*time.Millisecond)
}

func tequilaIsHealthy(t *testing.T, containerId string) bool {
var healthcheckOutput struct {
Uptime string `json:"uptime"`
}
healthcheckJSON, err := sh.Output("docker", "exec", containerId, "curl", "-s", "localhost:4050/healthcheck")
if err != nil {
return false
}
fmt.Println(healthcheckJSON)
err = json.Unmarshal([]byte(healthcheckJSON), &healthcheckOutput)
failIfFunc(t)(err)
assert.NotEmpty(t, healthcheckOutput.Uptime)
return true
}

func failIfFunc(t *testing.T) func(error) {
return func(err error) {
if err != nil {
assert.FailNow(t, "Fatal error occurred: "+err.Error())
}
}
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ require (
github.com/status-im/keycard-go v0.0.0-20191114114615-9d48af884d5b // indirect
github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570 // indirect
github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3 // indirect
github.com/stretchr/testify v1.4.0
github.com/stretchr/testify v1.4.1-0.20200130210847-518a1491c713
github.com/urfave/cli/v2 v2.1.1
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
Expand All @@ -73,5 +73,5 @@ require (
google.golang.org/appengine v1.6.5 // indirect
gopkg.in/src-d/go-git.v4 v4.13.1 // indirect
gopkg.in/urfave/cli.v1 v1.20.0 // indirect
gopkg.in/yaml.v2 v2.2.7 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
)
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -569,11 +569,14 @@ github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3 h1:njlZPzLwU639
github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3/go.mod h1:hpGUWaI9xL8pRQCTXQgocU38Qw1g0Us7n5PxxTwTCYU=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.4.1-0.20200130210847-518a1491c713 h1:6Ug34M4M9ccOd4tmc1tqLP6pHVbQNYi6HdE00T7wYjw=
github.com/stretchr/testify v1.4.1-0.20200130210847-518a1491c713/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d h1:gZZadD8H+fF+n9CmNhYL1Y0dJB+kLOmKd7FbPJLeGHs=
github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d/go.mod h1:9OrXJhf154huy1nPWmuSrkgjPUtUNhA+Zmy+6AESzuA=
Expand Down Expand Up @@ -837,6 +840,8 @@ gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
2 changes: 2 additions & 0 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import (
_ "github.com/mysteriumnetwork/node/ci/util/docker"
// mage:import
_ "github.com/mysteriumnetwork/node/localnet"
// mage:import
_ "github.com/mysteriumnetwork/node/ci/test/testinstall"
)

// GenerateEnvFile generates env file for further stages
Expand Down
9 changes: 4 additions & 5 deletions tequilapi/api_test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@ import (
"encoding/json"
"fmt"
"net/http"
"testing"

"github.com/stretchr/testify/assert"
)

type testClient struct {
t *testing.T
t assert.TestingT
baseURL string
}

// NewTestClient returns client for making test requests
func NewTestClient(t *testing.T, address string) *testClient {
func NewTestClient(t assert.TestingT, address string) *testClient {
return &testClient{
t,
fmt.Sprintf("http://%s", address),
Expand All @@ -47,12 +46,12 @@ func (tc *testClient) Get(path string) *http.Response {
return resp
}

func expectJSONStatus200(t *testing.T, resp *http.Response, httpStatus int) {
func expectJSONStatus200(t assert.TestingT, resp *http.Response, httpStatus int) {
assert.Equal(t, "application/json; charset=utf-8", resp.Header.Get("Content-type"))
assert.Equal(t, httpStatus, resp.StatusCode)
}

func parseResponseAsJSON(t *testing.T, resp *http.Response, v interface{}) {
func parseResponseAsJSON(t assert.TestingT, resp *http.Response, v interface{}) {
err := json.NewDecoder(resp.Body).Decode(v)
assert.Nil(t, err)
}