Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port shell resource and tests #101

Merged
merged 5 commits into from Jul 21, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions helpers/fakerenderer/fakerenderer.go
@@ -0,0 +1,26 @@
// Copyright © 2016 Asteris, LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package fakerenderer

type FakeRenderer struct {
}

func (fr *FakeRenderer) Value() (string, bool) {
return "", true
}

func (fr *FakeRenderer) Render(name, content string) (string, error) {
return content, nil
}
29 changes: 29 additions & 0 deletions helpers/fakerenderer/fakerenderer_test.go
@@ -0,0 +1,29 @@
// Copyright © 2016 Asteris, LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package fakerenderer_test

import (
"testing"

"github.com/asteris-llc/converge/helpers/fakerenderer"
"github.com/asteris-llc/converge/resource"
"github.com/stretchr/testify/assert"
)

func TestFakeRendererInterface(t *testing.T) {
t.Parallel()

assert.Implements(t, (*resource.Renderer)(nil), new(fakerenderer.FakeRenderer))
}
42 changes: 42 additions & 0 deletions resource/shell/preparer_test.go
Expand Up @@ -17,6 +17,7 @@ package shell_test
import (
"testing"

"github.com/asteris-llc/converge/helpers/fakerenderer"
"github.com/asteris-llc/converge/resource"
"github.com/asteris-llc/converge/resource/shell"
"github.com/stretchr/testify/assert"
Expand All @@ -27,3 +28,44 @@ func TestPreparerInterface(t *testing.T) {

assert.Implements(t, (*resource.Resource)(nil), new(shell.Preparer))
}

func TestShellValidateValid(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/ShellValidate/Prepare/g but otherwise LGTM!

t.Parallel()

sp := &shell.Preparer{
Check: "echo test",
Apply: "echo test",
}

_, err := sp.Prepare(&fakerenderer.FakeRenderer{})

assert.NoError(t, err)
}

func TestShellValidateInvalidCheck(t *testing.T) {
t.Parallel()

sp := &shell.Preparer{
Check: "if do then; esac",
}

_, err := sp.Prepare(&fakerenderer.FakeRenderer{})

if assert.Error(t, err) {
assert.EqualError(t, err, "exit status 2")
}
}

func TestShellValidateInvalidApply(t *testing.T) {
t.Parallel()

sp := &shell.Preparer{
Apply: "if do then; esac",
}

_, err := sp.Prepare(&fakerenderer.FakeRenderer{})

if assert.Error(t, err) {
assert.EqualError(t, err, "exit status 2")
}
}