generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement simple integration test with crane
- Loading branch information
1 parent
07fa635
commit b7bd4ef
Showing
9 changed files
with
301 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
//go:build !nointegration | ||
// +build !nointegration | ||
|
||
/* | ||
Copyright 2022 The Kubernetes 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 main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"os/exec" | ||
"testing" | ||
|
||
"sigs.k8s.io/oci-proxy/internal/integration" | ||
) | ||
|
||
func TestIntegrationMain(t *testing.T) { | ||
integration.MaybeSkip(t) | ||
|
||
// setup crane | ||
rootDir, err := integration.ModuleRootDir() | ||
if err != nil { | ||
t.Fatalf("Failed to detect module root dir: %v", err) | ||
} | ||
// NOTE: also ensures rootDir/bin is in front of $PATH | ||
if err := integration.EnsureCrane(rootDir); err != nil { | ||
t.Fatalf("Failed to ensure crane: %v", err) | ||
} | ||
|
||
// build binary | ||
buildCmd := exec.Command("make", "archeio") | ||
buildCmd.Dir = rootDir | ||
if err := buildCmd.Run(); err != nil { | ||
t.Fatalf("Failed to build archeio for integration testing: %v", err) | ||
} | ||
|
||
// start server in background | ||
testPort := "61337" | ||
testAddr := "localhost:" + testPort | ||
serverErrChan := make(chan error) | ||
cmdContext, serverCancel := context.WithCancel(context.TODO()) | ||
serverCmd := exec.CommandContext(cmdContext, "archeio") | ||
serverCmd.Env = append(serverCmd.Env, "PORT="+testPort) | ||
// serverCmd.Stderr = os.Stderr | ||
defer serverCancel() | ||
go func() { | ||
serverErrChan <- serverCmd.Start() | ||
serverErrChan <- serverCmd.Wait() | ||
}() | ||
|
||
// TODO: wait for readyz or similar ... | ||
startErr := <-serverErrChan | ||
if startErr != nil { | ||
t.Fatalf("Failed to start archeio: %v", err) | ||
} | ||
|
||
// TODO: fake being on AWS | ||
testPull := func(image string) error { | ||
cmd := exec.Command("crane", "pull", testAddr+"/"+image, os.DevNull) | ||
//cmd.Stderr = os.Stderr | ||
return cmd.Run() | ||
} | ||
// test pulling pause image | ||
// TODO: test pulling more things | ||
if err := testPull("pause:3.1"); err != nil { | ||
t.Fatalf("Failed to pull pause:3.1 with err: %v", err) | ||
} | ||
|
||
// we're done, cleanup | ||
if err := serverCmd.Process.Signal(os.Interrupt); err != nil { | ||
t.Fatalf("failed to signal archeio: %v", err) | ||
} | ||
if err := <-serverErrChan; err != nil { | ||
t.Fatalf("archeio did not exit cleanly: %v", err) | ||
} | ||
} |
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
Oops, something went wrong.