Skip to content

Commit

Permalink
Add make integration-actions command (#1948)
Browse files Browse the repository at this point in the history
* Add make integration-actions command

Signed-off-by: Javier López Barba <javier@okteto.com>

* Integration test takes at most 15m

Signed-off-by: Javier López Barba <javier@okteto.com>

* Add 'OKTETO_SKIP_CTX_TEST' env var to skip context action test

Signed-off-by: Javier López Barba <javier@okteto.com>

* Rename skip context test env var

Signed-off-by: Javier López Barba <javier@okteto.com>

* Increase test time to 20 min

Signed-off-by: Javier López Barba <javier@okteto.com>

* Upgrade test times

Signed-off-by: Javier López Barba <javier@okteto.com>
  • Loading branch information
jLopezbarb committed Nov 5, 2021
1 parent cee2db3 commit 8d66bf3
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 94 deletions.
6 changes: 5 additions & 1 deletion Makefile
Expand Up @@ -40,7 +40,11 @@ test:

.PHONY: integration
integration:
go test github.com/okteto/okteto/integration -tags=integration --count=1 -v -timeout 45m
go test github.com/okteto/okteto/integration -tags="common integration actions" --count=1 -v -timeout 45m

.PHONY: integration-actions
integration-actions:
go test github.com/okteto/okteto/integration -tags="common actions" --count=1 -v -timeout 15m

.PHONY: build
build:
Expand Down
8 changes: 6 additions & 2 deletions integration/actions_test.go
@@ -1,5 +1,5 @@
//go:build integration
// +build integration
//go:build actions
// +build actions

// Copyright 2021 The Okteto Authors
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -205,6 +205,10 @@ func TestContextAction(t *testing.T) {
t.Skip("this test is not required for windows e2e tests")
return
}
if os.Getenv("OKTETO_SKIP_CONTEXT_TEST") != "" {
t.Skip("this test is not required because of 'OKTETO_SKIP_CONTEXT_TEST' env var")
return
}

ctx := context.Background()
var remove bool
Expand Down
22 changes: 0 additions & 22 deletions integration/stacks_test.go
Expand Up @@ -104,28 +104,6 @@ func TestStacks(t *testing.T) {
})
}

func cloneGitRepo(ctx context.Context, name string) error {
log.Printf("cloning git repo %s", name)
cmd := exec.Command("git", "clone", name)
o, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("cloning git repo %s failed: %s - %s", name, string(o), err)
}
log.Printf("clone git repo %s success", name)
return nil
}

func deleteGitRepo(ctx context.Context, path string) error {
log.Printf("delete git repo %s", path)
err := os.RemoveAll(path)
if err != nil {
return fmt.Errorf("delete git repo %s failed: %w", path, err)
}

log.Printf("deleted git repo %s", path)
return nil
}

