Skip to content

Commit

Permalink
Merge pull request #565 from fluxcd/tidy-nits
Browse files Browse the repository at this point in the history
Address various issues throughout code base
  • Loading branch information
hiddeco authored Oct 19, 2023
2 parents defd112 + f8f4741 commit 4e56fa2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
5 changes: 2 additions & 3 deletions internal/provider/provider_resource_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
apimachineryschema "k8s.io/apimachinery/pkg/runtime/schema"
restclient "k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/tools/clientcmd/api"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -364,9 +363,9 @@ func getClientConfiguration(ctx context.Context, kubernetes *Kubernetes) (client
if diag := kubernetes.Exec.Env.ElementsAs(ctx, &envMap, false); diag.HasError() {
return nil, fmt.Errorf("%s", diag)
}
var env []api.ExecEnvVar
var env []clientcmdapi.ExecEnvVar
for k, v := range envMap {
env = append(env, api.ExecEnvVar{
env = append(env, clientcmdapi.ExecEnvVar{
Name: k,
Value: v,
})
Expand Down
23 changes: 16 additions & 7 deletions internal/provider/resource_bootstrap_git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const (

func TestMain(m *testing.M) {
ctrllog.SetLogger(logr.New(ctrllog.NullLogSink{}))

tmpDir, err := os.MkdirTemp("", "boostrap-git-test")
if err != nil {
fmt.Println(err)
Expand All @@ -75,16 +76,21 @@ func TestMain(m *testing.M) {
os.Exit(1)
return
}
f.Close()
err = os.Setenv(hostaliasesEnvKey, hostAliases)
if err != nil {
if err = f.Close(); err != nil {
fmt.Println(err)
os.Exit(1)
return
}

if err = os.Setenv(hostaliasesEnvKey, hostAliases); err != nil {
fmt.Println(err)
os.Exit(1)
return
}

exitVal := m.Run()
_ = os.Unsetenv(hostaliasesEnvKey)
os.Exit(exitVal)
os.Unsetenv(hostaliasesEnvKey)
}

func TestAccBootstrapGit_InvalidCustomization(t *testing.T) {
Expand Down Expand Up @@ -628,7 +634,7 @@ type environment struct {

func setupEnvironment(t *testing.T) environment {
t.Helper()
rand.Seed(time.Now().UnixNano())

httpPort := rand.Intn(65535-1024) + 1024
sshPort := httpPort + 10
randSuffix := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)
Expand Down Expand Up @@ -735,7 +741,8 @@ func setupEnvironment(t *testing.T) environment {
Key: string(keyPair.PublicKey),
ReadOnly: false,
}
giteaClient.AdminCreateUserPublicKey(username, createPublicKeyOpt)
_, _, err = giteaClient.AdminCreateUserPublicKey(username, createPublicKeyOpt)
require.NoError(t, err)

keyPairRo, err := ssh.GenerateKeyPair(ssh.ECDSA_P256)
require.NoError(t, err)
Expand All @@ -744,9 +751,11 @@ func setupEnvironment(t *testing.T) environment {
Key: string(keyPairRo.PublicKey),
ReadOnly: true,
}
giteaClient.AdminCreateUserPublicKey(username, createPublicKeyOptRo)
_, _, err = giteaClient.AdminCreateUserPublicKey(username, createPublicKeyOptRo)
require.NoError(t, err)

sshHostKey, err := sourcesecret.ScanHostKey(fmt.Sprintf("%s:%d", giteaName, sshPort))
require.NoError(t, err)
return environment{
kubeCfgPath: kubeCfgPath,
httpClone: repo.CloneURL,
Expand Down

0 comments on commit 4e56fa2

Please sign in to comment.