Skip to content

Commit

Permalink
🐛 fix: wrong ut for types
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotxx committed Mar 7, 2022
1 parent bd6e583 commit 63f0306
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 54 deletions.
17 changes: 1 addition & 16 deletions blueprint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,7 @@ import (
"github.com/elliotxx/gulu/json"
)

var TestTemplateConfiguration = &TemplateConfiguration{
Variables: map[string]Variable{
"Env": {
Description: "The env name. One of dev,test,stable,pre,sim,gray,prod.",
Default: "dev",
},
"ClusterName": {
Description: "The Cluster Name.",
Default: "kubernetes-dev",
},
"Image": {
Description: "The Image Address.",
Default: "gcr.io/google-samples/gb-frontend:v4",
},
},
}
var TestTemplateConfiguration *TemplateConfiguration

func TestParseTemplateConfiguration(t *testing.T) {
type args struct {
Expand Down
14 changes: 13 additions & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package blueprint

import (
"errors"
"sort"
)

const TemplateConfigurationFilenameWithoutExt = "blueprint"
Expand All @@ -19,7 +20,18 @@ func NewTemplate(tc *TemplateConfiguration) (*Template, error) {
variableSlice: []*Variable{},
}

for k, v := range tc.Variables {
// Sort variables by name
variableKeys := []string{}
for k := range tc.Variables {
variableKeys = append(variableKeys, k)
}

sort.Strings(variableKeys)

// Create Template
for _, k := range variableKeys {
v := tc.Variables[k]

nv, err := NewVariable(k, v.Description, v.Default)
if err != nil {
return nil, err
Expand Down
103 changes: 66 additions & 37 deletions types_test.go
Original file line number Diff line number Diff line change
@@ -1,45 +1,17 @@
package blueprint

import (
"os"
"reflect"
"testing"
)

var TestVariableMap = map[string]*Variable{
"Env": {
Name: "Env",
Description: "The env name. One of dev,test,stable,pre,sim,gray,prod.",
Default: "dev",
},
"ClusterName": {
Name: "ClusterName",
Description: "The Cluster Name.",
Default: "kubernetes-dev",
},
"Image": {
Name: "Image",
Description: "The Image Address.",
Default: "gcr.io/google-samples/gb-frontend:v4",
},
}
"github.com/elliotxx/gulu/json"
)

var TestVariableSlice = []*Variable{
{
Name: "Env",
Description: "The env name. One of dev,test,stable,pre,sim,gray,prod.",
Default: "dev",
},
{
Name: "ClusterName",
Description: "The Cluster Name.",
Default: "kubernetes-dev",
},
{
Name: "Image",
Description: "The Image Address.",
Default: "gcr.io/google-samples/gb-frontend:v4",
},
}
var (
TestVariableMap map[string]*Variable
TestVariableSlice []*Variable
)

func TestNewTemplate(t *testing.T) {
type args struct {
Expand Down Expand Up @@ -73,7 +45,7 @@ func TestNewTemplate(t *testing.T) {
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("NewTemplate() = %v, want %v", got, tt.want)
t.Errorf("NewTemplate() = %v, want %v", json.MustPrettyMarshalString(got), json.MustPrettyMarshalString(tt.want))
}
})
}
Expand Down Expand Up @@ -147,8 +119,8 @@ func TestTemplate_Variables(t *testing.T) {
variableSlice: TestVariableSlice,
},
want: []Variable{
*TestVariableMap["Env"],
*TestVariableMap["ClusterName"],
*TestVariableMap["Env"],
*TestVariableMap["Image"],
},
wantErr: false,
Expand Down Expand Up @@ -242,3 +214,60 @@ func TestNewVariable(t *testing.T) {
})
}
}

func TestMain(m *testing.M) {
TestTemplateConfiguration = &TemplateConfiguration{
Variables: map[string]Variable{
"ClusterName": {
Description: "The Cluster Name.",
Default: "kubernetes-dev",
},
"Env": {
Description: "The env name. One of dev,test,stable,pre,sim,gray,prod.",
Default: "dev",
},
"Image": {
Description: "The Image Address.",
Default: "gcr.io/google-samples/gb-frontend:v4",
},
},
}

TestVariableMap = map[string]*Variable{
"ClusterName": {
Name: "ClusterName",
Description: "The Cluster Name.",
Default: "kubernetes-dev",
},
"Env": {
Name: "Env",
Description: "The env name. One of dev,test,stable,pre,sim,gray,prod.",
Default: "dev",
},
"Image": {
Name: "Image",
Description: "The Image Address.",
Default: "gcr.io/google-samples/gb-frontend:v4",
},
}

TestVariableSlice = []*Variable{
{
Name: "ClusterName",
Description: "The Cluster Name.",
Default: "kubernetes-dev",
},
{
Name: "Env",
Description: "The env name. One of dev,test,stable,pre,sim,gray,prod.",
Default: "dev",
},
{
Name: "Image",
Description: "The Image Address.",
Default: "gcr.io/google-samples/gb-frontend:v4",
},
}

os.Exit(m.Run())
}

0 comments on commit 63f0306

Please sign in to comment.