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

Add make integration-actions command #1948

Merged
merged 6 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
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 15m

.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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build integration
// +build integration
//go:build actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add an envvar to skip the execution of the context action?
that why we can automate the execution of that tests only if the CLI version under test support the context command

// +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_CTX_TEST") != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we call it OKTETO_SKIP_CONTEXT_TEST to make it more verbouse?

t.Skip("this test is not required because of 'OKTETO_SKIP_CTX_TEST' env var")
return
}

ctx := context.Background()
var remove bool
Expand Down
22 changes: 0 additions & 22 deletions integration/stacks_test.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
}