tests: test also clone step

Also test clone step so we are sure that the clone url is correct.
This commit is contained in:
Simone Gotti 2019-08-05 11:10:30 +02:00
parent 1c96b5fbff
commit c17772040b
3 changed files with 48 additions and 36 deletions

View File

@ -15,7 +15,7 @@ local dind_runtime(arch) = {
{ {
image: 'docker:stable-dind', image: 'docker:stable-dind',
privileged: true, privileged: true,
entrypoint: 'dockerd', entrypoint: 'dockerd --bip 172.18.0.1/16',
}, },
], ],
}; };
@ -92,7 +92,7 @@ local task_build_docker_tests(version, arch) = {
|||, |||,
}, },
{ type: 'restore_workspace', dest_dir: '.' }, { type: 'restore_workspace', dest_dir: '.' },
{ type: 'run', name: 'integration tests', command: 'AGOLA_TOOLBOX_PATH="./bin" GITEA_PATH=${PWD}/bin/gitea ./bin/integration-tests -test.parallel 1 -test.v' }, { type: 'run', name: 'integration tests', command: 'AGOLA_TOOLBOX_PATH="./bin" GITEA_PATH=${PWD}/bin/gitea DOCKER_BRIDGE_ADDRESS="172.18.0.1" ./bin/integration-tests -test.parallel 1 -test.v' },
], ],
depends: [ depends: [
'build go 1.12 amd64', 'build go 1.12 amd64',

View File

@ -360,9 +360,9 @@ TEMP_PATH = {{ .Data }}/gitea/uploads
[server] [server]
APP_DATA_PATH = {{ .Data }}/gitea APP_DATA_PATH = {{ .Data }}/gitea
SSH_DOMAIN = {{ .ListenAddress }} SSH_DOMAIN = {{ .SSHListenAddress }}
HTTP_PORT = {{ .HTTPPort }} HTTP_PORT = {{ .HTTPPort }}
ROOT_URL = http://{{ .ListenAddress }}:{{ .HTTPPort }}/ ROOT_URL = http://{{ .HTTPListenAddress }}:{{ .HTTPPort }}/
DISABLE_SSH = false DISABLE_SSH = false
# Use built-in ssh server # Use built-in ssh server
START_SSH_SERVER = true START_SSH_SERVER = true
@ -434,8 +434,9 @@ ENABLE_OPENID_SIGNUP = true
type GiteaConfig struct { type GiteaConfig struct {
Data string Data string
User string User string
ListenAddress string HTTPListenAddress string
HTTPPort string HTTPPort string
SSHListenAddress string
SSHPort string SSHPort string
} }
@ -444,12 +445,13 @@ type TestGitea struct {
GiteaPath string GiteaPath string
ConfigPath string ConfigPath string
ListenAddress string HTTPListenAddress string
HTTPPort string HTTPPort string
SSHListenAddress string
SSHPort string SSHPort string
} }
func NewTestGitea(t *testing.T, logger *zap.Logger, dir string, a ...string) (*TestGitea, error) { func NewTestGitea(t *testing.T, logger *zap.Logger, dir, dockerBridgeAddress string, a ...string) (*TestGitea, error) {
u := uuid.NewV4() u := uuid.NewV4()
uid := fmt.Sprintf("%x", u[:4]) uid := fmt.Sprintf("%x", u[:4])
@ -477,7 +479,8 @@ func NewTestGitea(t *testing.T, logger *zap.Logger, dir string, a ...string) (*T
giteaConfig := &GiteaConfig{ giteaConfig := &GiteaConfig{
Data: giteaDir, Data: giteaDir,
User: curUser.Username, User: curUser.Username,
ListenAddress: listenAddress, HTTPListenAddress: listenAddress,
SSHListenAddress: dockerBridgeAddress,
HTTPPort: httpPort, HTTPPort: httpPort,
SSHPort: sshPort, SSHPort: sshPort,
} }
@ -514,8 +517,9 @@ func NewTestGitea(t *testing.T, logger *zap.Logger, dir string, a ...string) (*T
}, },
GiteaPath: giteaPath, GiteaPath: giteaPath,
ConfigPath: configPath, ConfigPath: configPath,
ListenAddress: listenAddress, HTTPListenAddress: listenAddress,
HTTPPort: httpPort, HTTPPort: httpPort,
SSHListenAddress: dockerBridgeAddress,
SSHPort: sshPort, SSHPort: sshPort,
} }

View File

@ -81,8 +81,8 @@ func shutdownEtcd(tetcd *testutil.TestEmbeddedEtcd) {
} }
} }
func setupGitea(t *testing.T, dir string) *testutil.TestGitea { func setupGitea(t *testing.T, dir, dockerBridgeAddress string) *testutil.TestGitea {
tgitea, err := testutil.NewTestGitea(t, logger, dir) tgitea, err := testutil.NewTestGitea(t, logger, dir, dockerBridgeAddress)
if err != nil { if err != nil {
t.Fatalf("unexpected err: %v", err) t.Fatalf("unexpected err: %v", err)
} }
@ -156,6 +156,10 @@ func startAgola(ctx context.Context, t *testing.T, dir string, c *config.Config)
} }
func setup(ctx context.Context, t *testing.T, dir string) (*testutil.TestEmbeddedEtcd, *testutil.TestGitea, *config.Config) { func setup(ctx context.Context, t *testing.T, dir string) (*testutil.TestEmbeddedEtcd, *testutil.TestGitea, *config.Config) {
dockerBridgeAddress := os.Getenv("DOCKER_BRIDGE_ADDRESS")
if dockerBridgeAddress == "" {
dockerBridgeAddress = "172.17.0.1"
}
toolboxPath := os.Getenv("AGOLA_TOOLBOX_PATH") toolboxPath := os.Getenv("AGOLA_TOOLBOX_PATH")
if toolboxPath == "" { if toolboxPath == "" {
t.Fatalf("env var AGOLA_TOOLBOX_PATH is undefined") t.Fatalf("env var AGOLA_TOOLBOX_PATH is undefined")
@ -253,7 +257,7 @@ func setup(ctx context.Context, t *testing.T, dir string) (*testutil.TestEmbedde
}, },
} }
tgitea := setupGitea(t, dir) tgitea := setupGitea(t, dir, dockerBridgeAddress)
etcdDir := filepath.Join(dir, "etcd") etcdDir := filepath.Join(dir, "etcd")
tetcd := setupEtcd(t, etcdDir) tetcd := setupEtcd(t, etcdDir)
@ -282,16 +286,16 @@ func setup(ctx context.Context, t *testing.T, dir string) (*testutil.TestEmbedde
t.Fatalf("unexpected err: %v", err) t.Fatalf("unexpected err: %v", err)
} }
gwURL := fmt.Sprintf("http://%s:%s", listenAddress, gwPort) gwURL := fmt.Sprintf("http://%s:%s", dockerBridgeAddress, gwPort)
csURL := fmt.Sprintf("http://%s:%s", listenAddress, csPort) csURL := fmt.Sprintf("http://%s:%s", listenAddress, csPort)
rsURL := fmt.Sprintf("http://%s:%s", listenAddress, rsPort) rsURL := fmt.Sprintf("http://%s:%s", listenAddress, rsPort)
gitServerURL := fmt.Sprintf("http://%s:%s", listenAddress, gitServerPort) gitServerURL := fmt.Sprintf("http://%s:%s", dockerBridgeAddress, gitServerPort)
c.Gateway.Web.ListenAddress = fmt.Sprintf("%s:%s", listenAddress, gwPort) c.Gateway.Web.ListenAddress = fmt.Sprintf("%s:%s", dockerBridgeAddress, gwPort)
c.Configstore.Web.ListenAddress = fmt.Sprintf("%s:%s", listenAddress, csPort) c.Configstore.Web.ListenAddress = fmt.Sprintf("%s:%s", listenAddress, csPort)
c.Runservice.Web.ListenAddress = fmt.Sprintf("%s:%s", listenAddress, rsPort) c.Runservice.Web.ListenAddress = fmt.Sprintf("%s:%s", listenAddress, rsPort)
c.Executor.Web.ListenAddress = fmt.Sprintf("%s:%s", listenAddress, exPort) c.Executor.Web.ListenAddress = fmt.Sprintf("%s:%s", listenAddress, exPort)
c.Gitserver.Web.ListenAddress = fmt.Sprintf("%s:%s", listenAddress, gitServerPort) c.Gitserver.Web.ListenAddress = fmt.Sprintf("%s:%s", dockerBridgeAddress, gitServerPort)
c.Gateway.APIExposedURL = gwURL c.Gateway.APIExposedURL = gwURL
c.Gateway.WebExposedURL = gwURL c.Gateway.WebExposedURL = gwURL
@ -339,7 +343,7 @@ func TestCreateLinkedAccount(t *testing.T) {
} }
func createLinkedAccount(ctx context.Context, t *testing.T, tgitea *testutil.TestGitea, c *config.Config) (string, string) { func createLinkedAccount(ctx context.Context, t *testing.T, tgitea *testutil.TestGitea, c *config.Config) (string, string) {
giteaAPIURL := fmt.Sprintf("http://%s:%s", tgitea.ListenAddress, tgitea.HTTPPort) giteaAPIURL := fmt.Sprintf("http://%s:%s", tgitea.HTTPListenAddress, tgitea.HTTPPort)
giteaClient := gitea.NewClient(giteaAPIURL, "") giteaClient := gitea.NewClient(giteaAPIURL, "")
giteaToken, err := giteaClient.CreateAccessToken(giteaUser01, "password", gtypes.CreateAccessTokenOption{Name: "token01"}) giteaToken, err := giteaClient.CreateAccessToken(giteaUser01, "password", gtypes.CreateAccessTokenOption{Name: "token01"})
@ -403,7 +407,7 @@ func TestCreateProject(t *testing.T) {
defer shutdownGitea(tgitea) defer shutdownGitea(tgitea)
defer shutdownEtcd(tetcd) defer shutdownEtcd(tetcd)
giteaAPIURL := fmt.Sprintf("http://%s:%s", tgitea.ListenAddress, tgitea.HTTPPort) giteaAPIURL := fmt.Sprintf("http://%s:%s", tgitea.HTTPListenAddress, tgitea.HTTPPort)
giteaToken, token := createLinkedAccount(ctx, t, tgitea, c) giteaToken, token := createLinkedAccount(ctx, t, tgitea, c)
@ -450,7 +454,7 @@ func TestRun(t *testing.T) {
defer shutdownGitea(tgitea) defer shutdownGitea(tgitea)
defer shutdownEtcd(tetcd) defer shutdownEtcd(tetcd)
giteaAPIURL := fmt.Sprintf("http://%s:%s", tgitea.ListenAddress, tgitea.HTTPPort) giteaAPIURL := fmt.Sprintf("http://%s:%s", tgitea.HTTPListenAddress, tgitea.HTTPPort)
giteaToken, token := createLinkedAccount(ctx, t, tgitea, c) giteaToken, token := createLinkedAccount(ctx, t, tgitea, c)
@ -475,11 +479,12 @@ func TestRun(t *testing.T) {
runtime: { runtime: {
containers: [ containers: [
{ {
image: 'busybox', image: 'alpine/git',
}, },
], ],
}, },
steps: [ steps: [
{ type: 'clone' },
{ type: 'run', command: 'env' }, { type: 'run', command: 'env' },
], ],
}, },
@ -551,4 +556,7 @@ func TestRun(t *testing.T) {
if run.Phase != rstypes.RunPhaseFinished { if run.Phase != rstypes.RunPhaseFinished {
t.Fatalf("expected run phase %q, got %q", rstypes.RunPhaseFinished, run.Phase) t.Fatalf("expected run phase %q, got %q", rstypes.RunPhaseFinished, run.Phase)
} }
if run.Result != rstypes.RunResultSuccess {
t.Fatalf("expected run result %q, got %q", rstypes.RunResultSuccess, run.Result)
}
} }