Skip to content

Commit

Permalink
Merge branch 'main' into erik/add-exists-func
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasjackson authored Nov 18, 2024
2 parents 6f8b4ee + 7cf9b74 commit 0b4d37b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 34 deletions.
18 changes: 9 additions & 9 deletions pkg/config/resources/network/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var bridgeNetwork = dtypes.NetworkResource{
ID: "bridge",
Name: "bridge",
IPAM: network.IPAM{
Config: []network.IPAMConfig{network.IPAMConfig{Subnet: "10.8.2.0/24"}},
Config: []network.IPAMConfig{{Subnet: "10.8.2.0/24"}},
},
}

Expand All @@ -45,10 +45,10 @@ func TestLookupReturnsID(t *testing.T) {
md, p := setupNetworkTests(t, c)
testutils.RemoveOn(&md.Mock, "NetworkList")
md.On("NetworkList", mock.Anything, mock.Anything).Return([]dtypes.NetworkResource{
dtypes.NetworkResource{
{
ID: "testnet",
IPAM: network.IPAM{
Config: []network.IPAMConfig{network.IPAMConfig{Subnet: "10.1.2.0/24"}},
Config: []network.IPAMConfig{{Subnet: "10.1.2.0/24"}},
},
},
bridgeNetwork,
Expand Down Expand Up @@ -128,10 +128,10 @@ func TestNetworkDoesNOTCreateWhenExists(t *testing.T) {
md, p := setupNetworkTests(t, c)
testutils.RemoveOn(&md.Mock, "NetworkList")
md.On("NetworkList", mock.Anything, mock.Anything).Return([]dtypes.NetworkResource{
dtypes.NetworkResource{
{
ID: "testnet",
IPAM: network.IPAM{
Config: []network.IPAMConfig{network.IPAMConfig{Subnet: "10.1.2.0/24"}},
Config: []network.IPAMConfig{{Subnet: "10.1.2.0/24"}},
},
}, bridgeNetwork,
}, nil)
Expand All @@ -150,10 +150,10 @@ func TestCreateWithCorrectNameAndDifferentSubnetReturnsError(t *testing.T) {
md, p := setupNetworkTests(t, c)
testutils.RemoveOn(&md.Mock, "NetworkList")
md.On("NetworkList", mock.Anything, mock.Anything).Return([]dtypes.NetworkResource{
dtypes.NetworkResource{
{
ID: "testnet",
IPAM: network.IPAM{
Config: []network.IPAMConfig{network.IPAMConfig{Subnet: "10.1.1.0/24"}},
Config: []network.IPAMConfig{{Subnet: "10.1.1.0/24"}},
},
}, bridgeNetwork,
}, nil)
Expand All @@ -171,10 +171,10 @@ func TestCreateWithOverlappingSubnetReturnsError(t *testing.T) {
md, p := setupNetworkTests(t, c)
testutils.RemoveOn(&md.Mock, "NetworkList")
md.On("NetworkList", mock.Anything, mock.Anything).Return([]dtypes.NetworkResource{
dtypes.NetworkResource{
{
ID: "abc",
IPAM: network.IPAM{
Config: []network.IPAMConfig{network.IPAMConfig{Subnet: "10.2.0.0/24"}},
Config: []network.IPAMConfig{{Subnet: "10.2.0.0/24"}},
},
}, bridgeNetwork,
}, nil)
Expand Down
22 changes: 0 additions & 22 deletions pkg/config/resources/network/resource.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package network

import (
"fmt"

"github.com/jumppad-labs/hclconfig/types"
)

Expand All @@ -17,23 +15,3 @@ type Network struct {
Subnet string `hcl:"subnet" json:"subnet"`
EnableIPv6 bool `hcl:"enable_ipv6,optional" json:"enable_ipv6"`
}

func (c *Network) Parse(conf types.Findable) error {
// do any other networks with this name exist?
nets, err := conf.FindResourcesByType(TypeNetwork)
if err != nil {
return err
}

for _, n := range nets {
if n.Metadata().Name == c.Meta.Name && n.Metadata().ID != c.Meta.ID {
return fmt.Errorf("a network named '%s' is already defined by the resource '%s'", c.Meta.Name, n.Metadata().ID)
}
}

return nil
}

func (c *Network) Process() error {
return nil
}
4 changes: 2 additions & 2 deletions pkg/config/resources/terraform/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestCreatesTerraformContainerWithTheCorrectValues(t *testing.T) {
ID: "Abc123",
},
},
Version: "1.16.2",
Version: "1.9.8",
Source: "../../../../examples/terraform/workspace",
}

Expand All @@ -87,7 +87,7 @@ func TestCreatesTerraformContainerWithTheCorrectValues(t *testing.T) {
require.Equal(t, c.Environment["TF_PLUGIN_CACHE_DIR"], "/var/lib/terraform.d")

// check the correct image is used
require.Equal(t, c.Image.Name, "hashicorp/terraform:1.16.2")
require.Equal(t, c.Image.Name, "hashicorp/terraform:1.9.8")

// check the networks have been added
require.Equal(t, c.Networks[0].ID, "Abc123")
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/resources/terraform/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (t *Terraform) Process() error {

// set the base version
if t.Version == "" {
t.Version = "1.16.2"
t.Version = "1.9.8"
}

// restore the applyoutput from the state
Expand Down

0 comments on commit 0b4d37b

Please sign in to comment.