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

Embed test files #2

Merged
merged 2 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Test

on: [push]

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Go cache
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.18
- name: Configure Agent
run: go run mage.go ConfigureAgent
- name: Build
run: mage Build
- name: Test
run: mage Test
15 changes: 15 additions & 0 deletions mage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//go:build ignore
// +build ignore

package main

import (
"os"

"github.com/magefile/mage/mage"
)

// This file allows someone to run mage commands without mage installed
// by running `go run mage.go TARGET`.
// See https://magefile.org/zeroinstall/
func main() { os.Exit(mage.Main()) }
6 changes: 6 additions & 0 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
package main

import (
"get.porter.sh/magefiles/ci"
"github.com/carolynvs/magex/mgx"
"github.com/carolynvs/magex/shx"
)

var must = shx.CommandBuilder{StopOnError: true}

func ConfigureAgent() {
mgx.Must(ci.ConfigureAgent())
}

func Build() {
must.RunV("go", "build", "./...")
}
Expand Down
22 changes: 13 additions & 9 deletions tests/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tests

import (
"bytes"
_ "embed"
"fmt"
"html/template"
"io/ioutil"
Expand All @@ -10,6 +11,7 @@ import (
"net/http"
"os"
"path/filepath"
"strings"

"get.porter.sh/magefiles/docker"
"get.porter.sh/magefiles/tools"
Expand All @@ -29,6 +31,12 @@ const (

var (
must = shx.CommandBuilder{StopOnError: true}

//go:embed kind.config.yaml
templateKindConfig string

//go:embed local-registry.yaml
templateLocalRegistry string
)

// Ensure that the test KIND cluster is up.
Expand Down Expand Up @@ -97,15 +105,9 @@ func CreateTestCluster() {
}

os.Setenv("KUBECONFIG", filepath.Join(pwd(), Kubeconfig))
kindCfgPath := "mage/tests/kind.config.yaml"
kindCfg, err := ioutil.ReadFile(kindCfgPath)
if err != nil {
mgx.Must(fmt.Errorf("error reading %s: %w", kindCfgPath, err))
}

kindCfgTmpl, err := template.New("kind.config.yaml").Parse(string(kindCfg))
kindCfgTmpl, err := template.New("kind.config.yaml").Parse(templateKindConfig)
if err != nil {
mgx.Must(fmt.Errorf("error parsing EnsureKind config template %s: %w", kindCfgPath, err))
mgx.Must(fmt.Errorf("error parsing EnsureKind config template: %w", err))
}

var kindCfgContents bytes.Buffer
Expand All @@ -126,7 +128,9 @@ func CreateTestCluster() {
Env("KIND_EXPERIMENTAL_DOCKER_NETWORK=" + docker.DefaultNetworkName).Run()

// Document the local registry
kubectl("apply", "-f", "mage/tests/local-registry.yaml").Run()
kubectl("apply", "-f", "-").
Stdin(strings.NewReader(templateLocalRegistry)).
Run()
}

// Delete the KIND cluster named porter.
Expand Down