本文整理匯總了Golang中github.com/franela/goblin.Goblin函數的典型用法代碼示例。如果您正苦於以下問題:Golang Goblin函數的具體用法?Golang Goblin怎麽用?Golang Goblin使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Goblin函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestSpec
func TestSpec(t *testing.T) {
g := goblin.Goblin(t)
g.Describe("Spec file", func() {
g.Describe("when looking up a container", func() {
spec := Spec{}
spec.Containers = append(spec.Containers, &Container{
Name: "golang",
})
g.It("should find and return the container", func() {
c, err := spec.lookupContainer("golang")
g.Assert(err == nil).IsTrue("error should be nil")
g.Assert(c).Equal(spec.Containers[0])
})
g.It("should return an error when not found", func() {
c, err := spec.lookupContainer("node")
g.Assert(err == nil).IsFalse("should return error")
g.Assert(c == nil).IsTrue("should return nil container")
})
})
})
}
示例2: TestCache
func TestCache(t *testing.T) {
g := goblin.Goblin(t)
g.Describe("Cache", func() {
var c *gin.Context
g.BeforeEach(func() {
c = new(gin.Context)
ToContext(c, Default())
})
g.It("Should set and get an item", func() {
Set(c, "foo", "bar")
v, e := Get(c, "foo")
g.Assert(v).Equal("bar")
g.Assert(e == nil).IsTrue()
})
g.It("Should return nil when item not found", func() {
v, e := Get(c, "foo")
g.Assert(v == nil).IsTrue()
g.Assert(e == nil).IsFalse()
})
})
}
示例3: Test_shell
func Test_shell(t *testing.T) {
g := goblin.Goblin(t)
g.Describe("shell containers", func() {
g.It("should ignore plugin steps", func() {
root := parse.NewRootNode()
c := root.NewPluginNode()
c.Container = runner.Container{}
ops := NewShellOp(Linux_adm64)
ops.VisitContainer(c)
g.Assert(len(c.Container.Entrypoint)).Equal(0)
g.Assert(len(c.Container.Command)).Equal(0)
g.Assert(c.Container.Environment["DRONE_SCRIPT"]).Equal("")
})
g.It("should set entrypoint, command and environment variables", func() {
root := parse.NewRootNode()
root.Base = "/go"
root.Path = "/go/src/github.com/octocat/hello-world"
c := root.NewShellNode()
c.Commands = []string{"go build"}
ops := NewShellOp(Linux_adm64)
ops.VisitContainer(c)
g.Assert(c.Container.Entrypoint).Equal([]string{"/bin/sh", "-c"})
g.Assert(c.Container.Command).Equal([]string{"echo $DRONE_SCRIPT | base64 -d | /bin/sh -e"})
g.Assert(c.Container.Environment["DRONE_SCRIPT"] != "").IsTrue()
})
})
}
示例4: TestBlobstore
func TestBlobstore(t *testing.T) {
db := datasql.MustConnect("sqlite3", ":memory:")
bs := New(db)
g := goblin.Goblin(t)
g.Describe("Blobstore", func() {
// before each test be sure to purge the blob
// table data from the database.
g.Before(func() {
db.Exec("DELETE FROM blobs")
})
g.It("Should Put a Blob", func() {
err := bs.Put("foo", []byte("bar"))
g.Assert(err == nil).IsTrue()
})
g.It("Should Put a Blob reader", func() {
var buf bytes.Buffer
buf.Write([]byte("bar"))
err := bs.PutReader("foo", &buf)
g.Assert(err == nil).IsTrue()
})
g.It("Should Overwrite a Blob", func() {
bs.Put("foo", []byte("bar"))
bs.Put("foo", []byte("baz"))
blob, err := bs.Get("foo")
g.Assert(err == nil).IsTrue()
g.Assert(string(blob)).Equal("baz")
})
g.It("Should Get a Blob", func() {
bs.Put("foo", []byte("bar"))
blob, err := bs.Get("foo")
g.Assert(err == nil).IsTrue()
g.Assert(string(blob)).Equal("bar")
})
g.It("Should Get a Blob reader", func() {
bs.Put("foo", []byte("bar"))
r, _ := bs.GetReader("foo")
blob, _ := ioutil.ReadAll(r)
g.Assert(string(blob)).Equal("bar")
})
g.It("Should Del a Blob", func() {
bs.Put("foo", []byte("bar"))
err := bs.Del("foo")
g.Assert(err == nil).IsTrue()
})
g.It("Should create a Context", func() {
c := NewContext(context.Background(), db)
b := blobstore.FromContext(c).(*Blobstore)
g.Assert(b.DB).Equal(db)
})
})
}
示例5: TestUsers
func TestUsers(t *testing.T) {
gin.SetMode(gin.TestMode)
logrus.SetOutput(ioutil.Discard)
g := goblin.Goblin(t)
g.Describe("User endpoint", func() {
g.It("Should return the authenticated user", func() {
e := gin.New()
e.NoRoute(GetUser)
e.Use(func(c *gin.Context) {
c.Set("user", fakeUser)
})
w := httptest.NewRecorder()
r, _ := http.NewRequest("GET", "/", nil)
e.ServeHTTP(w, r)
want, _ := json.Marshal(fakeUser)
got := strings.TrimSpace(w.Body.String())
g.Assert(got).Equal(string(want))
g.Assert(w.Code).Equal(200)
})
})
}
示例6: Test_Matrix
func Test_Matrix(t *testing.T) {
g := goblin.Goblin(t)
g.Describe("Calculate matrix", func() {
axis, _ := Parse(fakeMatrix)
g.It("Should calculate permutations", func() {
g.Assert(len(axis)).Equal(24)
})
g.It("Should not duplicate permutations", func() {
set := map[string]bool{}
for _, perm := range axis {
set[perm.String()] = true
}
g.Assert(len(set)).Equal(24)
})
g.It("Should return nil if no matrix", func() {
axis, err := Parse("")
g.Assert(err == nil).IsTrue()
g.Assert(axis == nil).IsTrue()
})
})
}
示例7: Test_RealClient
func Test_RealClient(t *testing.T) {
g := goblin.Goblin(t)
g.Describe("Real Dart Client", func() {
// These tests will use the LIVE Dart URLs
// for integration testing purposes.
//
// Note that an outage or network connectivity
// issues could result in false positives.
c := NewClientDefault()
g.It("Should Get a Version", func() {
sdk, err := c.GetSDK()
g.Assert(err == nil).IsTrue()
g.Assert(sdk.Version == "").IsFalse()
g.Assert(sdk.Revision == "").IsFalse()
})
g.It("Should Get a Package", func() {
pkg, err := c.GetPackage("angular")
g.Assert(err == nil).IsTrue()
g.Assert(pkg.Name).Equal("angular")
g.Assert(pkg.Latest != nil).IsTrue()
})
g.It("Should Get a Recent Package List", func() {
pkgs, err := c.GetPackageRecent()
g.Assert(err == nil).IsTrue()
g.Assert(len(pkgs)).Equal(100)
})
})
}
示例8: TestParseForwardedHeadersProto
func TestParseForwardedHeadersProto(t *testing.T) {
g := goblin.Goblin(t)
g.Describe("Parse proto Forwarded Headers", func() {
g.It("Should parse a normal proto Forwarded header", func() {
parsedHeader := parseHeader(mockRequest, "Forwarded", "proto")
g.Assert("https" == parsedHeader[0]).IsTrue()
})
g.It("Should parse a normal for Forwarded header", func() {
parsedHeader := parseHeader(mockRequest, "Forwarded", "for")
g.Assert(reflect.DeepEqual([]string{"110.0.2.2", "\"[::1]\"", "10.2.3.4"}, parsedHeader)).IsTrue()
})
g.It("Should parse a normal host Forwarded header", func() {
parsedHeader := parseHeader(mockRequest, "Forwarded", "host")
g.Assert("example.com" == parsedHeader[0]).IsTrue()
})
g.It("Should parse a normal by Forwarded header", func() {
parsedHeader := parseHeader(mockRequest, "Forwarded", "by")
g.Assert("127.0.0.1" == parsedHeader[0]).IsTrue()
})
g.It("Should not crash if a wrongly formed Forwarder header is sent", func() {
parsedHeader := parseHeader(wronglyFormedRequest, "Forwarded", "by")
g.Assert(len(parsedHeader) == 0).IsTrue()
})
})
}
示例9: TestParallelNode
func TestParallelNode(t *testing.T) {
g := goblin.Goblin(t)
g.Describe("ParallelNode", func() {
g.It("should append nodes", func() {
node := NewRunNode()
parallel0 := NewParallelNode()
parallel1 := parallel0.Append(node)
g.Assert(parallel0.Type().String()).Equal(NodeParallel)
g.Assert(parallel0.Body[0]).Equal(node)
g.Assert(parallel0).Equal(parallel1)
})
g.It("should fail validation when invalid type", func() {
node := ParallelNode{}
err := node.Validate()
g.Assert(err == nil).IsFalse()
g.Assert(err.Error()).Equal("Parallel Node uses an invalid type")
})
g.It("should fail validation when empty body", func() {
node := NewParallelNode()
err := node.Validate()
g.Assert(err == nil).IsFalse()
g.Assert(err.Error()).Equal("Parallel Node body is empty")
})
g.It("should pass validation", func() {
node := NewParallelNode().Append(NewRunNode())
g.Assert(node.Validate() == nil).IsTrue()
})
})
}
示例10: TestBuildNode
func TestBuildNode(t *testing.T) {
g := goblin.Goblin(t)
g.Describe("Build", func() {
g.Describe("given a yaml file", func() {
g.It("should unmarshal", func() {
in := []byte(".")
out := build{}
err := yaml.Unmarshal(in, &out)
if err != nil {
g.Fail(err)
}
g.Assert(out.Context).Equal(".")
})
g.It("should unmarshal shorthand", func() {
in := []byte("{ context: ., dockerfile: Dockerfile }")
out := build{}
err := yaml.Unmarshal(in, &out)
if err != nil {
g.Fail(err)
}
g.Assert(out.Context).Equal(".")
g.Assert(out.Dockerfile).Equal("Dockerfile")
})
})
})
}
示例11: Test_Inject
func Test_Inject(t *testing.T) {
g := goblin.Goblin(t)
g.Describe("Inject params", func() {
g.It("Should replace vars with $$", func() {
s := "echo $$FOO $BAR"
m := map[string]string{}
m["FOO"] = "BAZ"
g.Assert("echo BAZ $BAR").Equal(Inject(s, m))
})
g.It("Should not replace vars with single $", func() {
s := "echo $FOO $BAR"
m := map[string]string{}
m["FOO"] = "BAZ"
g.Assert(s).Equal(Inject(s, m))
})
g.It("Should not replace vars in nil map", func() {
s := "echo $$FOO $BAR"
g.Assert(s).Equal(Inject(s, nil))
})
})
}
示例12: TestRecoverNode
func TestRecoverNode(t *testing.T) {
g := goblin.Goblin(t)
g.Describe("RecoverNode", func() {
g.It("should set body", func() {
node0 := NewRunNode()
recover0 := NewRecoverNode()
recover1 := recover0.SetBody(node0)
g.Assert(recover0.Type().String()).Equal(NodeRecover)
g.Assert(recover0.Body).Equal(node0)
g.Assert(recover0).Equal(recover1)
})
g.It("should fail validation when invalid type", func() {
recover0 := RecoverNode{}
err := recover0.Validate()
g.Assert(err == nil).IsFalse()
g.Assert(err.Error()).Equal("Recover Node uses an invalid type")
})
g.It("should fail validation when empty body", func() {
recover0 := NewRecoverNode()
err := recover0.Validate()
g.Assert(err == nil).IsFalse()
g.Assert(err.Error()).Equal("Recover Node body is empty")
})
g.It("should pass validation", func() {
recover0 := NewRecoverNode()
recover0.SetBody(NewRunNode())
g.Assert(recover0.Validate() == nil).IsTrue()
})
})
}
示例13: Test_args
func Test_args(t *testing.T) {
g := goblin.Goblin(t)
g.Describe("plugins arguments", func() {
g.It("should ignore non-plugin containers", func() {
root := parse.NewRootNode()
c := root.NewShellNode()
c.Container = runner.Container{}
c.Vargs = map[string]interface{}{
"depth": 50,
}
ops := NewArgsOp()
ops.VisitContainer(c)
g.Assert(c.Container.Environment["PLUGIN_DEPTH"]).Equal("")
})
g.It("should include args as environment variable", func() {
root := parse.NewRootNode()
c := root.NewPluginNode()
c.Container = runner.Container{}
c.Vargs = map[string]interface{}{
"depth": 50,
}
ops := NewArgsOp()
ops.VisitContainer(c)
g.Assert(c.Container.Environment["PLUGIN_DEPTH"]).Equal("50")
})
})
}
示例14: Test_normalize
func Test_normalize(t *testing.T) {
g := goblin.Goblin(t)
g.Describe("normalizing", func() {
g.Describe("images", func() {
g.It("should append tag if empty", func() {
c := newConfig(&yaml.Container{
Image: "golang",
})
ImageTag(c)
g.Assert(c.Pipeline[0].Image).Equal("golang:latest")
})
g.It("should not override existing tag", func() {
c := newConfig(&yaml.Container{
Image: "golang:1.5",
})
ImageTag(c)
g.Assert(c.Pipeline[0].Image).Equal("golang:1.5")
})
})
})
}
示例15: Test_pull
func Test_pull(t *testing.T) {
root := parse.NewRootNode()
g := goblin.Goblin(t)
g.Describe("pull image", func() {
g.It("should be enabled for plugins", func() {
c := root.NewPluginNode()
c.Container = runner.Container{}
op := NewPullOp(true)
op.VisitContainer(c)
g.Assert(c.Container.Pull).IsTrue()
})
g.It("should be disabled for plugins", func() {
c := root.NewPluginNode()
c.Container = runner.Container{}
op := NewPullOp(false)
op.VisitContainer(c)
g.Assert(c.Container.Pull).IsFalse()
})
g.It("should be disabled for non-plugins", func() {
c := root.NewShellNode()
c.Container = runner.Container{}
op := NewPullOp(true)
op.VisitContainer(c)
g.Assert(c.Container.Pull).IsFalse()
})
})
}