Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add make integration-actions command (#1948)
* 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
1 parent
cee2db3
commit 8d66bf3
Showing
5 changed files
with
137 additions
and
94 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
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,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 | ||
} |