forked from rook/rook
Remove all cgo from the code base, and start the transformation to calling external ceph tools to generate config and start daemons.
62 lines
1.9 KiB
Go
62 lines
1.9 KiB
Go
/*
|
|
Copyright 2016 The Rook Authors. All rights reserved.
|
|
|
|
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 sys
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGrep(t *testing.T) {
|
|
// single line
|
|
testGrep(t, "", "", "")
|
|
testGrep(t, "foo", "", "")
|
|
testGrep(t, "food", "foo", "food")
|
|
testGrep(t, "have you ever seen such a sight?", "^have", "have you ever seen such a sight?")
|
|
testGrep(t, "have you ever seen such a sight?", "you", "have you ever seen such a sight?")
|
|
testGrep(t, "have you ever seen such a sight?", "^you", "")
|
|
|
|
// multi-line
|
|
input := `This is a test
|
|
of the emergency broadcast system.
|
|
If the test fails,
|
|
you need to fix it! `
|
|
testGrep(t, input, "test", "This is a test")
|
|
testGrep(t, input, "broadcast", " of the emergency broadcast system.")
|
|
testGrep(t, input, "fix", " you need to fix it! ")
|
|
}
|
|
|
|
func testGrep(t *testing.T, input, searchFor, expected string) {
|
|
output := Grep(input, searchFor)
|
|
assert.Equal(t, expected, output)
|
|
}
|
|
|
|
func TestAwk(t *testing.T) {
|
|
testAwk(t, 0, "", "")
|
|
testAwk(t, 0, "hello world", "hello world")
|
|
testAwk(t, 1, "hello world", "hello")
|
|
testAwk(t, 1, " hello goodbye", "hello")
|
|
testAwk(t, 2, "goodbye", "")
|
|
testAwk(t, 2, "hello goodbye", "goodbye")
|
|
testAwk(t, 3, "hello goodbye", "")
|
|
}
|
|
|
|
func testAwk(t *testing.T, index int, input, expected string) {
|
|
out := Awk(input, index)
|
|
assert.Equal(t, expected, out)
|
|
}
|