From fd10e27b990cc9704ac0096847c151524b003c60 Mon Sep 17 00:00:00 2001 From: Alex Crawford Date: Fri, 12 Dec 2014 14:01:27 -0800 Subject: [PATCH] validate: empty user_data is also valid --- config/validate/validate.go | 2 ++ config/validate/validate_test.go | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/config/validate/validate.go b/config/validate/validate.go index 29c1da3..a5c078c 100644 --- a/config/validate/validate.go +++ b/config/validate/validate.go @@ -38,6 +38,8 @@ var ( // can be validated. func Validate(userdataBytes []byte) (Report, error) { switch { + case len(userdataBytes) == 0: + return Report{}, nil case config.IsScript(string(userdataBytes)): return Report{}, nil case config.IsCloudConfig(string(userdataBytes)): diff --git a/config/validate/validate_test.go b/config/validate/validate_test.go index 021b1d8..b390eda 100644 --- a/config/validate/validate_test.go +++ b/config/validate/validate_test.go @@ -78,6 +78,29 @@ func TestValidateCloudConfig(t *testing.T) { } } +func TestValidate(t *testing.T) { + tests := []struct { + config string + + report Report + }{ + {}, + { + config: "#!/bin/bash\necho hey", + }, + } + + for i, tt := range tests { + r, err := Validate([]byte(tt.config)) + if err != nil { + t.Errorf("bad error (case #%d): want %v, got %v", i, nil, err) + } + if !reflect.DeepEqual(tt.report, r) { + t.Errorf("bad report (case #%d): want %+v, got %+v", i, tt.report, r) + } + } +} + func BenchmarkValidate(b *testing.B) { config := `#cloud-config hostname: test