func deployStack(ctx context.Context, oktetoPath, stackPath, dir string) error {
log.Printf("okteto stack deploy %s", stackPath)
cmd := exec.Command(oktetoPath, "stack", "deploy", "-f", stackPath, "--build", "--wait")
Expand Down
69 changes: 0 additions & 69 deletions integration/up_test.go
Expand Up @@ -57,15 +57,9 @@ var (
deploymentTemplate = template.Must(template.New("deployment").Parse(deploymentFormat))
statefulsetTemplate = template.Must(template.New("statefulset").Parse(statefulsetFormat))
manifestTemplate = template.Must(template.New("manifest").Parse(manifestFormat))
user = ""
kubectlBinary = "kubectl"
zero int64 = 0
)

type deployment struct {
Name string
}

const (
indexEndpoint = "http://localhost:8080/index.html"
varEndpoint = "http://localhost:8080/var.html"
Expand Down Expand Up @@ -177,21 +171,6 @@ persistentVolume:

var mode string

func TestMain(m *testing.M) {
if u, ok := os.LookupEnv("OKTETO_USER"); !ok {
log.Println("OKTETO_USER is not defined")
os.Exit(1)
} else {
user = u
}

if runtime.GOOS == "windows" {
kubectlBinary = "kubectl.exe"
}

os.Exit(m.Run())
}

func TestGetVersion(t *testing.T) {
v, err := utils.GetLatestVersionFromGithub()
if err != nil {
Expand Down Expand Up @@ -1159,19 +1138,6 @@ func deploy(ctx context.Context, namespace, name, path string, isDeployment bool
return nil
}

func writeDeployment(template *template.Template, name, path string) error {
dFile, err := os.Create(path)
if err != nil {
return err
}

if err := template.Execute(dFile, deployment{Name: name}); err != nil {
return err
}
defer dFile.Close()
return nil
}

func writeStatefulset(name, path string) error {
dFile, err := os.Create(path)
if err != nil {
Expand All @@ -1185,41 +1151,6 @@ func writeStatefulset(name, path string) error {
return nil
}

func getOktetoPath(ctx context.Context) (string, error) {
oktetoPath, ok := os.LookupEnv("OKTETO_PATH")
if !ok {
oktetoPath = "/usr/local/bin/okteto"
}

log.Printf("using %s", oktetoPath)

var err error
oktetoPath, err = filepath.Abs(oktetoPath)
if err != nil {
return "", err
}

cmd := exec.Command(oktetoPath, "version")
cmd.Env = os.Environ()

o, err := cmd.CombinedOutput()
if err != nil {
return "", fmt.Errorf("okteto version failed: %s - %s", string(o), err)
}

log.Println(string(o))
return oktetoPath, nil
}

func getDeployment(ctx context.Context, ns, name string) (*appsv1.Deployment, error) {
client, _, err := K8sClient()
if err != nil {
return nil, err
}

return client.AppsV1().Deployments(ns).Get(ctx, name, metav1.GetOptions{})
}

func getStatefulset(ctx context.Context, ns, name string) (*appsv1.StatefulSet, error) {
client, _, err := K8sClient()
if err != nil {
Expand Down
126 changes: 126 additions & 0 deletions integration/utils_test.go
@@ -0,0 +1,126 @@
//go:build common
// +build common

// Copyright 2021 The Okteto Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package integration

import (
"context"
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"testing"
"text/template"

appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type deployment struct {
Name string
}

var (
user = ""
kubectlBinary = "kubectl"
)

func TestMain(m *testing.M) {
if u, ok := os.LookupEnv("OKTETO_USER"); !ok {
log.Println("OKTETO_USER is not defined")
os.Exit(1)
} else {
user = u
}

if runtime.GOOS == "windows" {
kubectlBinary = "kubectl.exe"
}

os.Exit(m.Run())
}

func cloneGitRepo(ctx context.Context, name string) error {
log.Printf("cloning git repo %s", name)
cmd := exec.Command("git", "clone", name)
o, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("cloning git repo %s failed: %s - %s", name, string(o), err)
}
log.Printf("clone git repo %s success", name)
return nil
}

func deleteGitRepo(ctx context.Context, path string) error {
log.Printf("delete git repo %s", path)
err := os.RemoveAll(path)
if err != nil {
return fmt.Errorf("delete git repo %s failed: %w", path, err)
}

log.Printf("deleted git repo %s", path)
return nil
}

func getOktetoPath(ctx context.Context) (string, error) {
oktetoPath, ok := os.LookupEnv("OKTETO_PATH")
if !ok {
oktetoPath = "/usr/local/bin/okteto"
}

log.Printf("using %s", oktetoPath)

var err error
oktetoPath, err = filepath.Abs(oktetoPath)
if err != nil {
return "", err
}

cmd := exec.Command(oktetoPath, "version")
cmd.Env = os.Environ()

o, err := cmd.CombinedOutput()
if err != nil {
return "", fmt.Errorf("okteto version failed: %s - %s", string(o), err)
}

log.Println(string(o))
return oktetoPath, nil
}

func getDeployment(ctx context.Context, ns, name string) (*appsv1.Deployment, error) {
client, _, err := K8sClient()
if err != nil {
return nil, err
}

return client.AppsV1().Deployments(ns).Get(ctx, name, metav1.GetOptions{})
}

func writeDeployment(template *template.Template, name, path string) error {
dFile, err := os.Create(path)
if err != nil {
return err
}

if err := template.Execute(dFile, deployment{Name: name}); err != nil {
return err
}
defer dFile.Close()
return nil
}

0 comments on commit 8d66bf3

Please sign in to comment.