Skip to content

Commit

Permalink
Hardcode BB versions in test to workaround git bug
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasrod16 committed Apr 3, 2024
1 parent 53edd82 commit 4cc9279
Showing 1 changed file with 61 additions and 58 deletions.
119 changes: 61 additions & 58 deletions src/extensions/bigbang/test/bigbang_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ package main

import (
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"regexp"
"strings"
"testing"

Expand All @@ -17,8 +14,17 @@ import (
"github.com/stretchr/testify/require"
)

// Code related to fetching the last two Big Bang versions
// and using them to set the BB_VERSION and BB_MAJOR variables
// has been commented out due to a bug in how Zarf clones and checks out git repos.
//
// https://github.com/defenseunicorns/zarf/actions/runs/8529925302/job/23403205495?pr=2411#step:9:897
//
// The versions are currently hardcoded to the last two known working versions.
// TODO: fix the git clone/checkout bug and update this test to not be hardcoded.

// The Big Bang project ID on Repo1
const bbProjID = "2872"
// const bbProjID = "2872"

var (
zarf string
Expand All @@ -27,19 +33,16 @@ var (
)

func TestMain(m *testing.M) {
var err error

// Change to the build dir
err = os.Chdir("../../../../build/")
if err != nil {
if err := os.Chdir("../../../../build/"); err != nil {
panic(err)
}

// Get the latest and previous releases
latest, previous, err = getReleases()
if err != nil {
panic(err)
}
// // Get the latest and previous releases
// latest, previous, err = getReleases()
// if err != nil {
// panic(err)
// }

// Get the Zarf CLI path
zarf = fmt.Sprintf("./%s", test.GetCLIName())
Expand Down Expand Up @@ -68,8 +71,8 @@ func TestReleases(t *testing.T) {
require.NoError(t, err)

// Build the previous version
bbVersion := fmt.Sprintf("--set=BB_VERSION=%s", previous)
bbMajor := fmt.Sprintf("--set=BB_MAJOR=%s", previous[0:1])
bbVersion := "--set=BB_VERSION=2.22.0"
bbMajor := "--set=BB_MAJOR=2"
stdOut, stdErr, err = zarfExec("package", "create", "../src/extensions/bigbang/test/package", bbVersion, bbMajor, tmpdir, "--confirm")
require.NoError(t, err, stdOut, stdErr)

Expand All @@ -94,8 +97,8 @@ func TestReleases(t *testing.T) {
require.NoError(t, err, stdOut, stdErr)

// Build the latest version
bbVersion = fmt.Sprintf("--set=BB_VERSION=%s", latest)
bbMajor = fmt.Sprintf("--set=BB_MAJOR=%s", latest[0:1])
bbVersion = "--set=BB_VERSION=2.23.0"
bbMajor = "--set=BB_MAJOR=2"
stdOut, stdErr, err = zarfExec("package", "create", "../src/extensions/bigbang/test/package", bbVersion, bbMajor, "--differential", pkgPath, tmpdir, "--confirm")
require.NoError(t, err, stdOut, stdErr)

Expand Down Expand Up @@ -150,44 +153,44 @@ func getZarfVersion(t *testing.T) string {
return strings.Trim(stdOut, "\n")
}

func getReleases() (latest, previous string, err error) {
// Create the URL for the API endpoint
url := fmt.Sprintf("https://repo1.dso.mil/api/v4/projects/%s/repository/tags", bbProjID)

// Send an HTTP GET request to the API endpoint
resp, err := http.Get(url)
if err != nil {
return latest, previous, err
}
defer resp.Body.Close()

// Read the response body
body, err := io.ReadAll(resp.Body)
if err != nil {
return latest, previous, err
}

// Parse the response body as a JSON array of objects
var data []map[string]interface{}
err = json.Unmarshal(body, &data)
if err != nil {
return latest, previous, err
}

// Compile the regular expression for filtering tags that don't contain a hyphen
re := regexp.MustCompile("^[^-]+$")

// Create a slice to store the tag names that match the regular expression
var releases []string

// Iterate over the tags returned by the API, and filter out tags that don't match the regular expression
for _, tag := range data {
name := tag["name"].(string)
if re.MatchString(name) {
releases = append(releases, name)
}
}

// Set the latest and previous release variables to the first two releases
return releases[0], releases[1], nil
}
// func getReleases() (latest, previous string, err error) {
// // Create the URL for the API endpoint
// url := fmt.Sprintf("https://repo1.dso.mil/api/v4/projects/%s/repository/tags", bbProjID)

// // Send an HTTP GET request to the API endpoint
// resp, err := http.Get(url)
// if err != nil {
// return latest, previous, err
// }
// defer resp.Body.Close()

// // Read the response body
// body, err := io.ReadAll(resp.Body)
// if err != nil {
// return latest, previous, err
// }

// // Parse the response body as a JSON array of objects
// var data []map[string]interface{}
// err = json.Unmarshal(body, &data)
// if err != nil {
// return latest, previous, err
// }

// // Compile the regular expression for filtering tags that don't contain a hyphen
// re := regexp.MustCompile("^[^-]+$")

// // Create a slice to store the tag names that match the regular expression
// var releases []string

// // Iterate over the tags returned by the API, and filter out tags that don't match the regular expression
// for _, tag := range data {
// name := tag["name"].(string)
// if re.MatchString(name) {
// releases = append(releases, name)
// }
// }

// // Set the latest and previous release variables to the first two releases
// return releases[0], releases[1], nil
// }

0 comments on commit 4cc9279

Please sign in to comment.